New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tsprotobuf-codec

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsprotobuf-codec

A browser-compatible protocol buffer encoder/decoder in typescript

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

tsprotobuf-codec

A browser-compatible protocol buffer encoder/decoder in typescript

Using

Note: this package is designed to be used from code generated by a protocol buffer code generator, but it can be used in any low-level library or to dynamically construct any arbitrary protocol buffer message. The example here shows one way of doing that.

yarn add tsprotobuf-codec

This provides read and write functions for translating between the wire format and javascript representation of the various proto3 types, such as int32, double, fixed32, etc..

So if you had a protocol buffer that looked something like this:

message MyMessage {
    int32 my_number = 1;
    string my_string = 2;
}

Then you could write that with the following code (normally raw access like this would be through generated code)

  import {WriteField as write, allocateNestingWriter, arrayCollector} from "tsprotobuf-codec";

  const myNumber = 42;
  const myNumber_field = 1;

  const myString = "The ultimate answer";
  const myString_field = 2;

  // Preallocate a buffer
  const writer = allocateNestingWriter(1024);

  // Write the fields to the buffer
  write.int32(writer, myNumber, myNumber_field);
  write.string(writer, myString, myString_field);

  // and then get the resulting blob
  const encoded = writer.finish(arrayCollector);

Building

yarn install
yarn test

FAQs

Package last updated on 31 Jan 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc