Skip to content

Wff Binary Message

Web Firm Framework edited this page Oct 8, 2016 · 15 revisions

Wff binary message is a message format which can hold binary data. Unlike in bson/json, wff binary message is a collection of name-values pairs where both name and values can be binary data and it can also have duplicate names. It's implemented in com.webfirmframework.wffweb.util.WffBinaryMessageUtil. The length of wff binary message is less than that of a JSON/BSON bytes, it's indeed valuable when a large amount of data needs to be processed / sent over network. And encoding and decoding of wff binary message is many times faster than JSON/BSON bytes. It is proved in com.webfirmframework.wffweb.util.WffBinaryMessageUtilTest test case. We have a made a major improvement in the algorithm and its implementation, it is available since wffweb-1.1.5.

Since wffweb-2.x.x, wff binary message is used as an application protocol in server client bi-directional communication. It may be used to transfer data across networks and clients where fast delivery and processing is required.

Wff Binary Message Advantages

  1. Unlike JSON, Wff Binary Message can hold raw binary data in name and values.
  2. Wff Binary Message size is lower than JSON bytes. Eg:- The minimal length of json string {"name1":["value1","value2","value3","value4","value5","value6","value7","value8","value9","valu10"]} is 101 but for the same data, wff message size is 79 bytes.
  3. Wff Binary Message size is lower than BSON bytes. Eg:- The minimal length of BSON bytes for {"name1":["value1","value2","value3","value4","value5","value6","value7","value8","value9","valu10"]} is 157 but for the same data, wff message size is 79 bytes.
  4. decoding and encoding is faster than JSON and BSON.

The message size is valuable when there are large number of messages or a large message to transfer across networks. This is one of the reasons why wffweb-2.x.x gives high performance for UI updates.

Wff Binary Message Known Disadvantages

  1. The message data is not human readable as it's raw bytes so it will be less convenient for debug purpose.
  2. Each byte in wff binary message is tightly formed so any change in the wff binary message bytes could cause unexpected result while decoding.

The wff binary message is composed as follows :-

The first byte represents the maximum number of bytes for name length bytes. The second byte represents the maximum number of bytes for the value length bytes. The remaining bytes represent the name-values pairs.

Name value pair :-

name length bytes name bytes values length bytes values bytes

Here, the name length bytes is the length of name bytes and values length bytes is the length of values bytes.

The values bytes is an array of value bytes.

Values composition :-

total values length bytes value length bytes value bytes value length bytes value bytes

Here, total values length bytes = sum of (value length bytes + value bytes + value length bytes + value bytes) no. of bytes. (we have removed extra identifier byte A from wff binary message version 1. Its implementation will be available since wffweb-1.1.5)

WffBinaryMessageUtil sample usage :-

Code samples of com.webfirmframework.wffweb.util.WffBinaryMessageUtil is given in this link.

We will soon implement wff binary message algorithm in other languages like javascript (it's implemented and available in 2.x.x version), objective-c etc... Or, if you want us to immediately implement this algorithm in any other languages, please create a ticket for it.