Skip to content

What is NanoPack?

NanoPack is a binary serialization format created for Poly. Messages exchanged between the portable layer and the native layer are serialized with NanoPack. Because of the large amount of messages exchanged between the two sides, NanoPack is designed to be easy to pack and parse.

NanoPack is currently being implemented in C++, TypeScript, and Swift.

Inspirations

NanoPack is heavily inspired by Protocol Buffer (protobuf), also a binary serialization format.

Why Not x?

Poly requires that the serialization format has the following features:

  • lightweight and minimal runtime
  • supports polymorphism to describe widget relations (array of widgets which can be texts, buttons, etc.)

Protobuf produces a large binary, so it is out of the question. Flatbuffer looks promising, but its type system is not very expressive. The closest thing to polymorphism, union vectors, are experimental and only supported by C++. Both JSON and YAML are inefficient when paired with statically-typed languages such as C++ and Swift.

Benchmark

I intend to benchmark NanoPack against other popular serialization formats when it is stable and more optimized. Currently, the primary goal is to build out Poly to a usable stage.

Glossaries

Below are terminologies that will be used throughout this documentation:

GlossaryDefinition
MessageA piece of structured data that contains fields that store different types of data. Think structs/classes
BufferA piece of contagious memory that stores raw bytes. Think bytes/byte array
SchemaA file that describes the shape/structure of a message or an enum.