Enum expry::DecodedValue
source · pub enum DecodedValue<'a> {
Null,
Bool(bool),
Int(i64),
Float(f32),
Double(f64),
String(&'a [u8]),
Array(DecodedArray<'a>),
Object(DecodedObject<'a>),
}
Expand description
The central data type of expry. It is modelled similar to JSON, however, contains a couple of noteworthy differences.
The differences with JSON:
- There is an explicit integer type;
- Floats are either 32-bits or 64-bits;
- All strings are u8: they can contain both text or binary data.
To convert DecodedValue to JSON, one can use the formatting options like:
use expry::*;
let value = value!({"foo": 42});
let output = format!("JSON output: {}", value);
assert_eq!(output, r#"JSON output: {"foo":42}"#);
Variants§
Null
Bool(bool)
Int(i64)
Signed 64-bits integer (that is packed into smaller value in the wire format if possible).
Float(f32)
32-bits float type.
Double(f64)
64-bits float type.
String(&'a [u8])
Can be both binary data as regular strings. So not necessary UTF-8 (like Rust strings).
Array(DecodedArray<'a>)
Object(DecodedObject<'a>)
Implementations§
source§impl<'a> DecodedValue<'a>
impl<'a> DecodedValue<'a>
pub fn is_valid_json(&self) -> bool
source§impl<'a> DecodedValue<'a>
impl<'a> DecodedValue<'a>
pub const fn type_string(&self) -> &'static str
sourcepub fn size_of_binary(&self) -> usize
pub fn size_of_binary(&self) -> usize
Returns the size needed if we serialize the Binary to a binary wire-format.
See DecodedValue::print_binary()
for explanation of the compact
argument.
sourcepub fn print_binary<E, Out: RawOutput<E>>(
&self,
writer: &mut Out
) -> Result<(), E>
pub fn print_binary<E, Out: RawOutput<E>>( &self, writer: &mut Out ) -> Result<(), E>
Converts a Binary to a wire representation of that Binary. This wire representation can be sent to other implementations as it is stable and ‘endian safe’.
For objects we have a compact
representation and one that inserts hints how to process the wire-representation faster when
using an expression to evaluate the Binary to another value. This is controlled with the
compact
argument.
This function expects that the writer
has enough room. The needed room can be queried
beforehand by using the DecodedValue::size_of_binary
.
sourcepub fn encode_to_vec(&self) -> EncodedValueVec
pub fn encode_to_vec(&self) -> EncodedValueVec
Converts a Binary to a wire representation of that Binary, in a self contained EncodedValueVec
unsing DecodedValue::print_binary
.
sourcepub fn encode_to_scope<'c>(
&self,
scope: &mut MemoryScope<'c>
) -> EncodedValueRef<'c>
pub fn encode_to_scope<'c>( &self, scope: &mut MemoryScope<'c> ) -> EncodedValueRef<'c>
Converts a Binary to a wire representation of that Binary, in a self contained EncodedValueVec
unsing DecodedValue::print_binary
.
sourcepub fn print_json(&self, writer: &mut String) -> Result<(), Utf8Error>
pub fn print_json(&self, writer: &mut String) -> Result<(), Utf8Error>
Convert a Binary value to a JSON output.
Note that some Binary values can not be encoded, because not all strings can be encoded as UTF-8. If this is the case, this method will result in a Utf8Error
. If non-UTF8 data needs to be ignored, use format!("{}", decoded_value)
or similar methods.
pub fn easy(&'a self) -> Easy<'a>
source§impl<'a> DecodedValue<'a>
impl<'a> DecodedValue<'a>
pub fn decoded_type_of(type_and_length: u64) -> Result<ValueType, EncodingError>
sourcepub const fn type_of_binary(type_and_length: u64) -> u8
pub const fn type_of_binary(type_and_length: u64) -> u8
Based on a variable length integer read for the wire, return the ValueType
raw number.
sourcepub const fn length_of_binary(type_and_length: u64) -> usize
pub const fn length_of_binary(type_and_length: u64) -> usize
Based on a variable length integer read for the wire, return the length of the current entry.
pub fn decoded_type_and_length( type_and_length: u64 ) -> Result<(ValueType, usize), EncodingError>
sourcepub fn decode<'b>(
reader: &mut RawReader<'a>
) -> Result<DecodedValue<'b>, EncodingError>where
'a: 'b,
pub fn decode<'b>(
reader: &mut RawReader<'a>
) -> Result<DecodedValue<'b>, EncodingError>where
'a: 'b,
Parse the wire-format. Note that although the input is malformed, it can still work out (keys of objects are not properly sorted, will not have an impact).
pub fn valid(reader: &mut RawReader<'a>) -> Result<(), EncodingError>
source§impl<'a> DecodedValue<'a>
impl<'a> DecodedValue<'a>
pub fn parse_json<'b, 'c>(
reader: &'a str,
allocator: &mut MemoryScope<'c>
) -> Result<DecodedValue<'b>, CompileError<'b>>where
'c: 'b,
'a: 'b,
pub fn parse_expression_to_value<'c>(
reader: &'a str,
scope: &mut MemoryScope<'c>
) -> Result<DecodedValue<'a>, CompileError<'a>>where
'c: 'a,
Trait Implementations§
source§impl<'a> Clone for DecodedValue<'a>
impl<'a> Clone for DecodedValue<'a>
source§fn clone(&self) -> DecodedValue<'a>
fn clone(&self) -> DecodedValue<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a, 'b, 'c> CloneInMemoryScope<'c, DecodedValue<'b>> for DecodedValue<'a>where
'c: 'b,
impl<'a, 'b, 'c> CloneInMemoryScope<'c, DecodedValue<'b>> for DecodedValue<'a>where
'c: 'b,
fn clone_in(&self, scope: &mut MemoryScope<'c>) -> DecodedValue<'b>
source§impl<'a> Debug for DecodedValue<'a>
impl<'a> Debug for DecodedValue<'a>
source§impl<'a> Default for DecodedValue<'a>
impl<'a> Default for DecodedValue<'a>
source§fn default() -> DecodedValue<'a>
fn default() -> DecodedValue<'a>
source§impl<'a> Display for DecodedValue<'a>
impl<'a> Display for DecodedValue<'a>
source§impl<'a, T> From<&'a &'a [T]> for DecodedValue<'a>
impl<'a, T> From<&'a &'a [T]> for DecodedValue<'a>
source§impl<'a, 'b> From<&'b &'a String> for DecodedValue<'a>
impl<'a, 'b> From<&'b &'a String> for DecodedValue<'a>
source§impl<'a, 'b> From<&'b &'a str> for DecodedValue<'a>
impl<'a, 'b> From<&'b &'a str> for DecodedValue<'a>
source§impl<'a> From<&'a [u8]> for DecodedValue<'a>
impl<'a> From<&'a [u8]> for DecodedValue<'a>
source§impl<'a> From<&BytecodeRef<'a>> for DecodedValue<'a>
impl<'a> From<&BytecodeRef<'a>> for DecodedValue<'a>
source§fn from(v: &BytecodeRef<'a>) -> Self
fn from(v: &BytecodeRef<'a>) -> Self
source§impl<'a> From<&'a BytecodeVec> for DecodedValue<'a>
impl<'a> From<&'a BytecodeVec> for DecodedValue<'a>
source§fn from(v: &'a BytecodeVec) -> Self
fn from(v: &'a BytecodeVec) -> Self
source§impl<'a> From<&DecodedValue<'a>> for DecodedValue<'a>
impl<'a> From<&DecodedValue<'a>> for DecodedValue<'a>
source§fn from(v: &DecodedValue<'a>) -> Self
fn from(v: &DecodedValue<'a>) -> Self
source§impl<'a, T: 'a> From<&'a Option<T>> for DecodedValue<'a>
impl<'a, T: 'a> From<&'a Option<T>> for DecodedValue<'a>
source§impl<'a> From<&'a String> for DecodedValue<'a>
impl<'a> From<&'a String> for DecodedValue<'a>
source§impl<'a, T> From<&'a Vec<T>> for DecodedValue<'a>
impl<'a, T> From<&'a Vec<T>> for DecodedValue<'a>
source§impl<'a> From<&bool> for DecodedValue<'a>
impl<'a> From<&bool> for DecodedValue<'a>
source§impl<'a> From<&f32> for DecodedValue<'a>
impl<'a> From<&f32> for DecodedValue<'a>
source§impl<'a> From<&f64> for DecodedValue<'a>
impl<'a> From<&f64> for DecodedValue<'a>
source§impl<'a> From<&i64> for DecodedValue<'a>
impl<'a> From<&i64> for DecodedValue<'a>
source§impl<'a> From<&'a mut [u8]> for DecodedValue<'a>
impl<'a> From<&'a mut [u8]> for DecodedValue<'a>
source§impl<'a> From<&'a mut str> for DecodedValue<'a>
impl<'a> From<&'a mut str> for DecodedValue<'a>
source§impl<'a> From<&'a str> for DecodedValue<'a>
impl<'a> From<&'a str> for DecodedValue<'a>
source§impl<'a> PartialEq for DecodedValue<'a>
impl<'a> PartialEq for DecodedValue<'a>
source§fn eq(&self, other: &DecodedValue<'a>) -> bool
fn eq(&self, other: &DecodedValue<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a> PartialOrd for DecodedValue<'a>
impl<'a> PartialOrd for DecodedValue<'a>
source§fn partial_cmp(&self, other: &DecodedValue<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &DecodedValue<'a>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more