freedomlayer / offset

Offset payment engine
https://www.offsetcredit.org
Other
162 stars 20 forks source link

capnp_conv review + cleanup #230

Open realcr opened 5 years ago

realcr commented 5 years ago

Help required

capnp-conv was written very hastily, and some help is required with improving the code:

What is capnp_conv

capnp_conv is a procedural macro mechanism allowing to automatically derive capnproto serialization and deserialization glue code between Rust structs and capnp structs.

Example for usage (From offst-proto):

#[capnp_conv(crate::funder_capnp::request_send_funds_op)]
#[derive(Eq, PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct RequestSendFundsOp {
    pub request_id: Uid,
    pub src_hashed_lock: HashedLock,
    pub route: FriendsRoute,
    #[capnp_conv(with = Wrapper<u128>)]
    pub dest_payment: u128,
    #[capnp_conv(with = Wrapper<u128>)]
    pub total_dest_payment: u128,
    pub invoice_id: InvoiceId,
    #[capnp_conv(with = Wrapper<u128>)]
    pub left_fees: u128,
}

The user can then invoke: request_send_funds.to_capnp_bytes() or RequestSendFunds::from_capnp_bytes(...)

The design of capnp_conv is inspired by proto_conv.

capnp_conv is currently being used through the whole Offst codebase, mostly in offst-proto.

realcr commented 5 years ago

@pzmarzly : Do you want to take this issue? (Requires some familiarity with procedural macros)