Protocol Buffers

Serialization

Converting complex objects to sequences of bits, so that it can be:

  1. Stored
  2. Transmitted
  3. 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"
		}
	]
}
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

Protocol Buffers

By Muhammad Magdi

Protocol Buffers

  • 330