Documentation
¶
Overview ¶
This package is a proof-of-concept demonstrating a serialization pattern as described by Glenn Fiedlers articles on UDP network traffic.
It has gone through several iterations to try new things, both to improve the performance, as well as the byte-packing.
This latest iteration discards variable support in favor of simplification.
The benchmarks have been enhanced to randomly populate a complex structure and use both tinylib/msgp and encoding/gob to compare both performance and byte size.
While I have strategies to running serialization against a variety of data I have not yet identified a sane pattern for complex variable size types, such as maps, and slices of variable length or that contain variable length data.
The benchmarks show significant packing when using this serialization tool, which can be further optimized through careful consideration when writing the serialization logic per structure. However, this process is cognitively expensive.
I cannot recommend the gob package. It has enormous variable sizes due to the amount of metadata stored, and in scenarios where you cannot rely on an existing instance it performs quite horribly by depending on a cache per instance, without which significantly more effort (likely via reflect) and more allocations are required.
The msgp solution is highly recommended for many reasons. First it performs far better with zero effort than manual serialization. Anywhere from 30% to several times faster. It also has roughly 5 times less allocations, which is much lighter on memory consumption. It supports a very similar pattern as the serialization strategy, and would be trivial to connect to a gzip package for example. The first downside is that it consumes around twice as many bytes as serialization. The second is that it produces a sizable amount of generated code. The trade-off is that generated code takes zero effort away from the core development. At worst, msgp is the absolute best way to get started with a project that needs good network communication.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Read ¶
type Read struct {
// contains filtered or unexported fields
}
A serialization writer which exposes the Serialize function.
func (*Read) Serialize ¶
This method directly funnels all input into binary.Write, which only accepts fixed size data types, and will not work on variable length data such as int, uint, string, slices of those types, and structures that contain them.
It will return immediately on the first error encountered.
While it can accept a slice and populate the existing instances, but it does not restore dynamic sized records. To work around this, expect the size to be stored and load that first.
type Write ¶
type Write struct {
// contains filtered or unexported fields
}
A serialization writer which exposes the Serialize function.
func (*Write) Serialize ¶
This method directly funnels all input into binary.Write, which only accepts fixed size data types, and will not work on variable length data such as int, uint, string, slices of those types, and structures that contain them.
It will return immediately on the first error encountered.
While slices of fixed-size types are accepted, the size of that slice is not stored with the data. To work around this, store the size first.