Back to the Presentation Page: https://raulingaverage.dev/Presentations

Protos, JSON,...or?

By Raul Maldonado
PyBay 2018, Lightning Talk: @Cloud_Chaoszero

Motivation

We would like to serialize structured data to transmit information over networks to avoid intensive cpu executions and related risks. So, we use a serialization mechanism to enable faster* data transfer of platform independence, data interexchange over heterogeneous distributed systems, and more

syntax = "proto2";
package tutorial;
message Person {
required string name = 1;
required int32 id = 2;  optional string email = 3;
enum PhoneType { MOBILE = 0;
HOME = 1;  WORK = 2;  }

message PhoneNumber {

required string number = 1;
optional PhoneType type = 2 [default = HOME];
}repeated PhoneNumber phones = 4;}

Protocol Buffer

  • Created by Google, Protocol Buffers are a binary encoding format of data into efficient and extensible format.

  • Facts

    • Schema declaration for over-the-wire data transfer to/from services. Ensure signals are valid
    • Backward Compatible for older datatypes
      • New fields could be introduced, and in-between servers need not inspect data
      • Validations: required, optional, repeeated keywords
      • Ease of Language Interpretability

Encoder Message

Json

  • Javascript Object Notation (JSON) is a minimal format for structuring data.
  • Use of Keys and Values
  • Built on two structures
    • Collection of name/value pairs
    • Ordered list of values
  • Javascript object is not JSON, and JSON is not a Javascript only object

JSON

{"firstName": "John",
"lastName": "Smith", "isAlive": true,
 "age": 27,
 "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021-3100"
            },
 "phoneNumbers": [ {
     "type": "home",   "number": "212 555-1234" }, {
     "type": "office",   "number": "646 555-4567" }, {
     "type": "mobile",   "number": "123 456-7890" }
}

XML

eXtensible Markup Language (XML) Tags and Attributes

xml

Compare & Contrast

  • Protocol Buffer
    • Dense and small output, memory saver
    • Hard to decode without knowing schema (in the case of security meausres)
    • Fast Processing
  • JSON
    • Human Readible
    • Can be parsed without knowing schema in advance
    • Somewhat verbose
    • Not Doc. Markup Language
  • XML
    • Human, but verbose, Readible
    • Parsed without knowing schema in advance
    • Standard for SOAP and other implementations
    • Document Markup Language

Other Tools

  • Apache Thrift
  • eProsima Fast Buffers
  • SGML

Resources