]> git.lizzy.rs Git - rust.git/commitdiff
Add raw bytes functions
authorWesley Wiser <wwiser@gmail.com>
Wed, 20 Dec 2017 03:31:15 +0000 (22:31 -0500)
committerWesley Wiser <wwiser@gmail.com>
Sat, 6 Jan 2018 19:57:27 +0000 (14:57 -0500)
Part of #45875

src/libserialize/opaque.rs

index 99557659b297bfbb794220802b66c8a700439763..4b2549a1aed2ba1cd6eca3024f7d5df6708108e9 100644 (file)
@@ -27,6 +27,10 @@ impl<'a> Encoder<'a> {
     pub fn new(cursor: &'a mut io::Cursor<Vec<u8>>) -> Encoder<'a> {
         Encoder { cursor: cursor }
     }
+
+    pub fn emit_raw_bytes(&mut self, s: &[u8]) -> EncodeResult {
+        self.cursor.write_all(s)
+    }
 }
 
 
@@ -169,6 +173,16 @@ pub fn set_position(&mut self, pos: usize) {
     pub fn advance(&mut self, bytes: usize) {
         self.position += bytes;
     }
+
+    pub fn read_raw_bytes(&mut self, s: &mut [u8]) -> Result<(), String> {
+        let len = s.len();
+
+        self.position += len;
+
+        s.copy_from_slice(&self.data[0..len]);
+
+        Ok(())
+    }
 }
 
 macro_rules! read_uleb128 {