@@ -121,6 +121,20 @@ pub fn write_u64<W: RmpWrite>(wr: &mut W, val: u64) -> Result<(), ValueWriteErro
121121 Ok ( ( ) )
122122}
123123
124+ /// Encodes and attempts to write an `u8` value into the given write using the most efficient
125+ /// representation, returning the marker used.
126+ ///
127+ /// See [`write_uint`] for more info.
128+ pub fn write_uint8 < W : RmpWrite > ( wr : & mut W , val : u8 ) -> Result < Marker , ValueWriteError < W :: Error > > {
129+ if val < 128 {
130+ write_pfix ( wr, val as u8 )
131+ . and ( Ok ( Marker :: FixPos ( val as u8 ) ) )
132+ . map_err ( ValueWriteError :: InvalidMarkerWrite )
133+ } else {
134+ write_u8 ( wr, val as u8 ) . and ( Ok ( Marker :: U8 ) )
135+ }
136+ }
137+
124138/// Encodes and attempts to write an `u64` value into the given write using the most efficient
125139/// representation, returning the marker used.
126140///
@@ -135,12 +149,8 @@ pub fn write_u64<W: RmpWrite>(wr: &mut W, val: u64) -> Result<(), ValueWriteErro
135149/// This function will return `ValueWriteError` on any I/O error occurred while writing either the
136150/// marker or the data.
137151pub fn write_uint < W : RmpWrite > ( wr : & mut W , val : u64 ) -> Result < Marker , ValueWriteError < W :: Error > > {
138- if val < 128 {
139- write_pfix ( wr, val as u8 )
140- . and ( Ok ( Marker :: FixPos ( val as u8 ) ) )
141- . map_err ( ValueWriteError :: InvalidMarkerWrite )
142- } else if val < 256 {
143- write_u8 ( wr, val as u8 ) . and ( Ok ( Marker :: U8 ) )
152+ if val < 256 {
153+ write_uint8 ( wr, val as u8 )
144154 } else if val < 65536 {
145155 write_u16 ( wr, val as u16 ) . and ( Ok ( Marker :: U16 ) )
146156 } else if val < 4294967296 {
0 commit comments