Skip to content

Instantly share code, notes, and snippets.

@AndrewJDR
Created March 19, 2017 19:51
Show Gist options
  • Save AndrewJDR/8ad04070ab3a67dcb5bad73cfdaccc80 to your computer and use it in GitHub Desktop.
Save AndrewJDR/8ad04070ab3a67dcb5bad73cfdaccc80 to your computer and use it in GitHub Desktop.
# To build the flatbuffer binary
flatc -c -b member.fbs m.room.member_example.json
# see member_generated.h for the code that gets generated that's capable of reading the binary message
# The .h is for C. To generate other language bindings:
flatc --js -c -b member.fbs m.room.member_example.json
flatc --go -c -b member.fbs m.room.member_example.json
flatc --python -c -b member.fbs m.room.member_example.json
flatc --csharp -c -b member.fbs m.room.member_example.json
# etc...
# To parse json back out from the flatbuffer (just for debugging, kind of defeats the purpose to use this in practice):
flatc --strict-json --raw-binary -o json_out -t member.fbs -- m.room.member_example.bin
# (see contents of json_out folder)
{
"age": 242352,
"content": {
"membership": "join",
"avatar_url": "mxc://localhost/SEsfnsuifSDFSSEF#auto",
"displayname": "Alice Margatroid"
},
"invite_room_state": [
{
"type": "m.room.name",
"state_key": "",
"content": {
"name": "Forest of Magic"
}
},
{
"type": "m.room.join_rules",
"state_key": "",
"content": {
"join_rules": "invite"
}
}
],
"state_key": "@alice:localhost",
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.member",
"room_id": "!Cuyf34gef24t:localhost",
"sender": "@example:localhost"
}
table MemberContent {
membership:string;
avatar_url:string;
displayname:string;
}
table RoomStateContent {
name:string;
join_rules:string;
}
table RoomState {
type:string;
state_key:string;
content:RoomStateContent;
}
table Member {
age:int;
content:MemberContent;
state_key:string;
origin_server_ts:ulong;
event_id:string;
type:string;
room_id:string;
sender:string;
invite_room_state:[RoomState];
}
root_type Member;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment