-
Notifications
You must be signed in to change notification settings - Fork 18
Extensibility
Fressian writers can define new struct types on the fly. A Struct definition consists of the STRUCT_TYPE
byte code, followed by the struct tag (a string uniquely naming the struct), followed by the number of fields in the struct (an integer), followed by the fields.
When it sees a struct for the first time, the serialization library assigns it a byte code representation. The first sixteen structs encountered get single byte codes starting at STRUCT_CACHE_PACKED_START
. Subsequent structs are encoded as the bytecode STRUCT
, plus the ordinal number of the struct's first appearance.
Once a struct has been assigned a byte code representation, that representation is used in subsequent writes instead of the type+tag+fieldcount.
Because the structs encode a fieldcount, naive readers can read structs they have never seen before. If a reader does not have any specific handler for a struct, it can represent the struct via the following logical interface (shown in Java):
public interface Tagged {
public Object getTag();
public Object getValue();
public Map getMeta();
}