#[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§
§impl ValueIn
impl ValueIn
pub fn read_short(&self) -> i16
pub fn read_short(&self) -> i16
alias to int16()
, for syntactic equivalence with Java
§impl ValueIn
impl ValueIn
pub fn read_float(&self) -> f32
pub fn read_float(&self) -> f32
alias to f32()
, for syntactic equivalence with Java
§impl ValueIn
impl ValueIn
pub fn read_double(&self) -> f64
pub fn read_double(&self) -> f64
alias to f64()
, for syntactic equivalence with Java
§impl ValueIn
impl ValueIn
pub fn read_string(&self) -> String
pub fn read_string(&self) -> String
alias to string()
, for syntactic equivalence with Java
§impl ValueIn
impl ValueIn
pub fn object<T>(&self) -> Twhere
T: Default,
pub fn object<T>(&self) -> Twhere
T: Default,
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>();
}
}
pub fn marshallable<F>(&self, cb: F) -> boolwhere
F: FnMut(&Wire),
pub fn marshallable<F>(&self, cb: F) -> boolwhere
F: FnMut(&Wire),
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();
// ...
});
}