FOA - Fast Object and Array encoding/decoding
The FOA specification defines an efficient standard for encoding/decoding data (array, objects and files) for transfering between systems. It's stream oriented and provides mechanisms for inline binary data within the character stream.FOA (C#) FOA (Java) FOA (C) FOA (C++) FOA (PECL)
The specification defines the "protocol" while the encoding page gives simple hists on what the encoding looks like.Specification Encoding
This section briefly describes the FOA encoding. Each encoded line contains either data (could be an array entry or an object member) or an special char. Each special char or data item must be followed by a newline (\n) character.
The special chars are:
'(': begin object
'[': begin array
']': end array
')': end object
Each data, array or object (type) can also be named by
'name = type'.
Arrays and objects can be unlimited nested in each other.
item := (name '=' data | data) + '\n' data := text | spec name := text - '=' text := any char spec := ()
Viewed from another angle: all encoded rows follows the pattern
'[name = ] data\n' (*), where the name is optional (the data is
anonymous) and data is either one of '()' or another expression like (*).
This is an example of how an array (named arr) containing two structures (persons with named members) will be encoded:
arr = [ ( name = Albert Einstein born = March 14, 1879 ) ( name = Isaac Newton born = December 25, 1642 ) ]
See the encoding page for more examples.
If escaping is turned on (the default), then all special chars will be escaped when encoding and unescaped when decoding (they are replaced by HTTP encoded equivalents). This is all transparent to the library user.
The escaping can be turned off thru foa_set_mode() to improve performance.