Protocol Buffers
Serialization
Converting complex objects to sequences of bits, so that it can be:
- Stored
- Transmitted
- Reconstructed later
Campaign XML / JSON
<?xml version="1.0" encoding="UTF-8"?>
<campaign_message>
<_id>5f4e1e6231e3d62bc255e1a3</_id>
<body>عايز تكسب خصم 50.00% على إجمالي مسحوبات الشهر؟
الموضوع بسيط! كل اللي عليك تعمله إن إجمالي طلبيات الشهر تكون 500.00ج أو أكتر.</body>
<campaign>
<element>
<_id>5f4e1e6231e3d62bc255e1a2</_id>
<created_at>2020-09-01 12:11:46</created_at>
<creation_month>202009</creation_month>
<type>TARGET_ANNOUNCEMENT</type>
<updated_at>2020-09-01 12:11:46</updated_at>
</element>
</campaign>
<campaign_id>5f4e1e6231e3d62bc255e1a2</campaign_id>
<created_at>2020-09-01 12:11:46</created_at>
<retailer_id>1600</retailer_id>
<retailer_mobile>01111111111</retailer_mobile>
<target_id>31</target_id>
</campaign_message>
{
"_id": "5f4e1e6231e3d62bc255e1a3",
"target_id": 31,
"retailer_id": 1600,
"retailer_mobile": "01111111111",
"body": "عايز تكسب خصم 50.00% على إجمالي مسحوبات الشهر؟\nالموضوع بسيط! كل اللي عليك تعمله إن إجمالي طلبيات الشهر تكون 500.00ج أو أكتر.",
"campaign_id": "5f4e1e6231e3d62bc255e1a2",
"created_at": "2020-09-01 12:11:46",
"campaign": [
{
"_id": "5f4e1e6231e3d62bc255e1a2",
"type": "TARGET_ANNOUNCEMENT",
"creation_month": 202009,
"updated_at": "2020-09-01 12:11:46",
"created_at": "2020-09-01 12:11:46"
}
]
}
-
Arrays
-
Syntax - Hands on
syntax = "proto3";
message MyMessageName {
dataType fieldName = fieldNumber;
}
Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data, You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
Agenda
- What and Why gRPC? - The full picture
- Data Serialization Formats
- XML vs JSON
- What and Why Protocol Buffers?
- proto3 types, syntax
- protobuf Hands-on
- .json vs .bin size
Protocol Buffers
By Muhammad Magdi
Protocol Buffers
- 330