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

Function write_sint

src/encode.rs:519–537  ·  view source on GitHub ↗

Encodes and attempts to write an `i64` 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, with the exception of sized/unsized types. Note, that the function will **always** use signed int

(wr: &mut W, val: i64)

Source from the content-addressed store, hash-verified

517/// This function will return `ValueWriteError` on any I/O error occurred while writing either the
518/// marker or the data, except the EINTR, which is handled internally.
519pub fn write_sint<W>(wr: &mut W, val: i64) -> Result<Marker, ValueWriteError>
520 where W: Write
521{
522 if -32 <= val && val <= 0 {
523 let marker = Marker::FixNeg(val as i8);
524
525 try!(write_fixval(wr, marker));
526
527 Ok(marker)
528 } else if -128 <= val && val < 128 {
529 write_i8(wr, val as i8).and(Ok(Marker::I8))
530 } else if -32768 <= val && val < 32768 {
531 write_i16(wr, val as i16).and(Ok(Marker::I16))
532 } else if -2147483648 <= val && val <= 2147483647 {
533 write_i32(wr, val as i32).and(Ok(Marker::I32))
534 } else {
535 write_i64(wr, val).and(Ok(Marker::I64))
536 }
537}
538
539/// Encodes and attempts to write an `i64` value using the most effective representation.
540fn write_sint_eff<W>(wr: &mut W, val: i64) -> Result<Marker, ValueWriteError>

Callers 3

write_valueFunction · 0.85
visit_i64Method · 0.85
write_value_refFunction · 0.85

Calls 5

write_fixvalFunction · 0.85
write_i8Function · 0.85
write_i16Function · 0.85
write_i32Function · 0.85
write_i64Function · 0.85

Tested by

no test coverage detected