Function pack_note

Source
pub fn pack_note(note: &Note) -> Result<Vec<u8>, Error>
Expand description

Packs a Note into its compact binary notepack representation.

This function serializes a Note into the raw notepack binary format:

  • Adds version (currently 1) as a varint.
  • Encodes fixed-size fields (id, pubkey, sig) as raw bytes.
  • Writes variable-length fields (content, tags) with varint length prefixes.
  • Optimizes strings that look like 32-byte hex by storing them in a compressed form.

Returns a Vec<u8> containing the binary payload, or an Error if hex decoding fails.

This is the low-level encoding API—most callers will want pack_note_to_string instead.

§Errors

Returns [Error::Hex] if any hex string field (like id, pubkey, or sig) fails to decode.

§Example

use notepack::{Note, pack_note};

let note = Note { /* ... */ };
let binary = pack_note(&note).unwrap();
assert!(binary.len() > 0);