Home

Awesome

MUS Serialization Format

MUS (Marshal, Unmarshal, Size) format, which by the way is a binary format, tries to be as simple as possible. You won't find field names, types or any other information in it besides values (with few exceptions, such as the 'nil' pointer flag and length for variable-length data types). So, for example, an object of type Foo:

type Foo {
  a int
  b bool
  c string
}

in the MUS format may look like this:

Foo{a: 300, b: true, c: "hi"}    MUS->    [216 4 1 4 104 105]
, where 
- [216 4] - is the value of the field a
- [1] - value of the field b
- [4] - length of the field  c
- [104 105] - value of the field c

Note that the object fields are encoded in order, first the first, then second, then third, and so on.

Motivation

This approach provides:

  1. A simple serializer that can be implemented quite easily and quickly for any programming language.
  2. As we know, simple products are much easier to maintain + they usually have fewer bugs.
  3. And most importantly, the small number of bytes required to encode data. This means we can send fewer bytes over the network or store fewer bytes on disk. And that's great because I/O is often a performance bottleneck.

Format Features

Data Type Metadata (DTM)

You can place a data type metadata in front of the data. Like in the Data Versioning section.

Data Versioning

MUS format does not have explicit data versioning support. But you can always do next:

// In this case DTM defines both the type and its version.
const FooV1DTM = 1
const FooV2DTM = 2

type FooV1 {
  // ...
}

type FooV2 {
  // ...
}

dtm, err = UnmarshalDTM(buf)
// ...
// Check DTM before Unmarshal.
switch dtm {
  case FooV1DTM:
    fooV1, err = UnmarshalFooV1(buf)
    // ...
  case FooV2DTM:
    fooV2, err = UnmarshalFooV2(buf)
    // ...
  default:
    return ErrUnsupportedDTM
}

Moreover, it is highly recommended to use DTM. With it, you will always be ready for changes in the type structure or MUS format.

Thus, the MUS format suggests to have only one "version" mark for the entire type, instead of having a separate "version" mark for each field. And again, the motivation for this approach is described here.

Streaming

MUS format is suitable for streaming, all we need to know for this is the data type on the receiving side.

Serializers