Skip to content

Commit fc2424b

Browse files
committed
Add raw bytes functions
Part of #45875
1 parent 72176cf commit fc2424b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libserialize/opaque.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ impl<'a> Encoder<'a> {
2727
pub fn new(cursor: &'a mut io::Cursor<Vec<u8>>) -> Encoder<'a> {
2828
Encoder { cursor: cursor }
2929
}
30+
31+
pub fn emit_raw_bytes(&mut self, s: &[u8]) -> EncodeResult {
32+
self.cursor.write_all(s)
33+
}
3034
}
3135

3236

@@ -169,6 +173,16 @@ impl<'a> Decoder<'a> {
169173
pub fn advance(&mut self, bytes: usize) {
170174
self.position += bytes;
171175
}
176+
177+
pub fn read_raw_bytes(&mut self, s: &mut [u8]) -> Result<(), String> {
178+
let len = s.len();
179+
180+
self.position += len;
181+
182+
s.copy_from_slice(&self.data[0..len]);
183+
184+
Ok(())
185+
}
172186
}
173187

174188
macro_rules! read_uleb128 {

0 commit comments

Comments
 (0)