SlideShare a Scribd company logo
DISTRIBUTED SYSTEMS
RPC: Part 2
Data Encoding in Remote Procedure Calls
1
2
Sending data over the network
Stream of bytes
3
struct item {
char name[64];
unsigned long id;
int number_in_stock;
float rating;
double price;
} scratcher = {
"Bear Claw Black Telescopic Back Scratcher",
00120,
332,
4.6,
5.99
}
gets stored in memory as:
42 65 61 72 20 43 6c 61 77 20 42 6c 61 63 6b 20 54 ...
Representing data
4
No such thing as
incompatibility problems on local system
Remote machine may have:
– Different byte ordering
– Different sizes of integers and other types
– Different floating-point representations
– Different character sets
– Alignment requirements
Integer sizes:
• 8, 16, 32, 64, and 128 bits
Floating point formats:
• IEEE 754 (FP16, P32, FP64, quadruple:
127-bit; octuple: 256 bit)
• Google BFloat16 (Google Brain, supported
by NVIDIA)
• NVIDIA TensorFloat (TF32)
String formats:
• ASCII, UTF-8, UTF-16, UTF-32
• Terminated by a 0 byte (C/C++)
• Various object headers (Go, Java, Python)
Representing data
IP (headers) forced all to use big endian byte ordering for 16- and 32-bit values
Big endian: Most significant byte in low memory
– Jave Virtual Machine, OpenRISC, Atmel AVR32, IBM z-series, SPARC < V9, Motorola 680x0, older PowerPC
Little endian: Most significant byte in high memory
– Intel/AMD IA-32, x64
Bi-endian: Processor may operate in either mode
– ARM, PowerPC, MIPS, SPARC V9, IA-64 (Intel Itanium)
main() {
unsigned int n;
char *a = (char *)&n;
n = 0x11223344;
printf("%02x, %02x, %02x, %02xn",
a[0], a[1], a[2], a[3]);
}
Output on an Intel CPU:
44, 33, 22, 11
Output on a PowerPC:
11, 22, 33, 44
IP headers use big endian
5
Representing data: serialization
6
We need a standard encoding to enable communication between
heterogeneous systems
• Serialization
– Convert data into a pointerless format: an array of bytes
• Examples
– XDR (eXternal Data Representation), used by ONC RPC
– JSON (JavaScript Object Notation)
– W3C XML Schema Language
– ASN.1 (ISO Abstract Syntax Notation)
– Google Protocol Buffers
Serializing data
Implicit typing
– only values are transmitted, not data types or parameter info
– e.g., ONC XDR (RFC 4506)
Explicit typing
– Type is transmitted with each value
– e.g., ISO’s ASN.1, XML, protocol buffers, JSON
Marshaling vs. serialization – almost synonymous – serialization is used in marshaling:
Serialization: converting an object into a sequence of bytes that can be sent over a network
7
Marshaling: bundling parameters into a form that can be reconstructed (unmarshaled) by
another process. May include object ID or other state. Marshaling uses
serialization.
XML: eXtensible Markup Language
<ShoppingCart>
<Items>
<Item>
<ItemID> 00120 </ItemID>
<Item> Bear Claw Black Telescopic Back Scratcher </Item>
<Price> 5.99 </Price>
</Item>
<item>
<ItemID> 00121 </ItemID>
<Item> Scalp Massager </Item>
<Price> 5.95 </Price>
</Item>
</Items>
</ShoppingCart>
Benefits:
– Human-readable
– Human-editable
– Interleaves structure with text
(data)
8
Problems:
– Verbose: transmit more data
than needed
– Longer parsing time
– Data conversion always required
for numbers
JSON: JavaScript Object Notation
9
• Lightweight (relatively efficient) data interchange format
– Introduced as the “fat-free alternative to XML”
– Based on JavaScript
• Human writeable and readable
• Self-describing (explicitly typed)
• Language independent
• Easy to parse
• Currently converters for 50+ languages
• Includes support for RPC invocation via JSON-RPC
JSON Data Encoding Example
{
"items": [
{
"item_id": 00120,
"item:": " Bear Claw Black Telescopic Back Scratcher",
"cost": "5.99"
}
{
"item_id": 00121,
"item:": " Scalp Massager r",
"cost": "5.95"
}
]
}
1
0
Google Protocol Buffers
11
• Efficient mechanism for serializing structured data
– Much simpler, smaller, and faster than XML or JSON
• Language independent
• Define messages
– Each message is a set of names and types
• Compile the messages to generate data access classes for your language
• Used extensively within Google
– Currently over 48,000 different message types defined
– Used both for RPC and for persistent storage
1
1
Example (from the Developer Guide)
12
http://code.google.com/apis/protocolbuffers/docs/overview.html
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 phone = 4;
}
1
2
Example (from the Developer Guide)
http://code.google.com/apis/protocolbuffers/docs/overview.html
13
Person person;
person.set_name("John Doe");
person.set_id(1234);
person.set_email("jdoe@example.com");
fstream output("myfile", ios::out | ios::binary);
person.SerializeToOstream(&output);
1
3
Efficiency example (from the Developer Guide)
http://code.google.com/apis/protocolbuffers/docs/overview.html
14
• Binary encoded message: ~28 bytes long, 100-200 ns to parse
• XML version: ≥ 69 bytes, 5,000-10,000 ns to parse
• In general,
– 3-10x smaller data
– 20-100 times faster to marshal/unmarshal
– Easier to use programmatically
<person>
<name>John Doe</name>
<email>jdoe@example.com</email>
</person>
person {
name: "John Doe"
email: "jdoe@example.com"
}
XML version T
ext (uncompiled) protocol buffer
1
4
15
The End
1
5

