Returns the exact encoded size of a
.
Reads a value of type A
from buffer
.
Reads a value of type A
from buffer
. This should generally follow the
contract that writeUnsafe(a, buffer); read(buffer) == a
.
Initiate a write.
Initiate a write. If a is successfully written (in its entirety) to
buffer
, then None
is returned. Otherwise, Some(s)
is returned,
indicating that some more data (ie. s
) still needs to be written using
writeMore(s, _)
. This last condition will normally happen when we run
out of space in the buffer, so a
was only partially written.
Writes the remaining data from a call to writeInit
to buffer
.
Writes the remaining data from a call to writeInit
to buffer
. If this
is written completely and successfully, None
is returned. Otherwise,
Some(s2)
is returned, which contains more data to be written with
writeMore
.
Performs an *unsafe* write of a
to buffer
.
Performs an *unsafe* write of a
to buffer
. This does not perform any
safety checks and assumes buffer
has at least encodedSize(a)
bytes
remaining. The behaviour if this is not the case is undefined.
Returns an upper bound on the size of a
.
Returns a lower bound on the space required in a buffer so that a
can
be written.
This is similar to read(buffer)
, except that a value does not actually
need to be returned.
Writes a
using a ByteBufferMonad
.
Writes a
using a ByteBufferMonad
. This is much slower than just using
writeInit/writeMore.
Writes a
entirely to a series of ByteBuffer
s returned by acquire
.
Writes a
entirely to a series of ByteBuffer
s returned by acquire
.
The returned set of ByteBuffer
s is in reverse order, so that calls
to writeAll
can be chained by passing in the previous result to used
.
Codecs allow a writer to deal with the case where we have a buffer overflow when attempting to write all data to the buffer. This lets the writer return some state indicating more data needs to be written. This state is then given to a
writeMore
method so it can finish the writing. It may take several calls towriteMore
before it all is finally written.