Skip to content

Commit

Permalink
Replace prost with protobuf in misc/prost-codec
Browse files Browse the repository at this point in the history
  • Loading branch information
kckeiks committed Oct 25, 2022
1 parent 437b387 commit 29e6c38
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
6 changes: 6 additions & 0 deletions misc/prost-codec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.2.1 [unreleased]

- Remove `prost` and add `protobuf`. See [PR 3050].

[PR 3050]: https://github.com/libp2p/rust-libp2p/pull/3050

# 0.2.0

- Update to prost(-build) `v0.11`. See [PR 2788].
Expand Down
5 changes: 1 addition & 4 deletions misc/prost-codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ categories = ["asynchronous"]
[dependencies]
asynchronous-codec = { version = "0.6" }
bytes = { version = "1" }
prost = "0.11"
protobuf = "3.2"
thiserror = "1.0"
unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] }

[dev-dependencies]
prost-build = "0.11"

# Passing arguments to the docsrs builder in order to properly document cfg's.
# More information: https://docs.rs/about/builds#cross-compiling
[package.metadata.docs.rs]
Expand Down
16 changes: 7 additions & 9 deletions misc/prost-codec/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use asynchronous_codec::{Decoder, Encoder};
use bytes::BytesMut;
use prost::Message;
use std::io::Cursor;
use bytes::Bytes;
use protobuf::Message;
use std::marker::PhantomData;
use thiserror::Error;
use unsigned_varint::codec::UviBytes;
Expand Down Expand Up @@ -41,11 +40,10 @@ impl<In: Message, Out> Encoder for Codec<In, Out> {
item: Self::Item,
dst: &mut asynchronous_codec::BytesMut,
) -> Result<(), Self::Error> {
let mut encoded_msg = BytesMut::new();
item.encode(&mut encoded_msg)
.expect("BytesMut to have sufficient capacity.");
let bytes = item.write_to_bytes()
.expect("Failed to write to bytes.");
self.uvi
.encode(encoded_msg.freeze(), dst)
.encode(Bytes::from(bytes), dst)
.map_err(|e| e.into())
}
}
Expand All @@ -61,7 +59,7 @@ impl<In, Out: Message + Default> Decoder for Codec<In, Out> {
Ok(self
.uvi
.decode(src)?
.map(|msg| Message::decode(Cursor::new(msg)))
.map(|msg| Message::parse_from_bytes(msg.as_ref()))
.transpose()?)
}
}
Expand All @@ -72,7 +70,7 @@ pub enum Error {
Decode(
#[from]
#[source]
prost::DecodeError,
protobuf::Error,
),
#[error("Io error {0}")]
Io(
Expand Down

0 comments on commit 29e6c38

Please sign in to comment.