v0.4.3: tuple struct serialization bug
This commit is contained in:
parent
814ac8f858
commit
ad32bbe26e
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bipack_ru"
|
name = "bipack_ru"
|
||||||
version = "0.4.2"
|
version = "0.4.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
description = "binary size-effective format used in Divan smart contracts, wasm bindings, network protocols, etc."
|
description = "binary size-effective format used in Divan smart contracts, wasm bindings, network protocols, etc."
|
||||||
|
34
src/de.rs
34
src/de.rs
@ -3,7 +3,7 @@ use serde::de::value::U32Deserializer;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::bipack_source::{BipackError, BipackSource, SliceSource};
|
use crate::bipack_source::{BipackError, BipackSource, SliceSource};
|
||||||
use crate::error::{Result};
|
use crate::error::Result;
|
||||||
|
|
||||||
pub struct Deserializer<T: BipackSource> {
|
pub struct Deserializer<T: BipackSource> {
|
||||||
// This string starts with the input data and characters are truncated off
|
// This string starts with the input data and characters are truncated off
|
||||||
@ -264,12 +264,12 @@ mod tests {
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use crate::bipack_source::BipackError;
|
|
||||||
|
|
||||||
|
use crate::bipack_source::BipackError;
|
||||||
use crate::de::from_bytes;
|
use crate::de::from_bytes;
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
use crate::ser::{to_buffer, to_bytes};
|
use crate::ser::{to_buffer, to_bytes};
|
||||||
use crate::tools::to_dump;
|
use crate::tools::{to_dump};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ints() -> Result<()> {
|
fn test_ints() -> Result<()> {
|
||||||
@ -406,4 +406,32 @@ mod tests {
|
|||||||
assert_eq!(6, to_bytes(&z).unwrap().len());
|
assert_eq!(6, to_bytes(&z).unwrap().len());
|
||||||
assert_eq!(z, to_bytes(&z).unwrap()[1..]);
|
assert_eq!(z, to_bytes(&z).unwrap()[1..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is real life sample bug:
|
||||||
|
#[derive(Debug,Serialize,Deserialize,Eq, PartialEq)]
|
||||||
|
pub enum LogLevel {
|
||||||
|
Debug,
|
||||||
|
Info,
|
||||||
|
Warning,
|
||||||
|
Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize,Deserialize,Debug,PartialEq)]
|
||||||
|
pub struct LogArgs(
|
||||||
|
pub LogLevel,
|
||||||
|
pub String
|
||||||
|
);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_logargs() {
|
||||||
|
let x = LogArgs(LogLevel::Debug,"hello".to_string());
|
||||||
|
let packed = to_bytes(&x).unwrap();
|
||||||
|
// println!("{}", packed.to_dump());
|
||||||
|
let y: LogArgs = from_bytes(&packed).unwrap();
|
||||||
|
// println!("{:?}", y);
|
||||||
|
assert_eq!(LogLevel::Debug, y.0);
|
||||||
|
assert_eq!("hello", y.1);
|
||||||
|
assert_eq!(7, packed.len());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -172,7 +172,7 @@ impl<'a, S: BipackSink> ser::Serializer for &'a mut Serializer<S> {
|
|||||||
_name: &'static str,
|
_name: &'static str,
|
||||||
len: usize,
|
len: usize,
|
||||||
) -> Result<Self::SerializeTupleStruct> {
|
) -> Result<Self::SerializeTupleStruct> {
|
||||||
self.serialize_seq(Some(len))
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_tuple_variant(
|
fn serialize_tuple_variant(
|
||||||
|
Loading…
Reference in New Issue
Block a user