about summary refs log tree commit diff
path: root/compiler/rustc_serialize/src/json.rs
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2021-03-11 22:06:45 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2021-03-19 19:35:22 +0100
commit09a638820e6a2383b9b84333aa588ced80982d0a (patch)
treed34ae37323511392449bb99f992817b496950ce1 /compiler/rustc_serialize/src/json.rs
parente5d09fbbe99f87efdb9ed23d6770fa0f62fdffcf (diff)
downloadrust-09a638820e6a2383b9b84333aa588ced80982d0a.tar.gz
rust-09a638820e6a2383b9b84333aa588ced80982d0a.zip
Move raw bytes handling to Encoder/Decoder.
Diffstat (limited to 'compiler/rustc_serialize/src/json.rs')
-rw-r--r--compiler/rustc_serialize/src/json.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/compiler/rustc_serialize/src/json.rs b/compiler/rustc_serialize/src/json.rs
index bbbe568f17a..51945ab435e 100644
--- a/compiler/rustc_serialize/src/json.rs
+++ b/compiler/rustc_serialize/src/json.rs
@@ -188,6 +188,7 @@ use std::collections::{BTreeMap, HashMap};
 use std::io;
 use std::io::prelude::*;
 use std::mem::swap;
+use std::mem::MaybeUninit;
 use std::num::FpCategory as Fp;
 use std::ops::Index;
 use std::str::FromStr;
@@ -553,6 +554,12 @@ impl<'a> crate::Encoder for Encoder<'a> {
     fn emit_str(&mut self, v: &str) -> EncodeResult {
         escape_str(self.writer, v)
     }
+    fn emit_raw_bytes(&mut self, s: &[u8]) -> Result<(), Self::Error> {
+        for &c in s.iter() {
+            self.emit_u8(c)?;
+        }
+        Ok(())
+    }
 
     fn emit_enum<F>(&mut self, _name: &str, f: F) -> EncodeResult
     where
@@ -879,6 +886,12 @@ impl<'a> crate::Encoder for PrettyEncoder<'a> {
     fn emit_str(&mut self, v: &str) -> EncodeResult {
         escape_str(self.writer, v)
     }
+    fn emit_raw_bytes(&mut self, s: &[u8]) -> Result<(), Self::Error> {
+        for &c in s.iter() {
+            self.emit_u8(c)?;
+        }
+        Ok(())
+    }
 
     fn emit_enum<F>(&mut self, _name: &str, f: F) -> EncodeResult
     where
@@ -2354,6 +2367,14 @@ impl crate::Decoder for Decoder {
         expect!(self.pop(), String).map(Cow::Owned)
     }
 
+    fn read_raw_bytes(&mut self, s: &mut [MaybeUninit<u8>]) -> Result<(), Self::Error> {
+        for c in s.iter_mut() {
+            let h = self.read_u8()?;
+            unsafe { *c.as_mut_ptr() = h };
+        }
+        Ok(())
+    }
+
     fn read_enum<T, F>(&mut self, _name: &str, f: F) -> DecodeResult<T>
     where
         F: FnOnce(&mut Decoder) -> DecodeResult<T>,