This repository was archived by the owner on Aug 15, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -280,16 +280,16 @@ where
280280 }
281281
282282 fn try_parse_u128 ( & mut self ) -> Result < Option < u128 > > {
283- // ^ Only *try* parse because the value could be a non-u128 byte array .
283+ // ^ Only *try* parse because the value could be a non-u128 bytestring .
284284 let desc = match self . peek ( ) ? {
285285 Some ( desc) => desc,
286286 None => return Ok ( None ) ,
287287 } ;
288288 let ty = desc >> 5 ;
289289 if ty != 2 {
290- return Ok ( None ) ;
290+ return Ok ( None ) ; // not a bytestring
291291 }
292- let len = desc & 0x1fu8 ;
292+ let len = desc & 0x1f ;
293293 if len > 16 {
294294 return Ok ( None ) ;
295295 }
@@ -730,7 +730,7 @@ where
730730 Some ( value) => visitor. visit_i128 ( -1 - value as i128 ) ,
731731 None => self . parse_value ( visitor) ,
732732 } ,
733- 0xc1 | 0xc4 ..=0xd7 => self . parse_value ( visitor) ,
733+ 0xc0 | 0xc1 | 0xc4 ..=0xd7 => self . parse_value ( visitor) ,
734734 0xd8 => {
735735 self . parse_u8 ( ) ?;
736736 self . parse_value ( visitor)
@@ -770,8 +770,7 @@ where
770770 }
771771 0xfc ..=0xfe => Err ( self . error ( ErrorCode :: UnassignedCode ) ) ,
772772 0xff => Err ( self . error ( ErrorCode :: UnexpectedCode ) ) ,
773-
774- _ => unreachable ! ( ) ,
773+ _ => unreachable ! ( ) // Remove this once minimum supported rustc version is 1.33.0.
775774 }
776775 }
777776}
Original file line number Diff line number Diff line change @@ -183,13 +183,13 @@ where
183183 if len <= 8 {
184184 self . write_u64 ( tag - 2 , value as u64 )
185185 } else {
186+ let mut buf = [ 0u8 ; 2 + 16 ] ;
187+ BigEndian :: write_u128 ( & mut buf[ 2 ..] , value) ;
188+ let hdr_offset = 16 - len as usize ;
189+ buf[ hdr_offset] = 6 << 5 | tag;
190+ buf[ hdr_offset + 1 ] = 2 << 5 | len as u8 ;
186191 self . writer
187- . write_all ( & [ 6 << 5 | tag, 2 << 5 | len as u8 ] )
188- . map_err ( |e| e. into ( ) ) ?;
189- let mut buf = [ 0u8 ; 16 ] ;
190- BigEndian :: write_u128 ( & mut buf, value) ;
191- self . writer
192- . write_all ( & buf[ ( 16 - len) as usize ..] )
192+ . write_all ( & buf[ hdr_offset..] )
193193 . map_err ( |e| e. into ( ) )
194194 }
195195 }
You can’t perform that action at this time.
0 commit comments