{"id":26115,"library":"protodef-protobuf","title":"protodef-protobuf","description":"A transpiler and runtime for using Google Protocol Buffers (.proto files) with ProtoDef in Node.js. Version 1.0.0 is the current stable release; the package is actively maintained with an irregular release cadence (last two releases: 0.0.2 and 1.0.0). Key differentiators include support for Proto2 and Proto3, nested messages, enums, maps, packed repeated fields, extensions, imports (including Google well-known types), and a protobuf_message container for length-prefixing. It offers both a compiler mode for high performance via ProtoDef's AOT compiler and an interpreter mode for dynamic schemas. Compared to alternatives like protobuf.js or protobuf-es, this library integrates tightly with the ProtoDef ecosystem, making it suitable for projects already using ProtoDef for protocol definitions.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/extremeheat/protodef-protobuf","tags":["javascript","typescript"],"install":[{"cmd":"npm install protodef-protobuf","lang":"bash","label":"npm"},{"cmd":"yarn add protodef-protobuf","lang":"bash","label":"yarn"},{"cmd":"pnpm add protodef-protobuf","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for parsing .proto files to ProtoDef schema","package":"protobufjs","optional":false},{"reason":"Required peer dependency for ProtoDef core types and compiler","package":"protodef","optional":false}],"imports":[{"note":"CommonJS package; no default ESM export. Use require() or dynamic import().","wrong":"import pp from 'protodef-protobuf'","symbol":"default","correct":"const pp = require('protodef-protobuf')"},{"note":"Available as named export via destructuring from require().","wrong":"import { transpile } from 'protodef-protobuf'","symbol":"transpile","correct":"const { transpile } = require('protodef-protobuf')"},{"note":"Used to register protobuf types with ProtoDefCompiler before compiling.","wrong":null,"symbol":"addTypesToCompiler","correct":"const { addTypesToCompiler } = require('protodef-protobuf')"}],"quickstart":{"code":"const { ProtoDefCompiler } = require('protodef').Compiler;\nconst pp = require('protodef-protobuf');\n\nconst schema = `\n  syntax = \"proto3\";\n  package chat;\n  message ChatMessage {\n    string user_id = 1;\n    string content = 2;\n  }\n`;\n\nconst generatedSchema = pp.transpile([schema]);\nconst protocol = {\n  ...generatedSchema,\n  packet_hello: ['protobuf_message', {\n    lengthType: 'varint',\n    type: 'chat_ChatMessage'\n  }]\n};\n\nconst compiler = new ProtoDefCompiler();\npp.addTypesToCompiler(compiler);\ncompiler.addTypesToCompile(protocol);\nconst proto = compiler.compileProtoDefSync();\n\nconst data = { user_id: 'user123', content: 'Hello, world!' };\nconst encoded = proto.createPacketBuffer('packet_hello', data);\nconst decoded = proto.parsePacketBuffer('packet_hello', encoded);\nconsole.log(decoded);","lang":"javascript","description":"Transpile a .proto schema, compile with ProtoDef, and encode/decode a protobuf message using the library."},"warnings":[{"fix":"Review CHANGELOG for breaking changes; update imports and transpile() calls.","message":"Version 1.0.0 is first stable release; API may have changed from 0.0.x versions.","severity":"breaking","affected_versions":">=0.0.2 <1.0.0"},{"fix":"Pass schema(s) as array: pp.transpile([schema])","message":"The 'transpile' function expects an array of schema strings, not a single string.","severity":"gotcha","affected_versions":">=0.0.2"},{"fix":"Use the naming convention as shown in generatedSchema keys.","message":"Proto type names are mangled: package_PascalCaseMessage (e.g. 'chat_ChatMessage').","severity":"gotcha","affected_versions":">=0.0.2"},{"fix":"Prefer ProtoDefCompiler over ProtoDef for better performance.","message":"Usage with 'protodef' interpreter mode may be deprecated; compiler mode is recommended.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure require or dynamic import is used: const pp = require('protodef-protobuf');","cause":"Missing require('protodef-protobuf') or incorrect import.","error":"TypeError: pp.transpile is not a function"},{"fix":"Add pp.addTypesToCompiler(compiler) before compiler.addTypesToCompile(protocol).","cause":"Missing call to pp.addTypesToCompiler(compiler).","error":"Error: protobuf_message type not found"},{"fix":"Check generatedSchema keys for correct type name; use e.g. 'chat_ChatMessage'.","cause":"Mismatch between generated type name and use in protocol.","error":"Error: Type 'chat_ChatMessage' not defined"},{"fix":"Install protobufjs: npm install protobufjs","cause":"Missing protobufjs dependency (peer).","error":"Error: Cannot find module 'protobufjs'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}