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

Function write_uint

src/encode.rs:482–500  ·  view source on GitHub ↗

Encodes and attempts to write an `u64` value into the given write using the most efficient representation, returning the marker used. This function obeys the MessagePack specification, which requires that the serializer SHOULD use the format which represents the data in the smallest number of bytes. The first byte becomes the marker and the others (if present, up to 9) will represent the data it

(wr: &mut W, val: u64)

Source from the content-addressed store, hash-verified

480/// marker or the data, except the EINTR, which is handled internally.
481// TODO: Replace with `match`?
482pub fn write_uint<W>(wr: &mut W, val: u64) -> Result<Marker, ValueWriteError>
483 where W: Write
484{
485 if val < 128 {
486 let marker = Marker::FixPos(val as u8);
487
488 try!(write_fixval(wr, marker));
489
490 Ok(marker)
491 } else if val < 256 {
492 write_u8(wr, val as u8).and(Ok(Marker::U8))
493 } else if val < 65536 {
494 write_u16(wr, val as u16).and(Ok(Marker::U16))
495 } else if val < 4294967296 {
496 write_u32(wr, val as u32).and(Ok(Marker::U32))
497 } else {
498 write_u64(wr, val).and(Ok(Marker::U64))
499 }
500}
501
502/// Encodes and attempts to write an `i64` value into the given write using the most efficient
503/// representation, returning the marker used.

Callers 4

write_valueFunction · 0.85
emit_u64Method · 0.85
visit_u64Method · 0.85
write_value_refFunction · 0.85

Calls 5

write_fixvalFunction · 0.85
write_u8Function · 0.85
write_u16Function · 0.85
write_u32Function · 0.85
write_u64Function · 0.85

Tested by

no test coverage detected