Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

binary vs text protocols

Tags:

I am wondering what the differences are between binary and text based protocols. I read that binary protocols are more compacts/faster to process. How does that work out? Since you have to send the same amount of data? No?

E.g how would the string "hello" differ in size in binary format?

like image 274
bob Avatar asked Mar 02 '10 16:03

bob


People also ask

What are binary protocols?

A binary protocol utilizes all values of a byte, as opposed to a text-based protocol which only uses values corresponding to human-readable characters in ASCII encoding. Binary protocols are intended to be read by a machine rather than a human being.

Is binary more efficient than text?

Text protocols are better in terms of readability, ease of reimplementing, and ease of debugging. Binary protocols are more compact. However, you can compress your text using a library like LZO or Zlib, and this is almost as compact as binary (with very little performance hit for compression/decompression.)

Is text a binary or HTTP?

The HTTP protocol itself is readable as text. This is useful because you can telnet into any server at all and communicate with it. Being text also allows you to easily watch HTTP communication with a program like wireshark.

Which is a text protocol?

Text protocol commands are sent from client to server. The text protocol has a less comprehensive format than the binary protocol, which is used by prepared statements only.


2 Answers

If all you are doing is transmitting text, then yes, the difference between the two isn't very significant. But consider trying to transmit things like:

  • Numbers - do you use a string representation of a number, or the binary? Especially for large numbers, the binary will be more compact.
  • Data Structures - How do you denote the beginning and ending of a field in a text protocol? Sometimes a binary protocol with fixed length fields is more compact.
like image 133
Nick Avatar answered Oct 03 '22 13:10

Nick


Text protocols are better in terms of readability, ease of reimplementing, and ease of debugging. Binary protocols are more compact.

However, you can compress your text using a library like LZO or Zlib, and this is almost as compact as binary (with very little performance hit for compression/decompression.)

You can read more info on the subject here:
http://www.faqs.org/docs/artu/ch05s01.html

like image 30
Max E. Avatar answered Oct 03 '22 15:10

Max E.