{"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.","language":"javascript","status":"active","last_verified":"Fri May 01","install":{"commands":["npm install protodef-protobuf"],"cli":null},"imports":["const pp = require('protodef-protobuf')","const { transpile } = require('protodef-protobuf')","const { addTypesToCompiler } = require('protodef-protobuf')"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}