Struct chronicle::queue::ValueIn

#[repr(C)]
pub struct ValueIn { /* private fields */ }
Expand description

The ValueIn type provides a normalised interface for reading content from a Chronicle Wire, which in turn abstracts underlying binary resources such as Queue documents.

Users will normally use a ValueIn type indirectly from a Wire or DocumentContext rather than explicitly manage ValueIn instances. See Wire and DocumentContext for more details and examples of recommended use with Queue

Implementations§

Returns a shared reference to the associated Wire

Returns a string from the current read position; increments the read position

Returns a bool from the current read position; increments the read position

Returns an i8 from the current read position; increments the read position

Returns a u8 from the current read position; increments the read position

Returns an i16 from the current read position; increments the read position

Returns a u16 from the current read position; increments the read position

Returns an i32 from the current read position; increments the read position

Returns a u32 from the current read position; increments the read position

Returns an i64 from the current read position; increments the read position

Returns an f32 from the current read position; increments the read position

Returns an f64 from the current read position; increments the read position

Returns a &[u8] slice from the current read position; increments the read position

alias to int8(), for syntactic equivalence with Java

alias to uint16(), for syntactic equivalence with Java

alias to int16(), for syntactic equivalence with Java

alias to int32(), for syntactic equivalence with Java

alias to int64(), for syntactic equivalence with Java

alias to f32(), for syntactic equivalence with Java

alias to f64(), for syntactic equivalence with Java

alias to string(), for syntactic equivalence with Java

The object method reads the raw bytes of an object at the current read position, incrementing the read position. The total number bytes read is size_of::<T>().

The type T must implement the Default trait.

The type T should be “trivially copyable” such that an object of the type can be safely copied and reconstructed by simply copying its binary representatioin in memory.

Trivially copyable types can be copied more efficiently, which can lead to important performance benefits. Types which are not trivially copyable will either need to use bespoke serialisation (for example reading from a slice obtained from scoped_bytes_reader), or alternatively using self-describing marshallable types (see marshallable).

Example
#[derive(PartialEq)]
#[derive(Debug)]
#[derive(Default)]
struct Simple {
    val1: i32,
    val2: f32
}

fn example() {
    let queue = queue::SingleChronicleQueueBuilder::new("example").build().unwrap();
    let tailer = queue.create_tailer().unwrap();
    {
        let context = tailer.scoped_reading_document();
        let wire = context.wire();
        let value_in = wire.value_in();

        let simple = value_in.object::<Simple>();
    }
}

The marshallable method enables a Wire-based closure to be applied to this ValueIn as a single action. One of the most useful use cases for this is reading fully self-describing content from a queue in a completely flexible format (eg to remove constraints on userdata schema changes).

Example

This example shows how a marshallable can be used to flexibly deserialise a self-describing trade object keyed with the “trade” label within the document:

let tailer = queue.create_tailer().unwrap();
{
    let context = tailer.scoped_reading_document();
    let wire = context.wire();
    wire.read("trade").marshallable(|w|{
        let symbol = w.read("symbol").string();
        let price = w.read("price").float64();
        let quantity = w.read("quantity").float64();
         // ...
    });
}

Trait Implementations§

§

type Id

A type-level representation of the type’s C++ namespace and type name. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.