{"id":26267022,"url":"https://github.com/the-minimal/protocol","last_synced_at":"2025-12-28T09:26:44.246Z","repository":{"id":237483204,"uuid":"794519877","full_name":"the-minimal/protocol","owner":"the-minimal","description":"Minimal and modular binary schema-full protocol for TypeScript.","archived":false,"fork":false,"pushed_at":"2024-05-29T19:31:09.000Z","size":2838,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-06-02T17:03:37.305Z","etag":null,"topics":["avro","binary-json","binary-protocol","bson","javascript","json","jsonb","protocol","protocol-buffers","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/the-minimal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-01T11:14:41.000Z","updated_at":"2024-07-06T13:43:05.786Z","dependencies_parsed_at":"2024-05-29T22:20:08.940Z","dependency_job_id":"eab11b13-c964-4938-857f-8aa0b879e4c9","html_url":"https://github.com/the-minimal/protocol","commit_stats":null,"previous_names":["the-minimal/protocol"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-minimal%2Fprotocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-minimal%2Fprotocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-minimal%2Fprotocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-minimal%2Fprotocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/the-minimal","download_url":"https://codeload.github.com/the-minimal/protocol/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243521219,"owners_count":20304187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avro","binary-json","binary-protocol","bson","javascript","json","jsonb","protocol","protocol-buffers","typescript"],"created_at":"2025-03-14T04:15:10.208Z","updated_at":"2025-12-28T09:26:44.194Z","avatar_url":"https://github.com/the-minimal.png","language":"TypeScript","readme":"# Highlights\n\n- Small (~ 1.1 KB)\n- Minimal runtime overhead\n- Static type inference\n- Single-pass data validation\n\n# Example\n\n```ts\nimport { email, rangeLength } from \"@the-minimal/validator\";\nimport { encodeObject, encodeAscii8, encodeUint8, encodeTap } from \"@the-minimal/protocol\";\n\nconst encodeUserData = encodeObject([\n  {\n    key: \"email\",\n    type: encodeTap(\n      encodeAscii8,\n      email\n    )\n  },\n  {\n    key: \"age\",\n    type: encodeTap(\n      encodeUint8,\n      rangeValue(0, 120)\n    )\n  },\n]);\n\nconst array = new Uint8Array(128);\nconst view = new DataView(array.buffer);\nconst state = {\n  a: array,\n  v: view,\n  o: 0\n};\n\nencodeUserLogin(state, {\n  email: \"user@example.com\",\n  age: 26\n});\n\nreturn array.subarray(0, state.o);\n```\n\n# State\n\nEvery encoder and decoder accepts `State` which looks like this:\n\n```ts\ntype State = {\n  // array\n  a: Uint8Array;\n  // view\n  v: DataView;\n  // offset\n  o: number;\n};\n```\n\nThis library doesn't come with its own memory allocator.\n\nIt's up to you and your specific use-case what kind of memory allocator you use.\n\n# Modularity\n\nThis library is basically just a tiny opinionated wrapper around `State`.\n\nWe use either `Uint8Array` or `DataView` to modify or read buffer and then we bump the offset.\n\nAll functions are standalone encoders and decoders which take `State` as a parameter.\n\nThis makes it very easy to extend the library to your liking and compose our encoders and decoders with your custom ones.\n\n# API\n\n## Bool\n\nEncoded as `Uint8` with values `0` or `1`.\n\n```ts\nencodeBool(state, true);\ndecodeBool(state);\n```\n\n## Uint8\n\n```ts\nencodeUint8(state, 64);\ndecodeUint8(state);\n```\n\n## Uint16\n\n```ts\nencodeUint16(state, 1024);\ndecodeUint16(state);\n```\n\n## Uint32\n\n```ts\nencodeUint32(state, 128_000);\ndecodeUint32(state);\n```\n\n## Int8\n\n```ts\nencodeInt8(state, 64);\ndecodeInt8(state);\n```\n\n## Int16\n\n```ts\nencodeInt16(state, 1024);\ndecodeInt16(state);\n```\n\n## Int32\n\n```ts\nencodeInt32(state, 128_000);\ndecodeInt32(state);\n```\n\n## Float32\n\n```ts\nencodeFloat32(state, 3.16);\ndecodeFloat32(state);\n```\n\n## Float64\n\n```ts\nencodeFloat64(state, 420_000.69);\ndecodeFloat64(state);\n```\n\n## Ascii8\n\nASCII string of maximum length of 256 bytes (256 characters).\n\n```ts\nencodeAscii8(state, \"Hello, World!\");\ndecodeAscii8(state);\n```\n\n## Ascii16\n\nASCII string of maximum length of 65536 bytes (65536 characters).\n\n```ts\nencodeAscii16(state, \"Lorem ipsum dolor sit amet, ..\");\ndecodeAscii16(state);\n```\n\n## Unicode8\n\nUnicode string of maximum length of 256 bytes (64-128 characters).\n\n```ts\nencodeUnicode8(state, \"Dobré ráno, světe!\");\ndecodeUnicode8(state);\n```\n\n## Unicode16\n\nASCII string of maximum length of 65536 bytes (16384-32768 characters).\n\n```ts\nencodeUnicode16(state, \"Oprávněné aniž i odstoupil o snadno osoby ..\");\ndecodeUnicode16(state);\n```\n\n## Array8\n\nArray of maximum length of 256.\n\n```ts\nencodeArray8(encodeUint8)(state, [1, 16, 4, 8, 7]);\ndecodeArray8(encodeUint8)(state);\n```\n\n## Array16\n\nArray of maximum length of 65536.\n\n```ts\nencodeArray16(encodeUint8)(state, [1, 16, 4, 8, 7, ..]);\ndecodeArray16(encodeUint8)(state);\n```\n\n## Object\n\nAll keys have to be defined, otherwise the buffer will be misaligned.\n\n```ts\nencodeObject([\n  { key: \"email\", type: encodeAscii8 },\n  { key: \"password\", type: encodeAscii8 },\n])(state, {\n  email: \"yamiteru@icloud.com\",\n  password: \"Test123456\"\n});\n\ndecodeObject([\n  { key: \"email\", type: decodeAscii8 },\n  { key: \"password\", type: decodeAscii8 },\n])(state);\n```\n\n## Tuple\n\nThe maximum length of tuple is 256.\n\n```ts\nencodeTuple([\n  encodeUint8,\n  encodeUint8,\n  encodeAscii\n])(state, [185, 90, \"yamiteru\"]);\n\ndecodeTuple([\n  decodeUint8,\n  decodeUint8,\n  decodeAscii\n])(state);\n```\n\n## Enum\n\nMaximum length of enum options is 256.\nOptions are represented as uint8 indexes.\n\n```ts\nencodeEnum([\"ADMIN\", \"USER\"])(state, \"USER\");\ndecodeEnum([\"ADMIN\", \"USER\"])(state);\n```\n\n## Nullable\n\nValue in buffer is prefixed with uint8 `0` if value is not null or `1` if value is null.\n\n```ts\nencodeNullable(encodeUint8)(state, 2);\ndecodeNullable(decodeUint8)(state);\n```\n\n## Tap\n\nThis function is not encoded into buffer.\n\nIt's used for intercepting values.\n\nMost notable use-case would be data validation while encoding or decoding.\n\nThe tap is executed before encoding and after decoding.\n\n```ts\nencodeTap(encodeUint8, () =\u003e { /* .. */ })(state, 2);\ndecodeTap(decodeUint8, () =\u003e { /* .. */ })(state);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-minimal%2Fprotocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthe-minimal%2Fprotocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-minimal%2Fprotocol/lists"}