Skip to content

Commit

Permalink
Address CR comments
Browse files Browse the repository at this point in the history
Co-Authored-By: Markus Westerlind <marwes91@gmail.com>
  • Loading branch information
topisani and Marwes committed Dec 23, 2019
1 parent 9277c18 commit 8998b6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ serde = { version = "1.0.34", features = ["derive"] }
serde_json = "1.0.0"
serde_repr = "0.1"
url = {version = "2.0.0", features = ["serde"]}
base64 = "0.2.1"
byteorder = "1.3.2"
base64 = "0.11.0"

[features]
default = []
Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::collections::HashMap;
#[cfg(feature = "proposed")]
use base64;
#[cfg(feature = "proposed")]
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::convert::TryFrom;
use serde::de;
use serde::de::Error as Error_;
use serde_json::Value;
Expand Down Expand Up @@ -3687,13 +3687,13 @@ impl SemanticHighlightingToken {
{
let s = String::deserialize(deserializer)?;
let bytes =
base64::decode(s.as_str()).map_err(|_| serde::de::Error::custom("Error parsing base64 string"))?;
base64::decode_config(s.as_str(), base64::STANDARD).map_err(|_| serde::de::Error::custom("Error parsing base64 string"))?;
let mut res = Vec::new();
for chunk in bytes.chunks_exact(8) {
res.push(SemanticHighlightingToken {
character: (&chunk[0..4]).read_u32::<BigEndian>().unwrap(),
length: (&chunk[4..6]).read_u16::<BigEndian>().unwrap(),
scope: (&chunk[6..8]).read_u16::<BigEndian>().unwrap(),
character: u32::from_be_bytes(<[u8; 4]>::try_from(&chunk[0..4]).unwrap()),
length: u16::from_be_bytes(<[u8; 2]>::try_from(&chunk[4..6]).unwrap()),
scope: u16::from_be_bytes(<[u8; 2]>::try_from(&chunk[6..8]).unwrap()),
});
}
Result::Ok(res)
Expand All @@ -3709,11 +3709,11 @@ impl SemanticHighlightingToken {
{
let mut bytes = vec![];
for token in tokens {
bytes.write_u32::<BigEndian>(token.character).unwrap();
bytes.write_u16::<BigEndian>(token.length).unwrap();
bytes.write_u16::<BigEndian>(token.scope).unwrap();
bytes.extend_from_slice(&token.character.to_be_bytes());
bytes.extend_from_slice(&token.length.to_be_bytes());
bytes.extend_from_slice(&token.scope.to_be_bytes());
}
serializer.serialize_str(base64::encode(&bytes).as_str())
serializer.collect_str(&base64::display::Base64Display::with_config(&bytes, base64::STANDARD))
}
}

Expand Down

0 comments on commit 8998b6c

Please sign in to comment.