Struct chronicle::queue::ValueOut

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

The ValueOut type provides a normalised interface for writing content to a Chronicle Wire, which in turn abstracts underlying binary resources such as Queue documents.

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

Implementations§

Returns a shared reference to the associated Wire

Writes the given string at the current write position; increments the write position

Writes the given bool at the current write position; increments the write position

Writes the given i8 at the current write position; increments the write position

Writes the given u8 at the current write position; increments the write position

Writes the given i16 at the current write position; increments the write position

Writes the given u16 at the current write position; increments the write position

Writes the given i32 at the current write position; increments the write position

Writes the given u32 at the current write position; increments the write position

Writes the given i64 at the current write position; increments the write position

Writes the given f32 at the current write position; increments the write position

Writes the given f64 at the current write position; increments the write position

Writes the given &[u8] slice at the current write position; increments the write 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 float32(), for syntactic equivalence with Java

alias to float64(), for syntactic equivalence with Java

alias to string(), for syntactic equivalence with Java

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

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 writing to a slice obtained from reserve_bytes), 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 appender = q.acquire_appender().unwrap();
    {
        let context = appender.scoped_writing_document();
        let wire = context.wire();
        let value_out = wire.value_out();

        let simple = Simple { val1: 42, val2: 3.14 };
        value_out.object(&simple);
    }
}

The marshallable method enables a Wire-based closure to be applied to this ValueOut as a single action. One of the most useful use cases for this is writing fully self-describing content to 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 serialise a self-describing trade object keyed with the “trade” label within the document:

let appender = queue.acquire_appender().unwrap();
{
    let context = appender.scoped_writing_document();
    let wire = context.wire();
    wire.write("trade").marshallable(|w|{
        w.write("symbol").string("EURUSD")
         .write("price").float64(1.234)
         .write("quantity").float64(15e6)
         // ...
    });
}

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.