Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@protobuf-ts/runtime
Advanced tools
Runtime library for code generated by the protoc plugin "protobuf-ts"
@protobuf-ts/runtime is a runtime library for Protocol Buffers in TypeScript. It provides utilities for encoding, decoding, and working with Protocol Buffers messages in a TypeScript environment.
Encoding Messages
This feature allows you to encode a Protocol Buffers message into a binary format. The code sample demonstrates how to define a message class, create an instance of the message, and encode it.
const { Message, WireType } = require('@protobuf-ts/runtime');
class MyMessage extends Message {
static readonly runtime = { fields: [{ no: 1, name: 'field1', kind: 'scalar', T: 9 /* string */ }] };
field1 = '';
}
const message = new MyMessage({ field1: 'Hello, World!' });
const binary = MyMessage.encode(message).finish();
console.log(binary);
Decoding Messages
This feature allows you to decode a binary Protocol Buffers message back into a message object. The code sample demonstrates how to decode a binary message into an instance of the message class.
const { Message, WireType } = require('@protobuf-ts/runtime');
class MyMessage extends Message {
static readonly runtime = { fields: [{ no: 1, name: 'field1', kind: 'scalar', T: 9 /* string */ }] };
field1 = '';
}
const binary = new Uint8Array([10, 13, 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]);
const message = MyMessage.decode(binary);
console.log(message);
Message Reflection
This feature provides reflection capabilities for Protocol Buffers messages, allowing you to inspect the fields and types of a message at runtime. The code sample demonstrates how to access the runtime information of a message class.
const { Message, WireType } = require('@protobuf-ts/runtime');
class MyMessage extends Message {
static readonly runtime = { fields: [{ no: 1, name: 'field1', kind: 'scalar', T: 9 /* string */ }] };
field1 = '';
}
const message = new MyMessage({ field1: 'Hello, World!' });
console.log(MyMessage.runtime.fields);
protobufjs is a popular library for working with Protocol Buffers in JavaScript and TypeScript. It provides similar functionality to @protobuf-ts/runtime, including encoding, decoding, and message reflection. However, protobufjs is more widely used and has a larger community.
google-protobuf is the official Protocol Buffers library for JavaScript. It provides core functionality for encoding and decoding Protocol Buffers messages. While it is not as TypeScript-friendly as @protobuf-ts/runtime, it is the standard library provided by Google.
ts-proto is a TypeScript-first Protocol Buffers library that generates TypeScript code from .proto files. It provides strong type safety and integrates well with TypeScript projects. Compared to @protobuf-ts/runtime, ts-proto focuses more on code generation and type safety.
Runtime library for code generated by protobuf-ts.
Create, clone, serialize, and compare protobuf messages. Get reflection information about message fields and custom options.
Installation:
# with npm:
npm install @protobuf-ts/runtime
# with yarn:
yarn add @protobuf-ts/runtime
You probably want the protoc plugin as well:
# with npm:
npm install -D @protobuf-ts/plugin
# with yarn:
yarn add --dev @protobuf-ts/plugin
To learn more, please read the MANUAL or check the repository README for a quick overview.
FAQs
Runtime library for code generated by the protoc plugin "protobuf-ts"
The npm package @protobuf-ts/runtime receives a total of 303,692 weekly downloads. As such, @protobuf-ts/runtime popularity was classified as popular.
We found that @protobuf-ts/runtime demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.