pub struct TdfWriter {
pub buffer: Vec<u8>,
}
Expand description
Writer implementation for writing values to an underlying buffer this writer implementation provides functions for writing certain data types in their Blaze format
Fields§
§buffer: Vec<u8>
The buffer that will be written to
Implementations§
source§impl TdfWriter
impl TdfWriter
sourcepub fn write_byte(&mut self, value: u8)
pub fn write_byte(&mut self, value: u8)
Writes a single byte to the underlying buffer. This just appends the byte to the buffer.
value
The value to write
sourcepub fn write_slice(&mut self, value: &[u8])
pub fn write_slice(&mut self, value: &[u8])
Extends the underlying buffer with the provided slice value.
value
The slice value to write
sourcepub fn write_type(&mut self, ty: TdfType)
pub fn write_type(&mut self, ty: TdfType)
Writes the value type byte of the provided TdfType
ty
The type to write
sourcepub fn tag(&mut self, tag: &[u8], value_type: TdfType)
pub fn tag(&mut self, tag: &[u8], value_type: TdfType)
Writes a tag vvalue to the underlying buffer
tag
The tag bytes to write
value_type
The value type for the tag
sourcepub fn tag_bool(&mut self, tag: &[u8], value: bool)
pub fn tag_bool(&mut self, tag: &[u8], value: bool)
Writes a new tag to the buffer with a boolean as the tag value.
tag
The tag to write
value
The tag value boolean
sourcepub fn tag_zero(&mut self, tag: &[u8])
pub fn tag_zero(&mut self, tag: &[u8])
Writes a new tag where the value is a VarInt that is simply zero so the encoding can skip all the var int logic and directly write zero
tag
The tag to write
sourcepub fn tag_u8(&mut self, tag: &[u8], value: u8)
pub fn tag_u8(&mut self, tag: &[u8], value: u8)
Writes a new tag where the value is a u8 value using the var int encoding
tag
The tag to write
value
The value to write
sourcepub fn tag_u16(&mut self, tag: &[u8], value: u16)
pub fn tag_u16(&mut self, tag: &[u8], value: u16)
Writes a new tag where the value is a u16 value using the var int encoding
tag
The tag to write
value
The value to write
sourcepub fn tag_u32(&mut self, tag: &[u8], value: u32)
pub fn tag_u32(&mut self, tag: &[u8], value: u32)
Writes a new tag where the value is a u32 value using the var int encoding
tag
The tag to write
value
The value to write
sourcepub fn tag_u64(&mut self, tag: &[u8], value: u64)
pub fn tag_u64(&mut self, tag: &[u8], value: u64)
Writes a new tag where the value is a u64 value using the var int encoding
tag
The tag to write
value
The value to write
sourcepub fn tag_usize(&mut self, tag: &[u8], value: usize)
pub fn tag_usize(&mut self, tag: &[u8], value: usize)
Writes a new tag where the value is a usize value using the var int encoding
tag
The tag to write
value
The value to write
sourcepub fn tag_str_empty(&mut self, tag: &[u8])
pub fn tag_str_empty(&mut self, tag: &[u8])
Writes a new tag where the value is an empty string
tag
The tag to write
sourcepub fn tag_empty_blob(&mut self, tag: &[u8])
pub fn tag_empty_blob(&mut self, tag: &[u8])
Writes a new tag where the value is an empty blob. Empty blobs are simply encoded with a zero length
tag
The tag to write
sourcepub fn tag_str(&mut self, tag: &[u8], value: &str)
pub fn tag_str(&mut self, tag: &[u8], value: &str)
Writes a new tag where the value is a string.
tag
The tag to write
value
The value to write
sourcepub fn tag_group(&mut self, tag: &[u8])
pub fn tag_group(&mut self, tag: &[u8])
Writes a new tag indicating the start of a new group
tag
The tag to write
sourcepub fn tag_group_end(&mut self)
pub fn tag_group_end(&mut self)
Writes the zero value that indicates the end of a group
sourcepub fn group<F>(&mut self, tag: &[u8], gr: F)where
F: FnOnce(&mut Self),
pub fn group<F>(&mut self, tag: &[u8], gr: F)where F: FnOnce(&mut Self),
Writes a group opening tag and then completes the group function and closes the group tag
tag
The tag to write
gr
The group closure
sourcepub fn tag_list_start(&mut self, tag: &[u8], ty: TdfType, length: usize)
pub fn tag_list_start(&mut self, tag: &[u8], ty: TdfType, length: usize)
Writes a new tag indicating that a list is begining and writes the list type and length
tag
The tag to write
ty
The type of items being written after
length
The number of items that will be written
sourcepub fn tag_union_start(&mut self, tag: &[u8], key: u8)
pub fn tag_union_start(&mut self, tag: &[u8], key: u8)
Writes a new tag indicating that a union with the provided key is starting
tag
The tag to write
key
The key to write
sourcepub fn tag_union_value<C: Encodable + ValueType>(
&mut self,
tag: &[u8],
key: u8,
value_tag: &[u8],
value: &C
)
pub fn tag_union_value<C: Encodable + ValueType>( &mut self, tag: &[u8], key: u8, value_tag: &[u8], value: &C )
Writes a new union tag with its value
tag
The tag to write
key
The key of the union
value_tag
The tag for the value
value
The value to write
sourcepub fn tag_union_unset(&mut self, tag: &[u8])
pub fn tag_union_unset(&mut self, tag: &[u8])
Writes a new tag indicating a union with no value
tag
The tag to write
sourcepub fn tag_value<C: Encodable + ValueType>(&mut self, tag: &[u8], value: &C)
pub fn tag_value<C: Encodable + ValueType>(&mut self, tag: &[u8], value: &C)
Writes a tag and its value where the value implements ValueType
tag
The tag to write
value
The value to write
sourcepub fn tag_list_empty(&mut self, tag: &[u8], ty: TdfType)
pub fn tag_list_empty(&mut self, tag: &[u8], ty: TdfType)
Writes a tag for indiciating a list with no contents
tag
The tag to write
ty
The type of the empty list
sourcepub fn tag_slice_list<C: Encodable + ValueType>(
&mut self,
tag: &[u8],
value: &[C]
)
pub fn tag_slice_list<C: Encodable + ValueType>( &mut self, tag: &[u8], value: &[C] )
Slices are already borrowed so they confuse the tag_value
type using this
function instead makes them work
sourcepub fn tag_var_int_list_empty(&mut self, tag: &[u8])
pub fn tag_var_int_list_empty(&mut self, tag: &[u8])
Writes a tag for indiciating a var int list with no contents
tag
The tag to write
sourcepub fn tag_map_start(
&mut self,
tag: &[u8],
key: TdfType,
value: TdfType,
length: usize
)
pub fn tag_map_start( &mut self, tag: &[u8], key: TdfType, value: TdfType, length: usize )
Writes a tag indicating that a map will be written for the provided types and length
tag
The tag to write
key
The key tdf type
value
The value tdf type
length
The total number of entires that will be written
sourcepub fn tag_pair<A, B>(&mut self, tag: &[u8], value: (A, B))where
A: VarInt,
B: VarInt,
pub fn tag_pair<A, B>(&mut self, tag: &[u8], value: (A, B))where A: VarInt, B: VarInt,
Writes a tag with a pair of values
tag
The tag to write
value
The value to write
sourcepub fn tag_triple<A, B, C>(&mut self, tag: &[u8], value: (A, B, C))where
A: VarInt,
B: VarInt,
C: VarInt,
pub fn tag_triple<A, B, C>(&mut self, tag: &[u8], value: (A, B, C))where A: VarInt, B: VarInt, C: VarInt,
Writes a tag with a triple of values
tag
The tag to write
value
The value to write
sourcepub fn write_empty_str(&mut self)
pub fn write_empty_str(&mut self)
Writes an empty string. This is simply two bytes a 1 and a 0 which indicate a string consisting of only a null terminator
sourcepub fn write_f32(&mut self, value: f32)
pub fn write_f32(&mut self, value: f32)
Writes 32 bit float value to the underlying buffer in big-endian byte order.
value
The float value to write
sourcepub fn write_u8(&mut self, value: u8)
pub fn write_u8(&mut self, value: u8)
Writes a u8 value using the VarInt encoding
value
The value to write
sourcepub fn write_u16(&mut self, value: u16)
pub fn write_u16(&mut self, value: u16)
Writes a u16 value using the VarInt encoding
value
The value to write
sourcepub fn write_u32(&mut self, value: u32)
pub fn write_u32(&mut self, value: u32)
Writes a u32 value using the VarInt encoding
value
The value to write
sourcepub fn write_u64(&mut self, value: u64)
pub fn write_u64(&mut self, value: u64)
Writes a u64 value using the VarInt encoding
value
The value to write
sourcepub fn write_usize(&mut self, value: usize)
pub fn write_usize(&mut self, value: usize)
Writes a usize value using the VarInt encoding
value
The value to write
sourcepub fn write_str(&mut self, value: &str)
pub fn write_str(&mut self, value: &str)
Writes a string to the underlying buffer. The bytes are encoded an a null terminator is appended to the end then the size and bytes are written to the buffer
value
The string value to write
sourcepub fn write_bool(&mut self, value: bool)
pub fn write_bool(&mut self, value: bool)
Writes a boolean value which uses the VarInt encoding except because the values are < 64 they are just directly appended as bytes
sourcepub fn write_map_header(
&mut self,
key_type: TdfType,
value_type: TdfType,
length: usize
)
pub fn write_map_header( &mut self, key_type: TdfType, value_type: TdfType, length: usize )
Writes the header for a map in order to begin writing map values
key_type
The type of the map keys
value_type
The type of the map values
length
The total number of items that will be written