Skip to content

Commit

Permalink
use smaller length numbers for VoteTally serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-babichenko committed Oct 15, 2020
1 parent aeb1761 commit e186d00
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions chain-impl-mockchain/src/certificate/vote_plan.rs
Expand Up @@ -288,12 +288,6 @@ impl VotePlan {
}

pub fn serialize_in(&self, bb: ByteBuilder<Self>) -> ByteBuilder<Self> {
let mut member_keys_buf: ByteBuilder<u8> = ByteBuilder::new();
member_keys_buf = member_keys_buf.u64(self.committee_public_keys.len() as u64);
for key in &self.committee_public_keys {
let buf = key.to_bytes();
member_keys_buf = member_keys_buf.u64(buf.len() as u64).bytes(&buf);
}
bb.u32(self.vote_start.epoch)
.u32(self.vote_start.slot_id)
.u32(self.vote_end.epoch)
Expand All @@ -304,7 +298,10 @@ impl VotePlan {
.iter8(&mut self.proposals.iter(), |bb, proposal| {
proposal.serialize_in(bb)
})
.bytes(member_keys_buf.finalize().as_slice())
.iter8(self.committee_public_keys.iter(), |bb, key| {
let key_bytes = key.to_bytes();
bb.u32(key_bytes.len() as u32).bytes(&key_bytes)
})
}

pub fn serialize(&self) -> ByteArray<Self> {
Expand Down Expand Up @@ -443,10 +440,10 @@ impl Readable for VotePlan {
proposals.proposals.push(proposal);
}

let member_keys_len = buf.get_u64()?;
let member_keys_len = buf.get_u8()?;
let mut committee_public_keys = Vec::new();
for _ in 0..member_keys_len {
let key_len = buf.get_u64()?;
let key_len = buf.get_u32()?;
let key_buf = buf.get_slice(key_len as usize)?;
// Unwrap should be ok here, since we did serialize it ourselves
committee_public_keys.push(MemberPublicKey::from_bytes(key_buf).ok_or_else(|| {
Expand Down

0 comments on commit e186d00

Please sign in to comment.