Struct rubble::bytes::ByteWriter[][src]

pub struct ByteWriter<'a>(&'a mut [u8]);
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.

Tuple Fields

0: &'a mut [u8]

Implementations

Creates a writer that will write to buf.

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.

Writes a value to the stream by transmuting it to bytes.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.