binary serialization format
Colfer is a binary serialization format optimized for speed and size.
The project's compiler colf(1) generates source code from schema definitions
to marshal and unmarshall data structures.
This is free and unencumbered software released into the public domain. The format is inspired by Protocol Buffers.
Download a prebuilt compiler
or run go get -u github.com/pascaldekloe/colfer/cmd/colf to make one yourself.
Homebrew users can also brew install colfer.
The command prints its own manual when invoked without arguments.
…It is recommended to commit the generated source code into the respective version control to preserve build consistency and minimise the need for compiler installations. Alternatively, you may use the Maven plugin.
net.quies.colfer
colfer-maven-plugin
1.11.2
com/example
Data structures are defined in .colf files. The format is quite self-explanatory.
// Package demo offers a demonstration.
// These comment lines will end up in the generated code.
package demo
// Course is the grounds where the game of golf is played.
type course struct {
ID uint64
name text
holes []hole
image binary
tags []text
}
type hole struct {
// Lat is the latitude of the cup.
lat float64
// Lon is the longitude of the cup.
lon float64
// Par is the difficulty index.
par uint8
// Water marks the presence of water.
water bool
// Sand marks the presence of sand.
sand bool
}See what the generated code looks like in C, Go, Java or JavaScript.
The following table shows how Colfer data types are applied per language.
| Colfer | C | Go | Java | JavaScript |
|---|---|---|---|---|
| bool | char | bool | boolean | Boolean |
| uint8 | uint8_t | uint8 | byte † | Number |
| uint16 | uint16_t | uint16 | short † | Number |
| uint32 | uint32_t | uint32 | int † | Number |
| uint64 | uint64_t | uint64 | long † | Number ‡ |
| int32 | int32_t | int32 | int | Number |
| int64 | int64_t | int64 | long | Number ‡ |
| float32 | float | float32 | float | Number |
| float64 | double | float64 | double | Number |
| timestamp | timespec | time.Time †† | time.Instant | Date + Number |
| text | const char* + size_t | string | String | String |
| binary | uint8_t* + size_t | []byte | byte[] | Uint8Array |
| list | * + size_t | slice | array | Array |
Lists may contain floating points, text, binaries or data structures.
Colfer is suited for untrusted data sources such as network I/O or bulk streams. Marshalling and unmarshalling comes with built-in size protection to ensure predictable memory consumption. The format prevents memory bombs by design.
The marshaller may not produce malformed output, regardless of the data input. In no event may the unmarshaller read outside the boundaries of a serial. Fuzz testing did not reveal any volnurabilities yet. Computing power is welcome.
Name changes do not affect the serialization format. Deprecated fields should be renamed to clearly discourage their use. For backwards compatibility new fields must be added to the end of colfer structs. Thus the number of fields can be seen as the schema version.
Colfer aims to be the fastest and the smallest format without compromising on reliability. See the benchmark wiki for a comparison. Suboptimal performance is treated like a bug.
No open issues yet, or sync has not completed.