#[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§
§impl ValueOut
impl ValueOut
pub fn write_byte(&self, int8: i8) -> &Wire
pub fn write_byte(&self, int8: i8) -> &Wire
alias to int8()
, for syntactic equivalence with Java
§impl ValueOut
impl ValueOut
pub fn write_char(&self, uint16: u16) -> &Wire
pub fn write_char(&self, uint16: u16) -> &Wire
alias to uint16()
, for syntactic equivalence with Java
§impl ValueOut
impl ValueOut
pub fn write_short(&self, int16: i16) -> &Wire
pub fn write_short(&self, int16: i16) -> &Wire
alias to int16()
, for syntactic equivalence with Java
§impl ValueOut
impl ValueOut
pub fn write_long(&self, int64: i64) -> &Wire
pub fn write_long(&self, int64: i64) -> &Wire
alias to int64()
, for syntactic equivalence with Java
§impl ValueOut
impl ValueOut
pub fn write_float(&self, f32: f32) -> &Wire
pub fn write_float(&self, f32: f32) -> &Wire
alias to float32()
, for syntactic equivalence with Java
§impl ValueOut
impl ValueOut
pub fn write_double(&self, f64: f64) -> &Wire
pub fn write_double(&self, f64: f64) -> &Wire
alias to float64()
, for syntactic equivalence with Java
§impl<'a> ValueOut
impl<'a> ValueOut
pub fn write_string(&'a self, str: &str) -> &'a Wire
pub fn write_string(&'a self, str: &str) -> &'a Wire
alias to string()
, for syntactic equivalence with Java
§impl ValueOut
impl ValueOut
pub fn object<T>(&self, objref: &T)
pub fn object<T>(&self, objref: &T)
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);
}
}
pub fn marshallable<F>(&self, cb: F) -> &Wirewhere
F: FnMut(&Wire),
pub fn marshallable<F>(&self, cb: F) -> &Wirewhere
F: FnMut(&Wire),
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)
// ...
});
}