File tree 2 files changed +8
-0
lines changed 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> {
148
148
// String IDs in the table data are encoded in big endian format, while string
149
149
// IDs in the index are encoded in little endian format. Don't mix the two up.
150
150
fn 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.
151
154
assert ! ( bytes[ 0 ] == STRING_REF_TAG ) ;
152
155
assert ! ( STRING_REF_ENCODED_SIZE == 5 ) ;
156
+
153
157
let id = u32:: from_le_bytes ( bytes[ 1 ..5 ] . try_into ( ) . unwrap ( ) ) ;
154
158
StringId :: new ( id)
155
159
}
Original file line number Diff line number Diff line change @@ -180,7 +180,11 @@ impl<'s> StringComponent<'s> {
180
180
& mut bytes[ s. len ( ) ..]
181
181
}
182
182
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.
183
186
assert ! ( STRING_REF_ENCODED_SIZE == 5 ) ;
187
+
184
188
bytes[ 0 ] = STRING_REF_TAG ;
185
189
& mut bytes[ 1 ..5 ] . copy_from_slice ( & string_id. 0 . to_le_bytes ( ) ) ;
186
190
& mut bytes[ 5 ..]
You can’t perform that action at this time.
0 commit comments