Skip to content

Commit

Permalink
chore: breaking api change
Browse files Browse the repository at this point in the history
  • Loading branch information
is-it-ayush committed Feb 26, 2024
1 parent 52d4448 commit a814b09
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rust-fr = "0.1"

```rs
use serde::{Serialize, Deserialize};
use rust_fr::protocol;
use rust_fr::{serializer, deserializer};

// define some data
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
Expand All @@ -31,10 +31,10 @@ let human = Human {
};

// serialize the data to bytes (Vec<u8>)
let human_bytes = protocol::serializer::to_bytes(&human).unwrap();
let human_bytes = serializer::to_bytes(&human).unwrap();

// deserialize the data from serialized bytes.
let deserialized_human = protocol::deserializer::from_bytes::<Human>(&human_bytes).unwrap();
let deserialized_human = deserializer::from_bytes::<Human>(&human_bytes).unwrap();

assert_eq!(human, deserialized_human);
```
Expand Down
File renamed without changes.
File renamed without changes.
29 changes: 15 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod protocol;
pub mod error;
pub mod serializer;
pub mod deserializer;

#[cfg(test)]
mod tests {
use crate::protocol;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::{serializer, deserializer};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Primitives {
Expand Down Expand Up @@ -42,11 +44,10 @@ mod tests {
};

// Serialize
let bytes = protocol::serializer::to_bytes(&primitives).unwrap();
let bytes = serializer::to_bytes(&primitives).unwrap();

// Deserialize
let deserialized_primitives =
protocol::deserializer::from_bytes::<Primitives>(&bytes).unwrap();
let deserialized_primitives = deserializer::from_bytes::<Primitives>(&bytes).unwrap();
assert_eq!(primitives, deserialized_primitives);
}

Expand Down Expand Up @@ -87,11 +88,11 @@ mod tests {
};

// Serialize
let bytes = protocol::serializer::to_bytes(&compound_types).unwrap();
let bytes = serializer::to_bytes(&compound_types).unwrap();

// Deserialize
let deserialized_compound_types =
protocol::deserializer::from_bytes::<CompundTypes>(&bytes).unwrap();
deserializer::from_bytes::<CompundTypes>(&bytes).unwrap();
assert_eq!(compound_types, deserialized_compound_types);
}

Expand Down Expand Up @@ -144,10 +145,10 @@ mod tests {
};

// Serialize
let bytes = protocol::serializer::to_bytes(&random).unwrap();
let bytes = serializer::to_bytes(&random).unwrap();

// Deserialize
let deserialized_random = protocol::deserializer::from_bytes::<Random>(&bytes).unwrap();
let deserialized_random = deserializer::from_bytes::<Random>(&bytes).unwrap();
assert_eq!(random, deserialized_random);
}

Expand All @@ -165,10 +166,10 @@ mod tests {
};

// serialize the data to bytes (Vec<u8>)
let human_bytes = protocol::serializer::to_bytes(&human).unwrap();
let human_bytes = serializer::to_bytes(&human).unwrap();

// deserialize the data from serialized bytes.
let deserialized_human = protocol::deserializer::from_bytes::<Human>(&human_bytes).unwrap();
let deserialized_human = deserializer::from_bytes::<Human>(&human_bytes).unwrap();

assert_eq!(human, deserialized_human);
}
Expand Down Expand Up @@ -209,7 +210,7 @@ mod tests {
}),
};

let rust_fr_bytes = protocol::serializer::to_bytes(&data).unwrap();
let rust_fr_bytes = serializer::to_bytes(&data).unwrap();
let serde_json_bytes = serde_json::to_vec(&data).unwrap();
let rmp_serde_bytes = rmp_serde::to_vec(&data).unwrap();
let mut cir_serde_bytes = Vec::new();
Expand All @@ -235,7 +236,7 @@ mod tests {
up: None,
};

let rust_fr_bytes = protocol::serializer::to_bytes(&data).unwrap();
let rust_fr_bytes = serializer::to_bytes(&data).unwrap();
let serde_json_bytes = serde_json::to_vec(&data).unwrap();
let rmp_serde_bytes = rmp_serde::to_vec(&data).unwrap();
let mut cir_serde_bytes = Vec::new();
Expand Down Expand Up @@ -275,7 +276,7 @@ mod tests {
}),
};

let rust_fr_bytes = protocol::serializer::to_bytes(&data).unwrap();
let rust_fr_bytes = serializer::to_bytes(&data).unwrap();
let serde_json_bytes = serde_json::to_vec(&data).unwrap();
let rmp_serde_bytes = rmp_serde::to_vec(&data).unwrap();
let mut cir_serde_bytes = Vec::new();
Expand Down
3 changes: 0 additions & 3 deletions src/protocol/mod.rs

This file was deleted.

File renamed without changes.

0 comments on commit a814b09

Please sign in to comment.