Enum tezos_data_encoding::encoding::Encoding
source · pub enum Encoding {
Show 35 variants
Unit,
Int8,
Uint8,
Int16,
Uint16,
Int31,
Int32,
Uint32,
Int64,
RangedInt,
Z,
Mutez,
Float,
RangedFloat,
Bool,
String,
BoundedString(usize),
Bytes,
Tags(usize, TagMap),
List(Box<Encoding>),
BoundedList(usize, Box<Encoding>),
Enum,
Option(Box<Encoding>),
OptionalField(Box<Encoding>),
Obj(&'static str, Schema),
Tup(Vec<Encoding>),
ShortDynamic(Box<Encoding>),
Dynamic(Box<Encoding>),
BoundedDynamic(usize, Box<Encoding>),
Sized(usize, Box<Encoding>),
Bounded(usize, Box<Encoding>),
Greedy(Box<Encoding>),
Hash(HashType),
Timestamp,
Custom,
}Expand description
Represents schema used for encoding a data into a json or a binary form.
Variants§
Unit
Encoded as nothing in binary or null in json
Int8
Signed 8 bit integer (data is encoded as a byte in binary and an integer in JSON).
Uint8
Unsigned 8 bit integer (data is encoded as a byte in binary and an integer in JSON).
Int16
Signed 16 bit integer (data is encoded as a short in binary and an integer in JSON).
Uint16
Unsigned 16 bit integer (data is encoded as a short in binary and an integer in JSON).
Int31
Signed 31 bit integer, which corresponds to type int on 32-bit OCaml systems (data is encoded as a 32 bit int in binary and an integer in JSON).
Int32
Signed 32 bit integer (data is encoded as a 32-bit int in binary and an integer in JSON).
Uint32
Unsigned 32 bit integer (data is encoded as a 32-bit int in binary and an integer in JSON).
Int64
Signed 64 bit integer (data is encoded as a 64-bit int in binary and a decimal string in JSON).
RangedInt
Integer with bounds in a given range. Both bounds are inclusive.
Z
Big number In JSON, data is encoded as a decimal string. In binary, data is encoded as a variable length sequence of bytes, with a running unary size bit: the most significant bit of each byte tells is this is the last byte in the sequence (0) or if there is more to read (1). The second most significant bit of the first byte is reserved for the sign (positive if zero). Binary_size and sign bits ignored, data is then the binary representation of the absolute value of the number in little-endian order.
Mutez
Big number Almost identical to Encoding::Z, but does not contain the sign bit in the second most significant bit of the first byte
Float
Encoding of floating point number (encoded as a floating point number in JSON and a double in binary).
RangedFloat
Float with bounds in a given range. Both bounds are inclusive.
Bool
Encoding of a boolean (data is encoded as a byte in binary and a boolean in JSON).
String
Encoding of a string
- encoded as a byte sequence in binary prefixed by the length of the string
- encoded as a string in JSON.
BoundedString(usize)
Encoding of a string
- encoded as a byte sequence in binary prefixed by the length of the string
- encoded as a string in JSON.
Bytes
Encoding of arbitrary sized bytes (encoded via hex in JSON and directly as a sequence byte in binary).
Tags(usize, TagMap)
Tag is prefixed by tag id and followed by encoded bytes First argument represents size of the tag marker in bytes.
List(Box<Encoding>)
List combinator. It’s behavior is similar to Encoding::Greedy encoding. Main distinction is that we are expecting list of items instead of a single item to be contained in binary data.
- encoded as an array in JSON
- encoded as the concatenation of all the element in binary
BoundedList(usize, Box<Encoding>)
Encode enumeration via association list
- represented as a string in JSON and
- represented as an integer representing the element’s position in the list in binary. The integer size depends on the list size.
Enum
Encode enumeration via association list
- represented as a string in JSON and
- represented as an integer representing the element’s position in the list in binary. The integer size depends on the list size.
Option(Box<Encoding>)
Combinator to make an optional value (represented as a 1-byte tag followed by the data (or nothing) in binary and either the raw value or an empty object in JSON).
Compatible with ocaml usage: (req “arg” (Data_encoding.option string))
OptionalField(Box<Encoding>)
TE-172 - combinator to make an optional field, this is not the same as Encoding::Option (req “arg” (Data_encoding.option string)) is not the same as (opt “arg” string))
Compatible with ocaml usage: (opt “arg” string)
Obj(&'static str, Schema)
Is the collection of fields. not prefixed by anything in binary, encoded as the concatenation of all the element in binary
Tup(Vec<Encoding>)
Heterogeneous collection of values. Similar to Encoding::Obj, but schema can be any types, not just fields. Encoded as continuous binary representation.
ShortDynamic(Box<Encoding>)
Is the collection of fields. prefixed its length in bytes (1 Bytes), encoded as the concatenation of all the element in binary
Dynamic(Box<Encoding>)
Is the collection of fields. prefixed its length in bytes (4 Byte), encoded as the concatenation of all the element in binary
BoundedDynamic(usize, Box<Encoding>)
Is the collection of fields. prefixed its length in bytes (4 Bytes), encoded as the concatenation of all the element in binary
Sized(usize, Box<Encoding>)
Represents fixed size block in binary encoding.
Bounded(usize, Box<Encoding>)
Represents bounded block in binary encoding (one with a length that cannot exceed the upper value).
Greedy(Box<Encoding>)
Almost same as Encoding::Dynamic but without bytes size information prefix. It assumes that encoding passed as argument will process rest of the available data.
Hash(HashType)
Decode various types of hashes. Hash has it’s own predefined length and prefix. This is controller by a hash implementation.
Timestamp
Timestamp encoding.
- encoded as RFC 3339 in json
- encoded as Encoding::Int64 in binary
Custom
This is used to perform encoding using custom function rather than basing on schema. Used to get rid of recursion while encoding/decoding recursive types.
Implementations§
source§impl Encoding
impl Encoding
sourcepub fn list(encoding: Encoding) -> Encoding
pub fn list(encoding: Encoding) -> Encoding
Utility function to construct Encoding::List without the need to manually create new Box.
sourcepub fn bounded_list(max: usize, encoding: Encoding) -> Encoding
pub fn bounded_list(max: usize, encoding: Encoding) -> Encoding
Utility function to construct Encoding::List without the need to manually create new Box.
sourcepub fn sized(bytes_sz: usize, encoding: Encoding) -> Encoding
pub fn sized(bytes_sz: usize, encoding: Encoding) -> Encoding
Utility function to construct Encoding::Sized without the need to manually create new Box.
sourcepub fn bounded(max: usize, encoding: Encoding) -> Encoding
pub fn bounded(max: usize, encoding: Encoding) -> Encoding
Utility function to construct Encoding::Sized without the need to manually create new Box.
sourcepub fn greedy(encoding: Encoding) -> Encoding
pub fn greedy(encoding: Encoding) -> Encoding
Utility function to construct Encoding::Greedy without the need to manually create new Box.
sourcepub fn short_dynamic(encoding: Encoding) -> Encoding
pub fn short_dynamic(encoding: Encoding) -> Encoding
Utility function to construct Encoding::ShortDynamic without the need to manually create new Box.
sourcepub fn dynamic(encoding: Encoding) -> Encoding
pub fn dynamic(encoding: Encoding) -> Encoding
Utility function to construct Encoding::Dynamic without the need to manually create new Box.
sourcepub fn bounded_dynamic(max: usize, encoding: Encoding) -> Encoding
pub fn bounded_dynamic(max: usize, encoding: Encoding) -> Encoding
Utility function to construct Encoding::Dynamic without the need to manually create new Box.
sourcepub fn option(encoding: Encoding) -> Encoding
pub fn option(encoding: Encoding) -> Encoding
Utility function to construct Encoding::Option without the need to manually create new Box.
sourcepub fn option_field(encoding: Encoding) -> Encoding
pub fn option_field(encoding: Encoding) -> Encoding
Utility function to construct Encoding::OptionalField without the need to manually create new Box.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Encoding
impl Send for Encoding
impl Sync for Encoding
impl Unpin for Encoding
impl UnwindSafe for Encoding
Blanket Implementations§
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_mut() into the pipe
function.§impl<T> Pipe for T
impl<T> Pipe for T
§impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
§impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
§impl<T> PipeDeref for T
impl<T> PipeDeref for T
§impl<T> PipeRef for T
impl<T> PipeRef for T
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
§fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
.tap_ref_mut() only in debug builds, and is erased in release
builds.§impl<T> Tap for T
impl<T> Tap for T
§fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap<F, R>(self, func: F) -> Selfwhere F: FnOnce(&Self) -> R,
§fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Selfwhere F: FnOnce(&Self) -> R,
tap in debug builds, and does nothing in release builds.§fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Selfwhere F: FnOnce(&mut Self) -> R,
§fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere F: FnOnce(&mut Self) -> R,
tap_mut in debug builds, and does nothing in release builds.§impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
impl<T, U> TapAsRef<U> for Twhere U: ?Sized,
§fn tap_ref<F, R>(self, func: F) -> Selfwhere
Self: AsRef<T>,
F: FnOnce(&T) -> R,
fn tap_ref<F, R>(self, func: F) -> Selfwhere Self: AsRef<T>, F: FnOnce(&T) -> R,
§fn tap_ref_dbg<F, R>(self, func: F) -> Selfwhere
Self: AsRef<T>,
F: FnOnce(&T) -> R,
fn tap_ref_dbg<F, R>(self, func: F) -> Selfwhere Self: AsRef<T>, F: FnOnce(&T) -> R,
tap_ref in debug builds, and does nothing in release builds.§fn tap_ref_mut<F, R>(self, func: F) -> Selfwhere
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_ref_mut<F, R>(self, func: F) -> Selfwhere Self: AsMut<T>, F: FnOnce(&mut T) -> R,
§fn tap_ref_mut_dbg<F, R>(self, func: F) -> Selfwhere
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_ref_mut_dbg<F, R>(self, func: F) -> Selfwhere Self: AsMut<T>, F: FnOnce(&mut T) -> R,
tap_ref_mut in debug builds, and does nothing in release builds.§impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
impl<T, U> TapBorrow<U> for Twhere U: ?Sized,
§fn tap_borrow<F, R>(self, func: F) -> Selfwhere
Self: Borrow<T>,
F: FnOnce(&T) -> R,
fn tap_borrow<F, R>(self, func: F) -> Selfwhere Self: Borrow<T>, F: FnOnce(&T) -> R,
§fn tap_borrow_dbg<F, R>(self, func: F) -> Selfwhere
Self: Borrow<T>,
F: FnOnce(&T) -> R,
fn tap_borrow_dbg<F, R>(self, func: F) -> Selfwhere Self: Borrow<T>, F: FnOnce(&T) -> R,
tap_borrow in debug builds, and does nothing in release builds.§fn tap_borrow_mut<F, R>(self, func: F) -> Selfwhere
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut<F, R>(self, func: F) -> Selfwhere Self: BorrowMut<T>, F: FnOnce(&mut T) -> R,
§fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Selfwhere
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Selfwhere Self: BorrowMut<T>, F: FnOnce(&mut T) -> R,
tap_borrow_mut in debug builds, and does nothing in release
builds.§impl<T> TapDeref for T
impl<T> TapDeref for T
§fn tap_deref<F, R>(self, func: F) -> Selfwhere
Self: Deref,
F: FnOnce(&Self::Target) -> R,
fn tap_deref<F, R>(self, func: F) -> Selfwhere Self: Deref, F: FnOnce(&Self::Target) -> R,
self for inspection.§fn tap_deref_dbg<F, R>(self, func: F) -> Selfwhere
Self: Deref,
F: FnOnce(&Self::Target) -> R,
fn tap_deref_dbg<F, R>(self, func: F) -> Selfwhere Self: Deref, F: FnOnce(&Self::Target) -> R,
tap_deref in debug builds, and does nothing in release builds.§fn tap_deref_mut<F, R>(self, func: F) -> Selfwhere
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut<F, R>(self, func: F) -> Selfwhere Self: DerefMut, F: FnOnce(&mut Self::Target) -> R,
self for modification.§fn tap_deref_mut_dbg<F, R>(self, func: F) -> Selfwhere
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Selfwhere Self: DerefMut, F: FnOnce(&mut Self::Target) -> R,
tap_deref_mut in debug builds, and does nothing in release
builds.