More Related Content

Similar to Data Encoding in Remote Procedure calls.

05 rpc-case studies
05 rpc-case studies05 rpc-case studies
05 rpc-case studies
hushu
 
Networks
NetworksNetworks
Networks
Edward Blurock
 
DLD5.pdf
DLD5.pdfDLD5.pdf
DLD5.pdf
Shashi738182
 
Apache big data 2016 - Speaking the language of Big Data
Apache big data 2016 - Speaking the language of Big DataApache big data 2016 - Speaking the language of Big Data
Apache big data 2016 - Speaking the language of Big Data
techmaddy
 
Fletcher Framework for Programming FPGA
Fletcher Framework for Programming FPGAFletcher Framework for Programming FPGA
Fletcher Framework for Programming FPGA
Ganesan Narayanasamy
 
DEVNET-1152 OpenDaylight YANG Model Overview and Tools
DEVNET-1152	OpenDaylight YANG Model Overview and ToolsDEVNET-1152	OpenDaylight YANG Model Overview and Tools
DEVNET-1152 OpenDaylight YANG Model Overview and Tools
Cisco DevNet
 
What you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyondWhat you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyond
Jon Galloway
 
Keccak
KeccakKeccak
Keccak
Rajeev Verma
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonThrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Igor Anishchenko
 
Part 6 : Internet applications
Part 6 : Internet applicationsPart 6 : Internet applications
Part 6 : Internet applications
Olivier Bonaventure
 
Xdr ppt
Xdr pptXdr ppt
Xdr ppt
Nidhi Thakkar
 
Distributed Interactive Computing Environment (DICE)
Distributed Interactive Computing Environment (DICE)Distributed Interactive Computing Environment (DICE)
Distributed Interactive Computing Environment (DICE)
The HDF-EOS Tools and Information Center
 
Consuming RESTful Web services in PHP
Consuming RESTful Web services in PHPConsuming RESTful Web services in PHP
Consuming RESTful Web services in PHP
Zoran Jeremic
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
Zoran Jeremic
 
Polyraptor
PolyraptorPolyraptor
Polyraptor
MohammedAlasmar2
 
Networking- OSI Layer Protocol Functions
Networking- OSI Layer Protocol FunctionsNetworking- OSI Layer Protocol Functions
Networking- OSI Layer Protocol Functions
Gayathri Kesavan
 
PF_DIRECT@TMA12
PF_DIRECT@TMA12PF_DIRECT@TMA12
PF_DIRECT@TMA12
Nicola Bonelli
 
Chapter 5 introduction to VHDL
Chapter 5 introduction to VHDLChapter 5 introduction to VHDL
Chapter 5 introduction to VHDL
SSE_AndyLi
 
