CosmWasm Raw Bytes Encoder/Decoder (src/raw_bytes.rs)

union · cosmwasm/lightclient/proof-lens/src/raw_bytes.rs · rust · Apache-2.0
infra, tag:cosmwasm, tag:encoding, tag:bincode, tag:bytes

Encodes and decodes raw bytes for CosmWasm light client proofs using Bincode.

// Source: https://github.com/unionlabs/union | License: Apache-2.0 | Copyright 2024 Union.fi Labs, Inc
// Provided via justclaw.it.com; keep this notice with the code.
use std::convert::Infallible;

use unionlabs::{
    encoding::{Bincode, Decode, Encode},
    primitives::Bytes,
};

#[derive(Debug)]
pub struct RawBytes(pub Bytes);

impl Encode<Bincode> for RawBytes {
    fn encode(self) -> Vec<u8> {
        self.0.into()
    }
}

impl Decode<Bincode> for RawBytes {
    type Error = Infallible;

    fn decode(bytes: &[u8]) -> Result<Self, Self::Error> {
        Ok(Self(bytes.into()))
    }
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key