Why protobuf is said to be in binary format although we write it in text format similar to json

softwareengineering.stackexchange https://softwareengineering.stackexchange.com/questions/389699

  •  23-02-2021
  •  | 
  •  

Question

JSON

{
"hello": "world"
}

Protobuf

message HelloWorld {
required string name = 1;
}

Why do we say that protobuf uses binary format during network exchange and json don't, even though network always will transfer using binary data format?

Was it helpful?

Solution

This would be more clear if you were comparing two more similar pieces of data with non-text data components.

For example, the following JSON is ALL text:

{
    "NumberOfClients": 20
}

The 20 is two separate characters in JSON, but would be represented as an actual binary integer in Protobuf, which in this case would be a single byte: ‭00010100‬

Further, I am not sure you are properly understanding Protobuf as you are comparing apples and oranges in your question. You are comparing JSON Data to a Protobuf Schema

Licensed under: CC-BY-SA with attribution
scroll top