Registry / serialization / protodef-protobuf

protodef-protobuf

JSON →
library1.0.0jsnpmunverified

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.

npm install protodef-protobuf
INSTALL
IMPORT
SIG · PROTODEF-PROTOBUF
P
protodef-protobuf
serializationjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const pp = require('protodef-protobuf')
import pp from 'protodef-protobuf'
CommonJS package; no default ESM export. Use require() or dynamic import().
transpile
const { transpile } = require('protodef-protobuf')
import { transpile } from 'protodef-protobuf'
Available as named export via destructuring from require().
addTypesToCompiler
const { addTypesToCompiler } = require('protodef-protobuf')
Used to register protobuf types with ProtoDefCompiler before compiling.

Transpile a .proto schema, compile with ProtoDef, and encode/decode a protobuf message using the library.

const { ProtoDefCompiler } = require('protodef').Compiler; const pp = require('protodef-protobuf'); const schema = ` syntax = "proto3"; package chat; message ChatMessage { string user_id = 1; string content = 2; } `; const generatedSchema = pp.transpile([schema]); const protocol = { ...generatedSchema, packet_hello: ['protobuf_message', { lengthType: 'varint', type: 'chat_ChatMessage' }] }; const compiler = new ProtoDefCompiler(); pp.addTypesToCompiler(compiler); compiler.addTypesToCompile(protocol); const proto = compiler.compileProtoDefSync(); const data = { user_id: 'user123', content: 'Hello, world!' }; const encoded = proto.createPacketBuffer('packet_hello', data); const decoded = proto.parsePacketBuffer('packet_hello', encoded); console.log(decoded);
Debug
Known issues
breakingVersion 1.0.0 is first stable release; API may have changed from 0.0.x versions.
fix
Review CHANGELOG for breaking changes; update imports and transpile() calls.
affects: >=0.0.2 <1.0.0
gotchaThe 'transpile' function expects an array of schema strings, not a single string.
fix
Pass schema(s) as array: pp.transpile([schema])
affects: >=0.0.2
gotchaProto type names are mangled: package_PascalCaseMessage (e.g. 'chat_ChatMessage').
fix
Use the naming convention as shown in generatedSchema keys.
affects: >=0.0.2
deprecatedUsage with 'protodef' interpreter mode may be deprecated; compiler mode is recommended.
fix
Prefer ProtoDefCompiler over ProtoDef for better performance.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: pp.transpile is not a function
Missing require('protodef-protobuf') or incorrect import.
fix
Ensure require or dynamic import is used: const pp = require('protodef-protobuf');
Error: protobuf_message type not found
Missing call to pp.addTypesToCompiler(compiler).
fix
Add pp.addTypesToCompiler(compiler) before compiler.addTypesToCompile(protocol).
Error: Type 'chat_ChatMessage' not defined
Mismatch between generated type name and use in protocol.
fix
Check generatedSchema keys for correct type name; use e.g. 'chat_ChatMessage'.
Error: Cannot find module 'protobufjs'
Missing protobufjs dependency (peer).
fix
Install protobufjs: npm install protobufjs
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
protobufjsrequiredUsed internally for parsing .proto files to ProtoDef schema
protodefrequiredRequired peer dependency for ProtoDef core types and compiler
Agent activity
2 hits · last 30 days
node
2
Resources
protodef-protobuf — npm install protodef-protobuf · libregistry