Avani
AvaniAvani
Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016
Jian-Hong Pan
 

Similar to Data Encoding in Remote Procedure calls. (20)

05 rpc-case studies
05 rpc-case studies05 rpc-case studies
05 rpc-case studies
 
Networks
NetworksNetworks
Networks
 
DLD5.pdf
DLD5.pdfDLD5.pdf
DLD5.pdf
 
Apache big data 2016 - Speaking the language of Big Data
Apache big data 2016 - Speaking the language of Big DataApache big data 2016 - Speaking the language of Big Data
Apache big data 2016 - Speaking the language of Big Data
 
Fletcher Framework for Programming FPGA
Fletcher Framework for Programming FPGAFletcher Framework for Programming FPGA
Fletcher Framework for Programming FPGA
 
DEVNET-1152 OpenDaylight YANG Model Overview and Tools
DEVNET-1152	OpenDaylight YANG Model Overview and ToolsDEVNET-1152	OpenDaylight YANG Model Overview and Tools
DEVNET-1152 OpenDaylight YANG Model Overview and Tools
 
What you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyondWhat you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyond
 
Keccak
KeccakKeccak
Keccak
 
Thrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased ComparisonThrift vs Protocol Buffers vs Avro - Biased Comparison
Thrift vs Protocol Buffers vs Avro - Biased Comparison
 
Part 6 : Internet applications
Part 6 : Internet applicationsPart 6 : Internet applications
Part 6 : Internet applications
 
Xdr ppt
Xdr pptXdr ppt
Xdr ppt
 
Distributed Interactive Computing Environment (DICE)
Distributed Interactive Computing Environment (DICE)Distributed Interactive Computing Environment (DICE)
Distributed Interactive Computing Environment (DICE)
 
Consuming RESTful Web services in PHP
Consuming RESTful Web services in PHPConsuming RESTful Web services in PHP
Consuming RESTful Web services in PHP
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
Polyraptor
PolyraptorPolyraptor
Polyraptor
 
Networking- OSI Layer Protocol Functions
Networking- OSI Layer Protocol FunctionsNetworking- OSI Layer Protocol Functions
Networking- OSI Layer Protocol Functions
 
PF_DIRECT@TMA12
PF_DIRECT@TMA12PF_DIRECT@TMA12
PF_DIRECT@TMA12
 
Chapter 5 introduction to VHDL
Chapter 5 introduction to VHDLChapter 5 introduction to VHDL
Chapter 5 introduction to VHDL
 
Avani
AvaniAvani
Avani
 
Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016Micro HTTP Server Implemented in C @ COSCUP 2016
Micro HTTP Server Implemented in C @ COSCUP 2016
 

Recently uploaded

South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 

Recently uploaded (20)

South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 

