commit 1a7250f03ae3770845e0abd469d7766df2fa919b
parent a3f070715bb576ea4d21e9b27edc41953d3c79f3
Author: MTRNord <mtrnord1@gmail.com>
Date: Sat, 16 Apr 2022 20:42:01 +0200
Reduce wire size
Diffstat:
4 files changed, 24 insertions(+), 42 deletions(-)
diff --git a/build.rs b/build.rs
@@ -2,7 +2,6 @@ fn main() {
capnpc::CompilerCommand::new()
.src_prefix("schema")
.import_path("schema")
- .file("schema/utils.capnp")
.file("schema/matrix.capnp")
.run()
.expect("schema compiler command");
diff --git a/schema/matrix.capnp b/schema/matrix.capnp
@@ -1,23 +1,24 @@
@0xeab570afa44bcb9d;
-using Util = import "/utils.capnp";
-
struct MessageEvent {
content: union {
text: group {
body @0: Text;
- format @1: Util.Option(Text);
- formattedBody @2: Util.Option(Text);
+ # Format is optional
+ format @1: Text;
+ formattedBody @2: Text;
}
emote: group {
body @3: Text;
- format @4: Util.Option(Text);
- formattedBody @5: Util.Option(Text);
+ # Format is optional
+ format @4: Text;
+ formattedBody @5: Text;
}
notice: group {
body @6: Text;
- format @7: Util.Option(Text);
- formattedBody @8: Util.Option(Text);
+ # Format is optional
+ format @7: Text;
+ formattedBody @8: Text;
}
audio: group {
body @9: Text;
@@ -33,13 +34,15 @@ struct MessageEvent {
image: group {
body @16: Text;
info @17: ImageInfo;
- file @18: Util.Option(Text);
- url @19: Text;
+ url @18: Text;
+ # File only exists if e2ee encrypted
+ file @19: Text;
}
location: group {
body @20: Text;
geoUri @21: Text;
- info @22: Util.Option(LocationInfo);
+ # Info can be null
+ info @22: LocationInfo;
}
video: group {
body @23: Text;
@@ -54,11 +57,10 @@ struct MessageEvent {
}
}
roomId @30: Text;
- stateKey @31: Util.Option(Text);
- sender @32: Text;
- eventId @33: Text;
- originServerTs @34: UInt64;
- unsigned @35: Unsigned;
+ sender @31: Text;
+ eventId @32: Text;
+ originServerTs @33: UInt64;
+ unsigned @34: Unsigned;
enum ServerNoticeType {
usageLimitExceeded @0;
@@ -89,7 +91,8 @@ struct MessageEvent {
struct LocationInfo {
thumbnailInfo @0: ImageInfo;
thumbnailUrl @1: Text;
- thumbnailFile @2: Util.Option(Text);
+ # Only exists on E2EE encrypted messages
+ thumbnailFile @2: Text;
}
struct VideoInfo {
@@ -106,6 +109,6 @@ struct MessageEvent {
struct Unsigned(Content) {
age @0: UInt64;
transactionId @1: Text;
- prevContent @2: Util.Option(Content);
- redactedBecause @3: Util.Option(Text);
+ prevContent @2: Content;
+ redactedBecause @3: Text;
}
\ No newline at end of file
diff --git a/schema/utils.capnp b/schema/utils.capnp
@@ -1,9 +0,0 @@
-@0x9acbae5536535c84;
-
-# Equivalent to Rust's Option enum
-struct Option(SomeType) {
- union {
- none @0: Void;
- some @1: SomeType;
- }
-}
-\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
@@ -1,5 +1,4 @@
use crate::matrix_capnp::message_event;
-use crate::utils_capnp::option;
use capnp::serialize_packed;
use clap::Parser;
use color_eyre::eyre::{eyre, Result};
@@ -8,9 +7,6 @@ use std::{fs::File, io::BufReader};
pub mod matrix_capnp {
include!(concat!(env!("OUT_DIR"), "/matrix_capnp.rs"));
}
-pub mod utils_capnp {
- include!(concat!(env!("OUT_DIR"), "/utils_capnp.rs"));
-}
pub mod matrix {
use crate::matrix_capnp::message_event;
@@ -32,8 +28,6 @@ pub mod matrix {
let mut content = event.reborrow().init_content();
let mut text = content.reborrow().init_text();
text.set_body("This is a test");
- let mut formatted_body = text.init_formatted_body();
- formatted_body.set_none(());
}
}
@@ -73,12 +67,8 @@ fn main() -> Result<()> {
match event.get_content().which() {
Ok(message_event::content::Text(content)) => {
println!("text body: {}", content.get_body()?);
- match content.get_formatted_body()?.which() {
- Ok(option::Some(content)) => {
- println!("text formatted_body: {}", content?)
- }
- Ok(option::None(())) => println!("emote formatted_body: None"),
- Err(err) => println!("emote formatted_body: {:?}", err),
+ if content.has_formatted_body() {
+ println!("text formatted_body: {}", content.get_formatted_body()?)
}
}
Err(err) => println!("content: {:?}", err),