Skip to main content

FlexBuffersDeserializer

Struct FlexBuffersDeserializer 

Source
pub struct FlexBuffersDeserializer;
Expand description

Deserializes batches of QueryEvents from FlexBuffers format

Implementations§

Source§

impl FlexBuffersDeserializer

Source

pub fn deserialize_batch( bytes: &[u8], ) -> Result<DeserializedBatch, DeserializationError>

Deserialize a batch of events from FlexBuffers binary format

Returns the deserialized events along with batch metadata

Examples found in repository?
examples/deserialize.rs (line 36)
4fn main() {
5    println!("Scry Protocol - Deserialization Example\n");
6
7    // First, create and serialize some events
8    // (In a real scenario, these bytes would come from the network)
9    println!("Creating sample batch...");
10    let events = vec![
11        QueryEventBuilder::new("SELECT * FROM users WHERE id = 1")
12            .connection_id("conn-001")
13            .database("production")
14            .duration(Duration::from_millis(5))
15            .rows(1)
16            .build(),
17        QueryEventBuilder::new("UPDATE users SET last_login = NOW() WHERE id = 1")
18            .connection_id("conn-001")
19            .database("production")
20            .duration(Duration::from_millis(8))
21            .rows(1)
22            .build(),
23        QueryEventBuilder::new("SELECT COUNT(*) FROM orders WHERE user_id = 1")
24            .connection_id("conn-001")
25            .database("production")
26            .duration(Duration::from_millis(12))
27            .rows(1)
28            .build(),
29    ];
30
31    let bytes = FlatBuffersSerializer::serialize_batch(&events, "proxy-demo", 42);
32    println!("Serialized {} events into {} bytes\n", events.len(), bytes.len());
33
34    // Now deserialize the batch
35    println!("Deserializing batch...");
36    match FlexBuffersDeserializer::deserialize_batch(&bytes) {
37        Ok(batch) => {
38            println!("Deserialization successful!\n");
39
40            println!("Batch metadata:");
41            println!("  Proxy ID: {}", batch.proxy_id);
42            println!("  Batch sequence: {}", batch.batch_seq);
43            println!("  Event count: {}\n", batch.events.len());
44
45            println!("Events:");
46            for (i, event) in batch.events.iter().enumerate() {
47                println!("  Event {}:", i + 1);
48                println!("    ID: {}", event.event_id);
49                println!("    Query: {}", event.query);
50                println!("    Database: {}", event.database);
51                println!("    Connection: {}", event.connection_id);
52                println!("    Duration: {:?}", event.duration);
53                println!("    Rows: {:?}", event.rows);
54                println!("    Success: {}", event.success);
55                if let Some(err) = &event.error {
56                    println!("    Error: {}", err);
57                }
58                println!();
59            }
60
61            println!("All events deserialized successfully!");
62        }
63        Err(e) => {
64            eprintln!("Deserialization failed: {}", e);
65            std::process::exit(1);
66        }
67    }
68}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.