MCPcopy Create free account
hub / github.com/3Hren/msgpack-rust / write_str_len

Function write_str_len

src/encode.rs:623–640  ·  view source on GitHub ↗

Encodes and attempts to write the most efficient string length implementation to the given write, returning the marker used. This function is useful when you want to get full control for writing the data itself, for example, when using non-blocking socket. # Errors This function will return `ValueWriteError` on any I/O error occurred while writing either the marker or the data, except the EINTR

(wr: &mut W, len: u32)

Source from the content-addressed store, hash-verified

621/// This function will return `ValueWriteError` on any I/O error occurred while writing either the
622/// marker or the data, except the EINTR, which is handled internally.
623pub fn write_str_len<W>(wr: &mut W, len: u32) -> Result<Marker, ValueWriteError>
624 where W: Write
625{
626 if len < 32 {
627 let marker = Marker::FixStr(len as u8);
628 try!(write_fixval(wr, marker));
629 Ok(marker)
630 } else if len < 256 {
631 try!(write_marker(wr, Marker::Str8));
632 write_data_u8(wr, len as u8).and(Ok(Marker::Str8))
633 } else if len < 65536 {
634 try!(write_marker(wr, Marker::Str16));
635 write_data_u16(wr, len as u16).and(Ok(Marker::Str16))
636 } else {
637 try!(write_marker(wr, Marker::Str32));
638 write_data_u32(wr, len).and(Ok(Marker::Str32))
639 }
640}
641
642/// Encodes and attempts to write the most efficient string implementation to the given `Write`.
643///

Callers 1

write_strFunction · 0.85

Calls 2

write_fixvalFunction · 0.85
write_markerFunction · 0.85

Tested by

no test coverage detected