Data Encoding in Remote Procedure calls.

  • 1. DISTRIBUTED SYSTEMS RPC: Part 2 Data Encoding in Remote Procedure Calls 1
  • 2. 2 Sending data over the network
  • 3. Stream of bytes 3 struct item { char name[64]; unsigned long id; int number_in_stock; float rating; double price; } scratcher = { "Bear Claw Black Telescopic Back Scratcher", 00120, 332, 4.6, 5.99 } gets stored in memory as: 42 65 61 72 20 43 6c 61 77 20 42 6c 61 63 6b 20 54 ...
  • 4. Representing data 4 No such thing as incompatibility problems on local system Remote machine may have: – Different byte ordering – Different sizes of integers and other types – Different floating-point representations – Different character sets – Alignment requirements Integer sizes: • 8, 16, 32, 64, and 128 bits Floating point formats: • IEEE 754 (FP16, P32, FP64, quadruple: 127-bit; octuple: 256 bit) • Google BFloat16 (Google Brain, supported by NVIDIA) • NVIDIA TensorFloat (TF32) String formats: • ASCII, UTF-8, UTF-16, UTF-32 • Terminated by a 0 byte (C/C++) • Various object headers (Go, Java, Python)
  • 5. Representing data IP (headers) forced all to use big endian byte ordering for 16- and 32-bit values Big endian: Most significant byte in low memory – Jave Virtual Machine, OpenRISC, Atmel AVR32, IBM z-series, SPARC < V9, Motorola 680x0, older PowerPC Little endian: Most significant byte in high memory – Intel/AMD IA-32, x64 Bi-endian: Processor may operate in either mode – ARM, PowerPC, MIPS, SPARC V9, IA-64 (Intel Itanium) main() { unsigned int n; char *a = (char *)&n; n = 0x11223344; printf("%02x, %02x, %02x, %02xn", a[0], a[1], a[2], a[3]); } Output on an Intel CPU: 44, 33, 22, 11 Output on a PowerPC: 11, 22, 33, 44 IP headers use big endian 5
  • 6. Representing data: serialization 6 We need a standard encoding to enable communication between heterogeneous systems • Serialization – Convert data into a pointerless format: an array of bytes • Examples – XDR (eXternal Data Representation), used by ONC RPC – JSON (JavaScript Object Notation) – W3C XML Schema Language – ASN.1 (ISO Abstract Syntax Notation) – Google Protocol Buffers
  • 7. Serializing data Implicit typing – only values are transmitted, not data types or parameter info – e.g., ONC XDR (RFC 4506) Explicit typing – Type is transmitted with each value – e.g., ISO’s ASN.1, XML, protocol buffers, JSON Marshaling vs. serialization – almost synonymous – serialization is used in marshaling: Serialization: converting an object into a sequence of bytes that can be sent over a network 7 Marshaling: bundling parameters into a form that can be reconstructed (unmarshaled) by another process. May include object ID or other state. Marshaling uses serialization.
  • 8. XML: eXtensible Markup Language <ShoppingCart> <Items> <Item> <ItemID> 00120 </ItemID> <Item> Bear Claw Black Telescopic Back Scratcher </Item> <Price> 5.99 </Price> </Item> <item> <ItemID> 00121 </ItemID> <Item> Scalp Massager </Item> <Price> 5.95 </Price> </Item> </Items> </ShoppingCart> Benefits: – Human-readable – Human-editable – Interleaves structure with text (data) 8 Problems: – Verbose: transmit more data than needed – Longer parsing time – Data conversion always required for numbers
  • 9. JSON: JavaScript Object Notation 9 • Lightweight (relatively efficient) data interchange format – Introduced as the “fat-free alternative to XML” – Based on JavaScript • Human writeable and readable • Self-describing (explicitly typed) • Language independent • Easy to parse • Currently converters for 50+ languages • Includes support for RPC invocation via JSON-RPC
  • 10. JSON Data Encoding Example { "items": [ { "item_id": 00120, "item:": " Bear Claw Black Telescopic Back Scratcher", "cost": "5.99" } { "item_id": 00121, "item:": " Scalp Massager r", "cost": "5.95" } ] } 1 0
  • 11. Google Protocol Buffers 11 • Efficient mechanism for serializing structured data – Much simpler, smaller, and faster than XML or JSON • Language independent • Define messages – Each message is a set of names and types • Compile the messages to generate data access classes for your language • Used extensively within Google – Currently over 48,000 different message types defined – Used both for RPC and for persistent storage 1 1
  • 12. Example (from the Developer Guide) 12 http://code.google.com/apis/protocolbuffers/docs/overview.html 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 phone = 4; } 1 2
  • 13. Example (from the Developer Guide) http://code.google.com/apis/protocolbuffers/docs/overview.html 13 Person person; person.set_name("John Doe"); person.set_id(1234); person.set_email("jdoe@example.com"); fstream output("myfile", ios::out | ios::binary); person.SerializeToOstream(&output); 1 3
  • 14. Efficiency example (from the Developer Guide) http://code.google.com/apis/protocolbuffers/docs/overview.html 14 • Binary encoded message: ~28 bytes long, 100-200 ns to parse • XML version: ≥ 69 bytes, 5,000-10,000 ns to parse • In general, – 3-10x smaller data – 20-100 times faster to marshal/unmarshal – Easier to use programmatically <person> <name>John Doe</name> <email>jdoe@example.com</email> </person> person { name: "John Doe" email: "jdoe@example.com" } XML version T ext (uncompiled) protocol buffer 1 4