{"id":16916456,"url":"https://github.com/extremeheat/protodef-cpp","last_synced_at":"2026-03-03T21:32:10.965Z","repository":{"id":187020971,"uuid":"673233736","full_name":"extremeheat/protodef-cpp","owner":"extremeheat","description":"C++ compiler for ProtoDef schemas","archived":false,"fork":false,"pushed_at":"2025-01-30T16:00:21.000Z","size":678,"stargazers_count":2,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-24T19:46:25.538Z","etag":null,"topics":["cpp","protodef"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/extremeheat.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.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,"zenodo":null}},"created_at":"2023-08-01T07:09:28.000Z","updated_at":"2025-08-18T06:52:53.000Z","dependencies_parsed_at":"2025-04-11T17:39:35.503Z","dependency_job_id":"6ff3c830-0348-4e2e-a5e6-90b56a14e66b","html_url":"https://github.com/extremeheat/protodef-cpp","commit_stats":null,"previous_names":["extremeheat/protodef-cpp"],"tags_count":3,"template":false,"template_full_name":"PrismarineJS/prismarine-template","purl":"pkg:github/extremeheat/protodef-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extremeheat%2Fprotodef-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extremeheat%2Fprotodef-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extremeheat%2Fprotodef-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extremeheat%2Fprotodef-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/extremeheat","download_url":"https://codeload.github.com/extremeheat/protodef-cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/extremeheat%2Fprotodef-cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30062411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cpp","protodef"],"created_at":"2024-10-13T19:27:41.393Z","updated_at":"2026-03-03T21:32:10.936Z","avatar_url":"https://github.com/extremeheat.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# protodef-cpp\n[![NPM version](https://img.shields.io/npm/v/protodef-cpp.svg?logo=npm)](http://npmjs.com/package/protodef-cpp)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/extremeheat/protodef-cpp/ci.yml.svg?label=CI\u0026logo=github)](https://github.com/extremeheat/protodef-cpp/actions?query=workflow%3A%22CI%22)\n[![Try it on gitpod](https://img.shields.io/static/v1.svg?label=try\u0026message=on%20gitpod\u0026color=brightgreen\u0026logo=gitpod)](https://gitpod.io/#https://github.com/extremeheat/protodef-cpp)\n[![Official Discord](https://img.shields.io/static/v1.svg?label=PrismarineJS\u0026message=Discord\u0026color=blue\u0026logo=discord)](https://discord.gg/GsEFRM8)\n\nC++ compiler in Node.js for ProtoDef schemas, a lighter and more versatile alternative to Protocol Buffers or FlatBuffers that can support any binary format.\n\nSee the ProtoDef specification at https://github.com/ProtoDef-io/ProtoDef.\n\n### Features\n* Header-only : No dependencies other than the C or C++ standard libraries\n* Arrays, enums, nested structures, optional fields, variable-length integers/strings, custom types, etc. See ProtoDef spec for more details\n* Built-in support for dumping JSON for utility/debugging on top of binary encode/decode\n\n## Install\n```cmd\nnpm install protodef-cpp\n```\n\n## Usage\n\n### via npx / command line \n\nFeed the CLI tool a .json or .yaml file, and optionally specify a directory to write the generated files to.\nTwo header files will be written: a \"streams.h\", containing a binary stream implementation used by the encoder/decoder (if you don't already have one), \nand a \"protocol.h\" header file (name will vary depending on your input name), containing the generated encoder/decoder code.\n\n```go\n$ npx protodef-cpp --help\nprotodef-cpp - v1.0.0\nprotodef-cpp - A C++ compiler for ProtoDef schemas\n\nOptions:\n  --input, -i   Path to ProtoDef JSON/YAML file with protocol data\n  --lang, -l    What language use compile to. Currently only C++.  (default: cpp)\n  --output      Output folder  (default: ./)\n  --config, -t  Path to JS file whose exports will be merged into the current options, which allows you to define custom types and variables.\n  --namespace   What namespace to use, useful if you have multiple protocols.  (default: proto)\n```\n\nIf you have multiple protocols specified inside one JSON file, please use the programmatic API instead ([example](https://github.com/extremeheat/protodef-cpp/blob/master/examples/mcpc-protocol/main.js)).\n\n### via code / programmatic API\n\n```js\nconst protodefCpp = require('protodef-cpp')\nprotodefCpp.compile({\n  inputFile: 'protocol.json',\n  outputFolder: './',\n  lang: 'cpp',\n  namespace: 'proto',\n})\n```\n\n### Example\n\nprotocol.yml:\n\n```yaml\nstring: [\"pstring\", { countType: \"varint\" }]\npacket_video_stream_connect:\n  server_uri: string\n  frame_send_frequency: lf32\n  action: u8 =\u003e\n     1: none\n     2: close\n  resolution_x: li32\n  resolution_y: li32\n```\n\n\u003c!-- \u003cdetails\u003e\n\u003csummary\u003eCustom Types implementation in JavaScript\u003c/summary\u003e\nInside types.js:\n\n```js\nmodule.exports = {\n pstring: {\n    struct (args, name, makeCallingCode) {\n      return makeCallingCode('std::string', name)\n    },\n    read (args, [name, refName], makeCallingCode) {\n      if (args.count) return `if (!stream.readString(${refName}, ${args.count})) return false;`\n      const primitiveType = protodefTypeToCpp[args.countType]\n      return `\n        ${primitiveType} ${name}_strlen; ${makeCallingCode(args.countType, `${name}_strlen`)};\n        if (!stream.readString(${refName}, ${name}_strlen)) return false;\n      `.trim()\n    },\n    write (args, [name, refName], makeCallingCode) {\n      if (args.count) return `WRITE_OR_BAIL(writeString, ${refName});`\n      return `\n        ${makeCallingCode(args.countType, [refName, 'length()'])};\n        WRITE_OR_BAIL(writeString, ${refName});\n      `.trim()\n    },\n    size (args, [name, refName], makeCallingCode) {\n      if (args.count) return `len += ${args.count};`\n      return `\n        ${makeCallingCode(args.countType, [refName, 'length()'])};\n        len += ${refName}.length();\n      `.trim()\n    }\n  }\n}\n```\n\u003c/details\u003e --\u003e\n\nCommand line:\n```cmd\nnpx protodef-cpp -i protocol.yml --lang cpp\n```\n\nDone! You should now have a \"protocol.h\" file in your current directory. Here's how you would encode a structure:\n\n```cpp\n#include \"protocol.h\"\n\nint main () {\n  pdef::proto::packet_video_stream_connect packet {\n    .server_uri = \"wss://example.com\",\n    .frame_send_frequency = 60.0f,\n    .action = pdef::proto::packet_video_stream_connect::Action::None,\n    .resolution_x = 1920,\n    .resolution_y = 1080,\n  };\n  pdef::Stream stream(0);\n  pdef::proto::encode::packet_video_stream_connect(stream, packet);\n  stream.dumpToStdout();\n  return 0;\n}\n```\n\nSee [examples/](https://github.com/extremeheat/protodef-cpp/tree/master/examples) for more examples.\n\n### Deviations from ProtoDef spec\n\nprotodef-cpp does not support root level switches, or $ variables. Some \npreprocessing is done to inline root level switches, but for $ variables,\nsome complex use-cases may not work. Please update the schema to not use $ \nvariables if you encounter any issues.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextremeheat%2Fprotodef-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fextremeheat%2Fprotodef-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextremeheat%2Fprotodef-cpp/lists"}