Skip to content

Commit

Permalink
Return to 0.34 ABCI encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
hdevalence committed Sep 20, 2022
1 parent 1e054f7 commit c0c4e7d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions abci/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ where
message.encode(&mut buf).map_err(Error::encode)?;

let buf = buf.freeze();
prost::encoding::encode_varint(buf.len() as u64, &mut dst);
encode_varint(buf.len() as u64, &mut dst);
dst.put(buf);
Ok(())
}
Expand All @@ -142,11 +142,12 @@ where
{
let src_len = src.len();
let mut tmp = src.clone().freeze();
let encoded_len = match prost::encoding::decode_varint(&mut tmp) {
let encoded_len = match decode_varint(&mut tmp) {
Ok(len) => len,
// We've potentially only received a partial length delimiter
Err(_) if src_len <= MAX_VARINT_LENGTH => return Ok(None),
Err(e) => return Err(Error::decode(e)),
//Err(e) => return Err(Error::decode(e)),
Err(e) => return Err(e),
};
let remaining = tmp.remaining() as u64;
if remaining < encoded_len {
Expand All @@ -164,3 +165,14 @@ where
Ok(Some(res))
}
}

// encode_varint and decode_varint will be removed once
// https://github.com/tendermint/tendermint/issues/5783 lands in Tendermint.
pub fn encode_varint<B: BufMut>(val: u64, mut buf: &mut B) {
prost::encoding::encode_varint(val << 1, &mut buf);
}

pub fn decode_varint<B: Buf>(mut buf: &mut B) -> Result<u64, Error> {
let len = prost::encoding::decode_varint(&mut buf).map_err(Error::decode)?;
Ok(len >> 1)
}

0 comments on commit c0c4e7d

Please sign in to comment.