Skip to content

encode_vec() isn't infallible #1064

@hu55a1n1

Description

@hu55a1n1

What went wrong?

tendermint_proto::Protobuf::encode_vec() cannot fail since it uses a vector with required capacity and calls prost::Message::encode() which only fails if the input buffer doesn't have sufficient capacity.

fn encode_vec(&self) -> Result<Vec<u8>, Error> {
    let mut wire = Vec::with_capacity(self.encoded_len());
    self.encode(&mut wire).map(|_| wire)
}

Definition of "done"

tendermint_proto::Protobuf::encode_vec() could simply return a Vec<u8> and unwrap() internally.

fn encode_vec(&self) -> Vec<u8> {
    let mut wire = Vec::with_capacity(self.encoded_len());
    self.encode(&mut wire).map(|_| wire).unwrap()
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions