pub struct EncodedPayload { /* private fields */ }Expand description
EncodedPayload represents a payload that has had an encoding applied to it.
Encoding Format:
The encoded payload consists of two parts:
-
Header (32 bytes):
- Byte 0: Always 0x00 (reserved)
- Byte 1: Encoding Version byte (e.g., 0x00 for PayloadEncodingVersion::Zero)
- Bytes 2-5: Big-endian u32 representing the original payload length
- Bytes 6-31: Reserved (filled with 0x00)
-
Data (multiple of 32 bytes): Each 32-byte chunk contains:
- Byte 0: 0x00 (padding byte to ensure the data is in valid field element range)
- Bytes 1-31: 31 bytes of actual payload data (or padding for the last chunk)
The padding ensures that all data is compatible with the bn254 curve’s field element limitations, as each 32-byte segment represents a field element.
Implementations§
Source§impl EncodedPayload
impl EncodedPayload
Sourcepub fn new(payload: &Payload) -> Result<EncodedPayload, ConversionError>
pub fn new(payload: &Payload) -> Result<EncodedPayload, ConversionError>
Creates a new EncodedPayload from a Payload, performing the PayloadEncodingVersion0 encoding.
Sourcepub fn decode(&self) -> Result<Payload, ConversionError>
pub fn decode(&self) -> Result<Payload, ConversionError>
Decodes the EncodedPayload back into a Payload.
Sourcepub fn to_field_elements(&self) -> Vec<Fr> ⓘ
pub fn to_field_elements(&self) -> Vec<Fr> ⓘ
Converts the encoded payload to an array of field elements.
Sourcepub fn from_field_elements(
field_elements: &[Fr],
max_payload_length: usize,
) -> Result<EncodedPayload, ConversionError>
pub fn from_field_elements( field_elements: &[Fr], max_payload_length: usize, ) -> Result<EncodedPayload, ConversionError>
Creates an EncodedPayload from an array of field elements.
max_payload_length is the maximum length in bytes that the contained Payload is permitted to be.
Trait Implementations§
Source§impl Debug for EncodedPayload
impl Debug for EncodedPayload
Source§impl PartialEq for EncodedPayload
impl PartialEq for EncodedPayload
Source§fn eq(&self, other: &EncodedPayload) -> bool
fn eq(&self, other: &EncodedPayload) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for EncodedPayload
Auto Trait Implementations§
impl Freeze for EncodedPayload
impl RefUnwindSafe for EncodedPayload
impl Send for EncodedPayload
impl Sync for EncodedPayload
impl Unpin for EncodedPayload
impl UnsafeUnpin for EncodedPayload
impl UnwindSafe for EncodedPayload
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more