pub struct QueryEventBuilder { /* private fields */ }Expand description
Builder for creating QueryEvent instances
Implementations§
Source§impl QueryEventBuilder
impl QueryEventBuilder
Sourcepub fn new(query: impl Into<String>) -> Self
pub fn new(query: impl Into<String>) -> Self
Examples found in repository?
examples/serialize.rs (line 9)
4fn main() {
5 println!("Scry Protocol - Serialization Example\n");
6
7 // Create some sample events
8 let events = vec![
9 QueryEventBuilder::new("SELECT * FROM users WHERE id = 1")
10 .connection_id("conn-001")
11 .database("production")
12 .duration(Duration::from_millis(5))
13 .rows(1)
14 .build(),
15 QueryEventBuilder::new("INSERT INTO orders (user_id, total) VALUES (1, 99.99)")
16 .connection_id("conn-001")
17 .database("production")
18 .duration(Duration::from_millis(3))
19 .rows(1)
20 .build(),
21 QueryEventBuilder::new("INVALID SQL QUERY")
22 .connection_id("conn-002")
23 .database("production")
24 .duration(Duration::from_millis(1))
25 .success(false)
26 .error("syntax error at or near \"INVALID\"")
27 .build(),
28 ];
29
30 println!("Created {} events:", events.len());
31 for (i, event) in events.iter().enumerate() {
32 println!(" {}. {} ({})", i + 1, event.query, if event.success { "success" } else { "failed" });
33 }
34
35 // Serialize the batch
36 let proxy_id = "proxy-demo";
37 let batch_seq = 0;
38 let bytes = FlatBuffersSerializer::serialize_batch(&events, proxy_id, batch_seq);
39
40 println!("\nSerialized batch:");
41 println!(" Proxy ID: {}", proxy_id);
42 println!(" Batch seq: {}", batch_seq);
43 println!(" Event count: {}", events.len());
44 println!(" Binary size: {} bytes", bytes.len());
45 println!(" Average bytes/event: {} bytes", bytes.len() / events.len());
46
47 // Show first 32 bytes in hex
48 println!("\nFirst 32 bytes (hex):");
49 let preview = &bytes[..bytes.len().min(32)];
50 for (i, byte) in preview.iter().enumerate() {
51 if i > 0 && i % 16 == 0 {
52 println!();
53 }
54 print!("{:02x} ", byte);
55 }
56 println!();
57
58 println!("\nSerialization complete! These bytes can now be sent over the network.");
59}More examples
examples/deserialize.rs (line 11)
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}pub fn params(self, params: Vec<ParamValue>) -> Self
pub fn params_incomplete(self, incomplete: bool) -> Self
pub fn normalized_query(self, normalized_query: impl Into<String>) -> Self
pub fn value_fingerprints(self, fingerprints: Vec<String>) -> Self
Sourcepub fn duration(self, duration: Duration) -> Self
pub fn duration(self, duration: Duration) -> Self
Examples found in repository?
examples/serialize.rs (line 12)
4fn main() {
5 println!("Scry Protocol - Serialization Example\n");
6
7 // Create some sample events
8 let events = vec![
9 QueryEventBuilder::new("SELECT * FROM users WHERE id = 1")
10 .connection_id("conn-001")
11 .database("production")
12 .duration(Duration::from_millis(5))
13 .rows(1)
14 .build(),
15 QueryEventBuilder::new("INSERT INTO orders (user_id, total) VALUES (1, 99.99)")
16 .connection_id("conn-001")
17 .database("production")
18 .duration(Duration::from_millis(3))
19 .rows(1)
20 .build(),
21 QueryEventBuilder::new("INVALID SQL QUERY")
22 .connection_id("conn-002")
23 .database("production")
24 .duration(Duration::from_millis(1))
25 .success(false)
26 .error("syntax error at or near \"INVALID\"")
27 .build(),
28 ];
29
30 println!("Created {} events:", events.len());
31 for (i, event) in events.iter().enumerate() {
32 println!(" {}. {} ({})", i + 1, event.query, if event.success { "success" } else { "failed" });
33 }
34
35 // Serialize the batch
36 let proxy_id = "proxy-demo";
37 let batch_seq = 0;
38 let bytes = FlatBuffersSerializer::serialize_batch(&events, proxy_id, batch_seq);
39
40 println!("\nSerialized batch:");
41 println!(" Proxy ID: {}", proxy_id);
42 println!(" Batch seq: {}", batch_seq);
43 println!(" Event count: {}", events.len());
44 println!(" Binary size: {} bytes", bytes.len());
45 println!(" Average bytes/event: {} bytes", bytes.len() / events.len());
46
47 // Show first 32 bytes in hex
48 println!("\nFirst 32 bytes (hex):");
49 let preview = &bytes[..bytes.len().min(32)];
50 for (i, byte) in preview.iter().enumerate() {
51 if i > 0 && i % 16 == 0 {
52 println!();
53 }
54 print!("{:02x} ", byte);
55 }
56 println!();
57
58 println!("\nSerialization complete! These bytes can now be sent over the network.");
59}More examples
examples/deserialize.rs (line 14)
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}Sourcepub fn rows(self, rows: u64) -> Self
pub fn rows(self, rows: u64) -> Self
Examples found in repository?
examples/serialize.rs (line 13)
4fn main() {
5 println!("Scry Protocol - Serialization Example\n");
6
7 // Create some sample events
8 let events = vec![
9 QueryEventBuilder::new("SELECT * FROM users WHERE id = 1")
10 .connection_id("conn-001")
11 .database("production")
12 .duration(Duration::from_millis(5))
13 .rows(1)
14 .build(),
15 QueryEventBuilder::new("INSERT INTO orders (user_id, total) VALUES (1, 99.99)")
16 .connection_id("conn-001")
17 .database("production")
18 .duration(Duration::from_millis(3))
19 .rows(1)
20 .build(),
21 QueryEventBuilder::new("INVALID SQL QUERY")
22 .connection_id("conn-002")
23 .database("production")
24 .duration(Duration::from_millis(1))
25 .success(false)
26 .error("syntax error at or near \"INVALID\"")
27 .build(),
28 ];
29
30 println!("Created {} events:", events.len());
31 for (i, event) in events.iter().enumerate() {
32 println!(" {}. {} ({})", i + 1, event.query, if event.success { "success" } else { "failed" });
33 }
34
35 // Serialize the batch
36 let proxy_id = "proxy-demo";
37 let batch_seq = 0;
38 let bytes = FlatBuffersSerializer::serialize_batch(&events, proxy_id, batch_seq);
39
40 println!("\nSerialized batch:");
41 println!(" Proxy ID: {}", proxy_id);
42 println!(" Batch seq: {}", batch_seq);
43 println!(" Event count: {}", events.len());
44 println!(" Binary size: {} bytes", bytes.len());
45 println!(" Average bytes/event: {} bytes", bytes.len() / events.len());
46
47 // Show first 32 bytes in hex
48 println!("\nFirst 32 bytes (hex):");
49 let preview = &bytes[..bytes.len().min(32)];
50 for (i, byte) in preview.iter().enumerate() {
51 if i > 0 && i % 16 == 0 {
52 println!();
53 }
54 print!("{:02x} ", byte);
55 }
56 println!();
57
58 println!("\nSerialization complete! These bytes can now be sent over the network.");
59}More examples
examples/deserialize.rs (line 15)
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}Sourcepub fn success(self, success: bool) -> Self
pub fn success(self, success: bool) -> Self
Examples found in repository?
examples/serialize.rs (line 25)
4fn main() {
5 println!("Scry Protocol - Serialization Example\n");
6
7 // Create some sample events
8 let events = vec![
9 QueryEventBuilder::new("SELECT * FROM users WHERE id = 1")
10 .connection_id("conn-001")
11 .database("production")
12 .duration(Duration::from_millis(5))
13 .rows(1)
14 .build(),
15 QueryEventBuilder::new("INSERT INTO orders (user_id, total) VALUES (1, 99.99)")
16 .connection_id("conn-001")
17 .database("production")
18 .duration(Duration::from_millis(3))
19 .rows(1)
20 .build(),
21 QueryEventBuilder::new("INVALID SQL QUERY")
22 .connection_id("conn-002")
23 .database("production")
24 .duration(Duration::from_millis(1))
25 .success(false)
26 .error("syntax error at or near \"INVALID\"")
27 .build(),
28 ];
29
30 println!("Created {} events:", events.len());
31 for (i, event) in events.iter().enumerate() {
32 println!(" {}. {} ({})", i + 1, event.query, if event.success { "success" } else { "failed" });
33 }
34
35 // Serialize the batch
36 let proxy_id = "proxy-demo";
37 let batch_seq = 0;
38 let bytes = FlatBuffersSerializer::serialize_batch(&events, proxy_id, batch_seq);
39
40 println!("\nSerialized batch:");
41 println!(" Proxy ID: {}", proxy_id);
42 println!(" Batch seq: {}", batch_seq);
43 println!(" Event count: {}", events.len());
44 println!(" Binary size: {} bytes", bytes.len());
45 println!(" Average bytes/event: {} bytes", bytes.len() / events.len());
46
47 // Show first 32 bytes in hex
48 println!("\nFirst 32 bytes (hex):");
49 let preview = &bytes[..bytes.len().min(32)];
50 for (i, byte) in preview.iter().enumerate() {
51 if i > 0 && i % 16 == 0 {
52 println!();
53 }
54 print!("{:02x} ", byte);
55 }
56 println!();
57
58 println!("\nSerialization complete! These bytes can now be sent over the network.");
59}Sourcepub fn error(self, error: impl Into<String>) -> Self
pub fn error(self, error: impl Into<String>) -> Self
Examples found in repository?
examples/serialize.rs (line 26)
4fn main() {
5 println!("Scry Protocol - Serialization Example\n");
6
7 // Create some sample events
8 let events = vec![
9 QueryEventBuilder::new("SELECT * FROM users WHERE id = 1")
10 .connection_id("conn-001")
11 .database("production")
12 .duration(Duration::from_millis(5))
13 .rows(1)
14 .build(),
15 QueryEventBuilder::new("INSERT INTO orders (user_id, total) VALUES (1, 99.99)")
16 .connection_id("conn-001")
17 .database("production")
18 .duration(Duration::from_millis(3))
19 .rows(1)
20 .build(),
21 QueryEventBuilder::new("INVALID SQL QUERY")
22 .connection_id("conn-002")
23 .database("production")
24 .duration(Duration::from_millis(1))
25 .success(false)
26 .error("syntax error at or near \"INVALID\"")
27 .build(),
28 ];
29
30 println!("Created {} events:", events.len());
31 for (i, event) in events.iter().enumerate() {
32 println!(" {}. {} ({})", i + 1, event.query, if event.success { "success" } else { "failed" });
33 }
34
35 // Serialize the batch
36 let proxy_id = "proxy-demo";
37 let batch_seq = 0;
38 let bytes = FlatBuffersSerializer::serialize_batch(&events, proxy_id, batch_seq);
39
40 println!("\nSerialized batch:");
41 println!(" Proxy ID: {}", proxy_id);
42 println!(" Batch seq: {}", batch_seq);
43 println!(" Event count: {}", events.len());
44 println!(" Binary size: {} bytes", bytes.len());
45 println!(" Average bytes/event: {} bytes", bytes.len() / events.len());
46
47 // Show first 32 bytes in hex
48 println!("\nFirst 32 bytes (hex):");
49 let preview = &bytes[..bytes.len().min(32)];
50 for (i, byte) in preview.iter().enumerate() {
51 if i > 0 && i % 16 == 0 {
52 println!();
53 }
54 print!("{:02x} ", byte);
55 }
56 println!();
57
58 println!("\nSerialization complete! These bytes can now be sent over the network.");
59}Sourcepub fn database(self, database: impl Into<String>) -> Self
pub fn database(self, database: impl Into<String>) -> Self
Examples found in repository?
examples/serialize.rs (line 11)
4fn main() {
5 println!("Scry Protocol - Serialization Example\n");
6
7 // Create some sample events
8 let events = vec![
9 QueryEventBuilder::new("SELECT * FROM users WHERE id = 1")
10 .connection_id("conn-001")
11 .database("production")
12 .duration(Duration::from_millis(5))
13 .rows(1)
14 .build(),
15 QueryEventBuilder::new("INSERT INTO orders (user_id, total) VALUES (1, 99.99)")
16 .connection_id("conn-001")
17 .database("production")
18 .duration(Duration::from_millis(3))
19 .rows(1)
20 .build(),
21 QueryEventBuilder::new("INVALID SQL QUERY")
22 .connection_id("conn-002")
23 .database("production")
24 .duration(Duration::from_millis(1))
25 .success(false)
26 .error("syntax error at or near \"INVALID\"")
27 .build(),
28 ];
29
30 println!("Created {} events:", events.len());
31 for (i, event) in events.iter().enumerate() {
32 println!(" {}. {} ({})", i + 1, event.query, if event.success { "success" } else { "failed" });
33 }
34
35 // Serialize the batch
36 let proxy_id = "proxy-demo";
37 let batch_seq = 0;
38 let bytes = FlatBuffersSerializer::serialize_batch(&events, proxy_id, batch_seq);
39
40 println!("\nSerialized batch:");
41 println!(" Proxy ID: {}", proxy_id);
42 println!(" Batch seq: {}", batch_seq);
43 println!(" Event count: {}", events.len());
44 println!(" Binary size: {} bytes", bytes.len());
45 println!(" Average bytes/event: {} bytes", bytes.len() / events.len());
46
47 // Show first 32 bytes in hex
48 println!("\nFirst 32 bytes (hex):");
49 let preview = &bytes[..bytes.len().min(32)];
50 for (i, byte) in preview.iter().enumerate() {
51 if i > 0 && i % 16 == 0 {
52 println!();
53 }
54 print!("{:02x} ", byte);
55 }
56 println!();
57
58 println!("\nSerialization complete! These bytes can now be sent over the network.");
59}More examples
examples/deserialize.rs (line 13)
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}Sourcepub fn connection_id(self, connection_id: impl Into<String>) -> Self
pub fn connection_id(self, connection_id: impl Into<String>) -> Self
Examples found in repository?
examples/serialize.rs (line 10)
4fn main() {
5 println!("Scry Protocol - Serialization Example\n");
6
7 // Create some sample events
8 let events = vec![
9 QueryEventBuilder::new("SELECT * FROM users WHERE id = 1")
10 .connection_id("conn-001")
11 .database("production")
12 .duration(Duration::from_millis(5))
13 .rows(1)
14 .build(),
15 QueryEventBuilder::new("INSERT INTO orders (user_id, total) VALUES (1, 99.99)")
16 .connection_id("conn-001")
17 .database("production")
18 .duration(Duration::from_millis(3))
19 .rows(1)
20 .build(),
21 QueryEventBuilder::new("INVALID SQL QUERY")
22 .connection_id("conn-002")
23 .database("production")
24 .duration(Duration::from_millis(1))
25 .success(false)
26 .error("syntax error at or near \"INVALID\"")
27 .build(),
28 ];
29
30 println!("Created {} events:", events.len());
31 for (i, event) in events.iter().enumerate() {
32 println!(" {}. {} ({})", i + 1, event.query, if event.success { "success" } else { "failed" });
33 }
34
35 // Serialize the batch
36 let proxy_id = "proxy-demo";
37 let batch_seq = 0;
38 let bytes = FlatBuffersSerializer::serialize_batch(&events, proxy_id, batch_seq);
39
40 println!("\nSerialized batch:");
41 println!(" Proxy ID: {}", proxy_id);
42 println!(" Batch seq: {}", batch_seq);
43 println!(" Event count: {}", events.len());
44 println!(" Binary size: {} bytes", bytes.len());
45 println!(" Average bytes/event: {} bytes", bytes.len() / events.len());
46
47 // Show first 32 bytes in hex
48 println!("\nFirst 32 bytes (hex):");
49 let preview = &bytes[..bytes.len().min(32)];
50 for (i, byte) in preview.iter().enumerate() {
51 if i > 0 && i % 16 == 0 {
52 println!();
53 }
54 print!("{:02x} ", byte);
55 }
56 println!();
57
58 println!("\nSerialization complete! These bytes can now be sent over the network.");
59}More examples
examples/deserialize.rs (line 12)
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}Sourcepub fn build(self) -> QueryEvent
pub fn build(self) -> QueryEvent
Examples found in repository?
examples/serialize.rs (line 14)
4fn main() {
5 println!("Scry Protocol - Serialization Example\n");
6
7 // Create some sample events
8 let events = vec![
9 QueryEventBuilder::new("SELECT * FROM users WHERE id = 1")
10 .connection_id("conn-001")
11 .database("production")
12 .duration(Duration::from_millis(5))
13 .rows(1)
14 .build(),
15 QueryEventBuilder::new("INSERT INTO orders (user_id, total) VALUES (1, 99.99)")
16 .connection_id("conn-001")
17 .database("production")
18 .duration(Duration::from_millis(3))
19 .rows(1)
20 .build(),
21 QueryEventBuilder::new("INVALID SQL QUERY")
22 .connection_id("conn-002")
23 .database("production")
24 .duration(Duration::from_millis(1))
25 .success(false)
26 .error("syntax error at or near \"INVALID\"")
27 .build(),
28 ];
29
30 println!("Created {} events:", events.len());
31 for (i, event) in events.iter().enumerate() {
32 println!(" {}. {} ({})", i + 1, event.query, if event.success { "success" } else { "failed" });
33 }
34
35 // Serialize the batch
36 let proxy_id = "proxy-demo";
37 let batch_seq = 0;
38 let bytes = FlatBuffersSerializer::serialize_batch(&events, proxy_id, batch_seq);
39
40 println!("\nSerialized batch:");
41 println!(" Proxy ID: {}", proxy_id);
42 println!(" Batch seq: {}", batch_seq);
43 println!(" Event count: {}", events.len());
44 println!(" Binary size: {} bytes", bytes.len());
45 println!(" Average bytes/event: {} bytes", bytes.len() / events.len());
46
47 // Show first 32 bytes in hex
48 println!("\nFirst 32 bytes (hex):");
49 let preview = &bytes[..bytes.len().min(32)];
50 for (i, byte) in preview.iter().enumerate() {
51 if i > 0 && i % 16 == 0 {
52 println!();
53 }
54 print!("{:02x} ", byte);
55 }
56 println!();
57
58 println!("\nSerialization complete! These bytes can now be sent over the network.");
59}More examples
examples/deserialize.rs (line 16)
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 QueryEventBuilder
impl RefUnwindSafe for QueryEventBuilder
impl Send for QueryEventBuilder
impl Sync for QueryEventBuilder
impl Unpin for QueryEventBuilder
impl UnwindSafe for QueryEventBuilder
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