Skip to content

Commit

Permalink
Expose Serializer and Deserializer directly
Browse files Browse the repository at this point in the history
Allows external projects to plug BCS into libraries that expect a
`serde` `Serializer` or `Deserializer` implementation.
  • Loading branch information
Twey committed Nov 14, 2023
1 parent 1d03bda commit 45c7a6b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ where
}

/// Deserialization implementation for BCS
struct Deserializer<R> {
input: R,
pub struct Deserializer<'de> {
input: &'de [u8],
max_remaining_depth: usize,
}

Expand All @@ -155,7 +155,7 @@ impl<'de, R: Read> Deserializer<TeeReader<'de, R>> {
impl<'de> Deserializer<&'de [u8]> {
/// Creates a new `Deserializer` which will be deserializing the provided
/// input.
fn new(input: &'de [u8], max_remaining_depth: usize) -> Self {
pub fn new(input: &'de [u8], max_remaining_depth: usize) -> Self {
Deserializer {
input,
max_remaining_depth,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,13 @@ pub const MAX_SEQUENCE_LENGTH: usize = (1 << 31) - 1;
pub const MAX_CONTAINER_DEPTH: usize = 500;

pub use de::{
Deserializer,
from_bytes, from_bytes_seed, from_bytes_seed_with_limit, from_bytes_with_limit, from_reader,
from_reader_seed, from_reader_seed_with_limit, from_reader_with_limit,
};
pub use error::{Error, Result};
pub use ser::{
Serializer,
is_human_readable, serialize_into, serialize_into_with_limit, serialized_size,
serialized_size_with_limit, to_bytes, to_bytes_with_limit,
};
7 changes: 3 additions & 4 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub fn is_human_readable() -> bool {
}

/// Serialization implementation for BCS
struct Serializer<'a, W: ?Sized> {
pub struct Serializer<'a, W: ?Sized> {
output: &'a mut W,
max_remaining_depth: usize,
}
Expand All @@ -150,7 +150,7 @@ where
W: ?Sized + std::io::Write,
{
/// Creates a new `Serializer` which will emit BCS.
fn new(output: &'a mut W, max_remaining_depth: usize) -> Self {
pub fn new(output: &'a mut W, max_remaining_depth: usize) -> Self {
Self {
output,
max_remaining_depth,
Expand Down Expand Up @@ -479,8 +479,7 @@ where
}
}

#[doc(hidden)]
struct MapSerializer<'a, W: ?Sized> {
pub struct MapSerializer<'a, W: ?Sized> {
serializer: Serializer<'a, W>,
entries: Vec<(Vec<u8>, Vec<u8>)>,
next_key: Option<Vec<u8>>,
Expand Down

0 comments on commit 45c7a6b

Please sign in to comment.