kbinxml(cargo): upgrade to bytes 0.5

This commit is contained in:
Matt Bilker 2019-12-10 03:09:00 +00:00
parent ce0764af58
commit 70f10c56ac
No known key found for this signature in database
GPG Key ID: 69ADF8AEB6C8B5D1
8 changed files with 34 additions and 34 deletions

View File

@ -8,7 +8,7 @@ edition = "2018"
[dependencies]
byteorder = "1.3.2"
bytes = "0.4.10"
bytes = "0.5.2"
encoding_rs = "0.8.6"
indexmap = "1.0.1"
lazy_static = "1.0.0"

View File

@ -141,7 +141,7 @@ impl ByteBufferRead {
let start = self.data_buf_offset();
let end = self.check_read_size(start, size)?;
let data = self.buffer.slice(start, end);
let data = self.buffer.slice(start..end);
trace!(
"buf_read_size => index: {}, size: {}, data: 0x{:02x?}",
self.cursor.position(),
@ -192,14 +192,14 @@ impl ByteBufferRead {
let (check_old, data) = match size {
1 => {
let end = self.check_read_size(self.offset_1, 1)?;
let data = self.buffer.slice(self.offset_1, end);
let data = self.buffer.slice(self.offset_1..end);
self.offset_1 += 1;
(true, data)
},
2 => {
let end = self.check_read_size(self.offset_2, 2)?;
let data = self.buffer.slice(self.offset_2, end);
let data = self.buffer.slice(self.offset_2..end);
self.offset_2 += 2;
(true, data)

View File

@ -81,7 +81,7 @@ pub fn from_bytes(input: Bytes) -> Result<(NodeCollection, EncodingType)> {
#[inline]
pub fn from_slice(input: &[u8]) -> Result<(NodeCollection, EncodingType)> {
from_binary(Bytes::from(input))
from_binary(Bytes::from(input.to_vec()))
}
pub fn to_binary<T>(input: &T) -> Result<Vec<u8>>

View File

@ -8,8 +8,8 @@ use crate::reader::Reader;
pub struct Printer;
impl Printer {
pub fn run(input: &[u8]) -> Result<()> {
let mut reader = Reader::new(Bytes::from(input))?;
pub fn run(input: impl Into<Bytes>) -> Result<()> {
let mut reader = Reader::new(input.into())?;
let mut nodes = Vec::new();
let mut definitions = Vec::new();

View File

@ -96,7 +96,7 @@ pub struct Reader {
impl Reader {
pub fn new(input: Bytes) -> Result<Self, ReaderError> {
let mut header = Cursor::new(input.clone());
let mut header = Cursor::new(&input);
let signature = header.read_u8().context(Signature)?;
if signature != SIGNATURE {
@ -134,8 +134,8 @@ impl Reader {
// The data buffer is everything after that.
let node_buffer_end = 8 + len_node as usize;
let data_buffer_start = node_buffer_end + 4;
let node_buf = ByteBufferRead::new(input.slice(8, node_buffer_end));
let data_buf = ByteBufferRead::new(input.slice_from(data_buffer_start));
let node_buf = ByteBufferRead::new(input.slice(8..node_buffer_end));
let data_buf = ByteBufferRead::new(input.slice(data_buffer_start..));
Ok(Self {
compression,

View File

@ -102,7 +102,7 @@ impl<'a> TextXmlReader<'a> {
}
fn parse_attribute(&self, key: &[u8], value: &[u8]) -> Result<NodeDefinition, TextReaderError> {
let mut value = BytesMut::from(value.to_vec());
let mut value = BytesMut::from(value);
// Add the trailing null byte that kbin has at the end of strings
value.reserve(1);
@ -111,7 +111,7 @@ impl<'a> TextXmlReader<'a> {
let data = NodeData::Some {
key: Key::Uncompressed {
encoding: self.encoding,
data: Bytes::from(key),
data: Bytes::from(key.to_vec()),
},
value_data: value.freeze(),
};
@ -198,7 +198,7 @@ impl<'a> TextXmlReader<'a> {
let data = NodeData::Some {
key: Key::Uncompressed {
encoding: self.encoding,
data: Bytes::from(e.name()),
data: Bytes::from(e.name().to_vec()),
},
value_data,
};
@ -218,7 +218,7 @@ impl<'a> TextXmlReader<'a> {
let data = event.unescaped()?;
let data = match definition.node_type {
StandardType::String | StandardType::NodeStart => {
let mut data = BytesMut::from(data.into_owned());
let mut data = BytesMut::from(&*data);
// Add the trailing null byte that kbin has at the end of strings
data.reserve(1);

View File

@ -1,8 +1,8 @@
use std::io::Read;
use std::net::Ipv4Addr;
use byteorder::ReadBytesExt;
use bytes::{BigEndian, BufMut};
use byteorder::{BigEndian, ReadBytesExt};
use bytes::BufMut;
use snafu::ResultExt;
use crate::error::*;
@ -186,14 +186,14 @@ macro_rules! tuple_impl {
}
multibyte_impl! {
(i16, put_i16_be, read_i16),
(u16, put_u16_be, read_u16),
(i32, put_i32_be, read_i32),
(u32, put_u32_be, read_u32),
(i64, put_i64_be, read_i64),
(u64, put_u64_be, read_u64),
(f32, put_f32_be, read_f32),
(f64, put_f64_be, read_f64),
(i16, put_i16, read_i16),
(u16, put_u16, read_u16),
(i32, put_i32, read_i32),
(u32, put_u32, read_u32),
(i64, put_i64, read_i64),
(u64, put_u64, read_u64),
(f32, put_f32, read_f32),
(f64, put_f64, read_f64),
}
tuple_impl! {
@ -201,13 +201,13 @@ tuple_impl! {
u8: [2, 3, 4, 16],
bool: [2, 3, 4, 16],
multi: [
[i16; 2, 3, 4, 8] => (put_i16_be, read_i16_into),
[u16; 2, 3, 4, 8] => (put_u16_be, read_u16_into),
[i32; 2, 3, 4] => (put_i32_be, read_i32_into),
[u32; 2, 3, 4] => (put_u32_be, read_u32_into),
[i64; 2, 3, 4] => (put_i64_be, read_i64_into),
[u64; 2, 3, 4] => (put_u64_be, read_u64_into),
[f32; 2, 3, 4] => (put_f32_be, read_f32_into),
[f64; 2, 3, 4] => (put_f64_be, read_f64_into),
[i16; 2, 3, 4, 8] => (put_i16, read_i16_into),
[u16; 2, 3, 4, 8] => (put_u16, read_u16_into),
[i32; 2, 3, 4] => (put_i32, read_i32_into),
[u32; 2, 3, 4] => (put_u32, read_u32_into),
[i64; 2, 3, 4] => (put_i64, read_i64_into),
[u64; 2, 3, 4] => (put_u64, read_u64_into),
[f32; 2, 3, 4] => (put_f32, read_f32_into),
[f64; 2, 3, 4] => (put_f64, read_f64_into),
]
}

View File

@ -104,7 +104,7 @@ fn main() -> Result<(), anyhow::Error> {
if kbinxml::is_binary_xml(&contents) {
if printer_enabled {
Printer::run(&contents)?;
Printer::run(contents.clone())?;
}
let (collection, _encoding) = kbinxml::from_slice(&contents)?;
@ -121,7 +121,7 @@ fn main() -> Result<(), anyhow::Error> {
let buf = kbinxml::to_binary_with_options(options, &collection)?;
if printer_enabled {
Printer::run(&buf)?;
Printer::run(buf.clone())?;
}
io::stdout().write_all(&buf)?;