serde_bolt 0.1.2

Bitcoin Lightning BOLT message serializer / deserializer
Documentation

serde-BOLT

Crate Documentation Safety Dance

An incomplete implementation of the Lightning BOLT message serialization format.

Domain-specific types are not implemented. You can just use Vec<u8> or [u8; nnn] or a wrapped version thereof.

Structs and tuples are considered transparent - they are not delimited in the stream.

Unimplemented

  • TLVs
  • Leading-zero-dropped integers

Usage

    use hex::{encode, decode};
    use serde_derive::{Serialize, Deserialize};

    use serde_bolt::{to_vec, from_vec, Error};

    #[derive(Serialize, Deserialize, PartialEq, Debug)]
    struct Test {
        x: bool,
        a: u32,
        b: u8,
        c: Option<u16>,
        d: Option<u16>,
        e: Vec<u8>,
    }

    #[test]
    fn test_simple() {
        let test = Test {
            x: true,
            a: 65538, b:160, c: None, d: Some(3),
            e: vec![0x33, 0x44],
        };
        let result = to_vec(&test).unwrap();
        assert_eq!("0100010002a00001000300023344", encode(&result));

        let decoded: Test = from_vec(&mut result.clone()).unwrap();
        assert_eq!(test, decoded);
    }