The document discusses the advantages of using binary formats like FlatBuffers and FlexBuffers over JSON for serialization. It notes that binary formats have smaller payload sizes and faster encoding/decoding speeds which can significantly improve performance for machine to machine communication and state persistence. The document demonstrates how FlatBuffers and FlexBuffers can be used to efficiently store and access structured data like user profiles and city data. It concludes that developers should evaluate their use cases and consider binary formats instead of only using JSON because others do.
37. package demo
type Person struct {
name text
birthday Date
}
type Date struct {
year uint16
month uint8
day uint8
}
table Person {
name : string;
birthday : Date;
}
struct Date {
year : short;
month : byte;
day : byte;
}
root_type Person;
61. Benefits of FlexBuffers
• No schema, no code generation needed
• Random value access
• Can easily transform JSON to FlexBuffers
• Supports every type JSON does and a bit more
• Keeps type information in the binary
62. let data = FlexBuffer.dataFrom(jsonData:
"{name:"Maxim", birthday:{"year": 1981, month: 6, day: 12}}"
.data(using: .utf8)!
)
let accessor = FlexBuffer.decode(data:data)
let name = accessor?["name"]?.asString
let day = accessor?["birthday"]?["day"]?.asInt
63. Outlook
• Don’t use JSON just because other people do, think
about your use case
• Imagine how much more responses your server could
deliver if it took 200x less time to process a request
• Start thinking in Graphs not Trees
• please ask questions after the session
• … and btw. I like to collaborate 😉 @iceX33
64. References
• All Gifs are powered by giphy.com
• JSON number grammar diagrams taken from json.org
• Binary Visualiser „HEX Fiend“ by ridiculous_fish http://ridiculousfish.com/hexfiend/
• https://github.com/eishay/jvm-serializers/wiki
• https://github.com/pascaldekloe/colfer
• https://github.com/google/flatbuffers
• https://github.com/mzaks/FlatBuffersSwift
• https://github.com/mzaks/FlexBuffersSwift
• https://github.com/mzaks/FindCityFB
• http://resiapp.io