alexolivier / protobuf-js-from-object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

protobuf-js-from-object

This project comes from the issue: https://github.com/protocolbuffers/protobuf/issues/1591

There is no fromObject implementation in google-protobuf implementation so I wrote a little bit hacky solution to serialize protobuf object.

Examples

To run example, run the following command in examples folder:

yarn start

How to use it?

Import in Typescript

import { serializeFromObject } from "protobuf-js-from-object";

Import in Javascript

const { serializeFromObject } = require("protobuf-js-from-object");

Usage

const buffer: Uint8Array = serializeFromObject(obj, SomeProtoClass);
// Save into file or send it via network or whatever...
const classObj = SomeProtoClass.deserializeBinary(buffer);
const pureObj = classObj.toObject(false);

About

License:MIT License


Languages

Language:JavaScript 100.0%