build RA buffer through API

This makes a buffer overrun less likely.  Before this change the
buffer usage was tracked separately from the actually buffer
usage which can easily lead to bugs.  This change adds an API which
writes to the buffer and tracks the buffer usage through simple
functions.