Struct rubble::bytes::ByteWriter [−][src]
pub struct ByteWriter<'a>(_);
Expand description
Wrapper around a byte slice that can be used to encode data into bytes.
All write_*
methods on this type will return Error::Eof
when the underlying buffer slice is
full.
Implementations
Consumes self
and returns the part of the contained buffer that has not yet been written
to.
Returns the raw buffer this ByteWriter
would write to.
Combined with skip
, this method allows advanced operations on the underlying byte buffer.
Skips the given number of bytes in the output data without writing anything there.
This is a potentially dangerous operation that should only be used when necessary (eg. when the skipped data will be filled in by other code). If the skipped bytes are not written, they will probably contain garbage data from an earlier use of the underlying buffer.
Creates and returns another ByteWriter
that can write to the next len
Bytes in the
buffer.
self
will be modified to point after the split-off bytes.
Note that if the created ByteWriter
is not used, the bytes will contain whatever contents
they had before creating self
(ie. most likely garbage data left over from earlier use).
If you are really sure you want that, skip
is a more explicit way of accomplishing that.
Splits off the next byte in the buffer.
The writer will be advanced to point to the rest of the underlying buffer.
This allows filling in the value of the byte later, after writing more data.
For a similar, but more flexible operation, see split_off
.
Returns the number of bytes that can be written to self
until it is full.
Writes all bytes from other
to self
.
Returns Error::Eof
when self
does not have enough space left to fit other
. In that
case, self
will not be modified.
Writes as many bytes as can fit from other
into self
.
Returns the number of bytes written.
Writes a single byte to self
.
Returns Error::Eof
when no space is left.
Writes a u16
to self
, using Little Endian byte order.
If self
does not have enough space left, an error will be returned and no bytes will be
written to self
.
Writes a u32
to self
, using Little Endian byte order.
If self
does not have enough space left, an error will be returned and no bytes will be
written to self
.
Writes a u64
to self
, using Little Endian byte order.
If self
does not have enough space left, an error will be returned and no bytes will be
written to self
.