pub struct Anybuf { /* private fields */ }Implementations§
source§impl Anybuf
impl Anybuf
sourcepub fn append_bytes(self, field_number: u32, data: impl AsRef<[u8]>) -> Self
pub fn append_bytes(self, field_number: u32, data: impl AsRef<[u8]>) -> Self
Appends a bytes field with the given field number.
sourcepub fn append_string(self, field_number: u32, data: impl AsRef<str>) -> Self
pub fn append_string(self, field_number: u32, data: impl AsRef<str>) -> Self
Appends a string field with the given field number.
sourcepub fn append_uint64(self, field_number: u32, value: u64) -> Self
pub fn append_uint64(self, field_number: u32, value: u64) -> Self
Appends a uint64 field with the given field number.
sourcepub fn append_uint32(self, field_number: u32, value: u32) -> Self
pub fn append_uint32(self, field_number: u32, value: u32) -> Self
Appends a uint32 field with the given field number.
sourcepub fn append_bool(self, field_number: u32, value: bool) -> Self
pub fn append_bool(self, field_number: u32, value: bool) -> Self
Appends a bool field with the given field number.
sourcepub fn append_sint32(self, field_number: u32, value: i32) -> Self
pub fn append_sint32(self, field_number: u32, value: i32) -> Self
Appends an sint32 field with the given field number.
Please note that protobuf has two different 32 bit signed integer types with different encodings: sint32 and int32. This only works for the former.
sourcepub fn append_sint64(self, field_number: u32, value: i64) -> Self
pub fn append_sint64(self, field_number: u32, value: i64) -> Self
Appends an sint64 field with the given field number.
Please note that protobuf has two different 64 bit signed integer types with different encodings: sint64 and int64. This only works for the former.
sourcepub fn append_message(self, field_number: u32, value: &Anybuf) -> Self
pub fn append_message(self, field_number: u32, value: &Anybuf) -> Self
Appends a nested protobuf message with the given field number.
sourcepub fn append_repeated_uint32(self, field_number: u32, data: &[u32]) -> Self
pub fn append_repeated_uint32(self, field_number: u32, data: &[u32]) -> Self
Appends a repeated field of type uint32.
Use this instead of multiple Anybuf::append_uint32 to ensure 0 values are not lost.
sourcepub fn append_repeated_uint64(self, field_number: u32, data: &[u64]) -> Self
pub fn append_repeated_uint64(self, field_number: u32, data: &[u64]) -> Self
Appends a repeated field of type uint64.
Use this instead of multiple Anybuf::append_uint64 to ensure 0 values are not lost.
sourcepub fn append_repeated_sint32(self, field_number: u32, data: &[i32]) -> Self
pub fn append_repeated_sint32(self, field_number: u32, data: &[i32]) -> Self
Appends a repeated field of type sint32.
Use this instead of multiple Anybuf::append_sint32 to ensure 0 values are not lost.
Example
// Three signed ints with field number 4
let serialized = Anybuf::new()
.append_repeated_sint32(3, &[-30, 0, 17])
.into_vec();sourcepub fn append_repeated_sint64(self, field_number: u32, data: &[i64]) -> Self
pub fn append_repeated_sint64(self, field_number: u32, data: &[i64]) -> Self
Appends a repeated field of type sint64.
Use this instead of multiple Anybuf::append_sint64 to ensure 0 values are not lost.
Example
// Three signed ints with field number 4
let serialized = Anybuf::new()
.append_repeated_sint64(4, &[-30, 0, 17])
.into_vec();sourcepub fn append_repeated_bool(self, field_number: u32, data: &[bool]) -> Self
pub fn append_repeated_bool(self, field_number: u32, data: &[bool]) -> Self
Appends a repeated field of type bool.
Use this instead of multiple Anybuf::append_bool to ensure false values are not lost.
sourcepub fn append_repeated_string(self, field_number: u32, data: &[&str]) -> Self
pub fn append_repeated_string(self, field_number: u32, data: &[&str]) -> Self
Appends a repeated field of type string.
Use this instead of multiple Anybuf::append_string to ensure “” values are not lost.
Example
let name = "Bono".to_string();
// Three string fields with field number 4
let serialized = Anybuf::new()
.append_repeated_string(4, &["", "Caro", &name])
.into_vec();sourcepub fn append_repeated_bytes(self, field_number: u32, data: &[&[u8]]) -> Self
pub fn append_repeated_bytes(self, field_number: u32, data: &[&[u8]]) -> Self
Appends a repeated field of type bytes.
Use this instead of multiple Anybuf::append_bytes to ensure empty values are not lost.
Example
let blob = vec![4u8; 75];
// Three bytes fields with field number 5
let serialized = Anybuf::new()
.append_repeated_bytes(5, &[b"", b"abcd", &blob])
.into_vec();sourcepub fn append_repeated_message(
self,
field_number: u32,
messages: &[&Anybuf]
) -> Self
pub fn append_repeated_message( self, field_number: u32, messages: &[&Anybuf] ) -> Self
Appends a repeated field of type message.
Use this instead of multiple Anybuf::append_message to ensure empty values are not lost.
Example
// A repeated message at field number 11. This adds 3 elements, one of them is the default message.
let serialized = Anybuf::new()
.append_repeated_message(11, &[
&Anybuf::new().append_uint32(1, 1),
&Anybuf::new(),
&Anybuf::new().append_uint32(1, 3),
])
.into_vec();sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the protobuf bytes of the instance.
The data is the same as Anybuf::into_vec but does not consume the instance.
sourcepub fn into_vec(self) -> Vec<u8>
pub fn into_vec(self) -> Vec<u8>
Takes the instance and returns the protobuf bytes.
The data is the same as Anybuf::as_bytes but consumes the instance in order to
return an owned vector without cloning the data.