
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
Bytable - The Core PackageThe platform-agnostic library used as a core building block for browser and nodejs binary serializers. Before using this package check out bytable-node and bytable-client.
npm install bytable
The terminology defined here by author will introduce core concepts and principals the library is relying on.
Byte Table is a data structure describing memory allocation for underlying binary representation of an object. It can be visualized as a table with three key columns: type, offset and size, - the rows are corresponding class fields.
class Foo {
a: int;
b: string;
}
class Foo | TYPE | OFFSET (bytes) | SIZE (bytes) |
|---|---|---|---|
| a | int | x_a | y_a |
| b | string | x_b | y_b |
Please see example below.
Static Types are atomic fixed-size types (the size is known at compile time). There are limited to integer (Int8, Int16 and Int32), unsigned integer (UInt8, UInt16 and UInt32), floating point (Float and Double) and boolean (Boolean). A projection of static type data into binary representation can be identified by two parameters: offset and size. Offset is showing for how many bytes the data is shifted in memory. The size is a number of bytes to be allocated in memory starting with the offset pointer.
Dynamic Types are atomic types of dynmic sizes known only at run-time. Supported out of the box dynamic types are String and raw Binary, but it can be extended with BSON, for instance. A dynamic type is a combination of a static type header saying the data size (bynary length) and body of this size. By convention a header name is suffixed with "_SIZE" and it's UInt32 (i.e. max capacity of dynamic type is limited by UInt32.Max bytes).
By design byte tables should compliment serializable classes. Probably the best option available today in javascript or typescript is decorators. The linbrary exposes a set of decorators, which can attach platform-agnostic types to javascript objects.
Each serializable class should be decorated with @proto (from protocol) and each seriazable field - with one of the decorators from a table below.
| Group | Decorator | Aliases | Size (bytes) |
|---|---|---|---|
| Unsigned Integer | @uint8 | @u8 | 1 |
| @uint16 | @u16 | 2 | |
| @uint32 | @u32 | 4 | |
| Signed Integer | @int8 | @i8 | 1 |
| @int16 | @i16 | 2 | |
| @int32 | @i32 | 4 | |
| Floatin Point | @float | @f | 4 |
| @double | @d | 8 | |
| Boolean | @boolean | @bool | 1 |
| String | @string | @s | dynamic |
| Raw Binary | @binary | dynamic | |
| BSON | @bson | @obj | dynamic |
Here is a typical POST Request class written in TypeScript with type decorators:
import { proto, uint8, uint16, bson, string } from 'bytable';
@proto
class Request {
@string
requestId: string;
@uint8
readonly index: number;
@uint16
readonly count: number;
@bson
payload: IPayload;
}
The underlying Byte Table, generated in run-time:
| FIELD | TYPE | OFFSET (bytes) | SIZE (bytes) |
|---|---|---|---|
| requestId_SIZE | UInt32BE | 0 | 4 |
| requestId | String | 4 | 123 |
| index | UInt8 | 127 | 1 |
| count | UInt16BE | 128 | 2 |
| payload_SIZE | UInt32BE | 130 | 4 |
| payload | BSON | 134 | 42 |
Dynamic fields are accomponied with a header holding the field size. The name of this header has a suffix "_SIZE" by convention.
The next step is to convert an object into raw binary using a byte table. Two abstract classes are responsible for this: Reader and Writer. They are a layer of abstraction exposed to the library consumers, which should implement platform-specific bindings such as memory allocation and read/write from static types.
NodeJS and Browser implementations:
Summarizing there are two fundamental points of extension: Reader/Writer and decorators for custom dynamic types such as BSON.
The End
FAQs
Byte Tables for binary serialization
We found that bytable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.