Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Serializer and Deserializer directly #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ where
}

/// Deserialization implementation for BCS
struct Deserializer<R> {
pub struct Deserializer<R> {
input: R,
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
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ pub const MAX_CONTAINER_DEPTH: usize = 500;

pub use de::{
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,
from_reader_seed, from_reader_seed_with_limit, from_reader_with_limit, Deserializer,
};
pub use error::{Error, Result};
pub use ser::{
is_human_readable, serialize_into, serialize_into_with_limit, serialized_size,
serialized_size_with_limit, to_bytes, to_bytes_with_limit,
serialized_size_with_limit, to_bytes, to_bytes_with_limit, Serializer,
};
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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the #[doc(hidden)] ?

Copy link
Author

@Twey Twey Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was previously redundant, but you're right, it's now relevant. I was fooled by this regression in rustc — but I see that as the older rustc in CI finds, this is indeed incorrect since we're accidentally exposing the internal BcsDeserializer trait.

I'm a bit loath to expose BcsDeserializer, though, which looks to be quite internal, so I'll look at refactoring it when I get a moment. I have a suspicion it can be broken down into Read/BufRead + serde::Deserializer — or even if it can't completely we can expose those more standard bounds instead of the internal BcsDeserializer.

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
Loading