Skip to content

Efficiently serialize non Encodable data #595

@RCasatta

Description

@RCasatta

I've got a use case where I would like to efficiently serialize something like Vec<Option<TxOut>> and I can't use bitcoin::consensus::serialize because Option it's not Encodable and it looks neither I can use serde because it's not efficient at all (maybe because it's json specific?).

let genesis = genesis_block(Network::Bitcoin);
let a = serde_cbor::ser::to_vec_packed(&genesis).unwrap();
assert_eq!(461, a.len());
let b= bitcoin::consensus::serialize(&genesis);
assert_eq!(285, b.len());
let c: Vec<u8> = bincode::serialize(&genesis).unwrap();
assert_eq!(496, c.len());

maybe related rust-bitcoin/rust-secp256k1#295

UPDATED: changed serde_cbor::to_vec to serde_cbor::ser::to_vec_packed because I noticed to_vec store also field names which is unfair compared to others

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions