From fc2424b988c926004b93c28524be7f8a9388bdf7 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Tue, 19 Dec 2017 22:31:15 -0500 Subject: [PATCH] Add raw bytes functions Part of #45875 --- src/libserialize/opaque.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libserialize/opaque.rs b/src/libserialize/opaque.rs index 99557659b29..4b2549a1aed 100644 --- a/src/libserialize/opaque.rs +++ b/src/libserialize/opaque.rs @@ -27,6 +27,10 @@ impl<'a> Encoder<'a> { pub fn new(cursor: &'a mut io::Cursor>) -> Encoder<'a> { Encoder { cursor: cursor } } + + pub fn emit_raw_bytes(&mut self, s: &[u8]) -> EncodeResult { + self.cursor.write_all(s) + } } @@ -169,6 +173,16 @@ impl<'a> Decoder<'a> { 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 {