File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -148,8 +148,12 @@ impl<'st> StringRef<'st> {
148148// String IDs in the table data are encoded in big endian format, while string
149149// IDs in the index are encoded in little endian format. Don't mix the two up.
150150fn decode_string_ref_from_data ( bytes : & [ u8 ] ) -> StringId {
151+ // The code below assumes we use a 5-byte encoding for string
152+ // refs, where the first byte is STRING_REF_TAG and the
153+ // following 4 bytes are a little-endian u32 string ID value.
151154 assert ! ( bytes[ 0 ] == STRING_REF_TAG ) ;
152155 assert ! ( STRING_REF_ENCODED_SIZE == 5 ) ;
156+
153157 let id = u32:: from_le_bytes ( bytes[ 1 ..5 ] . try_into ( ) . unwrap ( ) ) ;
154158 StringId :: new ( id)
155159}
Original file line number Diff line number Diff line change @@ -180,7 +180,11 @@ impl<'s> StringComponent<'s> {
180180 & mut bytes[ s. len ( ) ..]
181181 }
182182 StringComponent :: Ref ( string_id) => {
183+ // The code below assumes we use a 5-byte encoding for string
184+ // refs, where the first byte is STRING_REF_TAG and the
185+ // following 4 bytes are a little-endian u32 string ID value.
183186 assert ! ( STRING_REF_ENCODED_SIZE == 5 ) ;
187+
184188 bytes[ 0 ] = STRING_REF_TAG ;
185189 & mut bytes[ 1 ..5 ] . copy_from_slice ( & string_id. 0 . to_le_bytes ( ) ) ;
186190 & mut bytes[ 5 ..]
You can’t perform that action at this time.
0 commit comments