thrift-native

Native node.js bindings for fast thirft serialization.

Usage no npm install needed!

<script type="module">
  import thriftNative from 'https://cdn.skypack.dev/thrift-native';
</script>

README

thrift-native

Node.js bindings to Thrift's C++ library. Designed for easy manually serializing / deserializing payloads with thrift. Currently only supports the Compact protocol.

This makes serializing large structs significantly faster. Currently, only the serializer uses the C++ library, and the deserializer just uses the thrift node library.

Using

First, you need to install the package:

npm install thrift-native --save

You can them import the Serializer and Deserializer classes and use them on your generated thrift structs:

import { Serializer, Deserializer } from 'thrift-native';
import { MyThriftStruct } from './generated/thrift';

const struct = new MyThriftStruct({ some: 'data' });
const serializer = new Serializer();
struct.write(serializer);

// To get the serialized value and reset the serializer:
const serailizedThrift = serializer.flush();

const deserializer = new Deserializer(serailizedThrift);
const structFromThrift = new MyThriftStruct();
structFromThrift.read(deserializer);