pub struct FlexBuffersDeserializer;Expand description
Deserializes batches of QueryEvents from FlexBuffers format
Implementations§
Source§impl FlexBuffersDeserializer
impl FlexBuffersDeserializer
Sourcepub fn deserialize_batch(
bytes: &[u8],
) -> Result<DeserializedBatch, DeserializationError>
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§
impl Freeze for FlexBuffersDeserializer
impl RefUnwindSafe for FlexBuffersDeserializer
impl Send for FlexBuffersDeserializer
impl Sync for FlexBuffersDeserializer
impl Unpin for FlexBuffersDeserializer
impl UnsafeUnpin for FlexBuffersDeserializer
impl UnwindSafe for FlexBuffersDeserializer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more