Socket
Socket
Sign inDemoInstall

@f0rr0/thrift-compact-protocol

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @f0rr0/thrift-compact-protocol

Marshalling/unmarshalling between Facebook Thrift Compact Protocol and Javascript with type definitions.


Version published
Maintainers
1
Created

Readme

Source

thrift-compact-protocol

Marshalling/unmarshalling between Facebook Thrift Compact Protocol and Javascript with type definitions.

Usage

import {
  t,
  ThriftType,
  thriftReadToObject,
  thriftWriteFromObject,
} from '@f0rr0/thrift-compact-protocol'

// Describe the shape of expected Thrift data over the wire
const structDefinition = t.struct({
  foo: t.field(1, t.boolean()),
  bar: t.field(2, t.int64()).optional(),
  baz: t.field(
    4,
    t.list(
      t.struct({
        quz: t.field(1, t.binary()),
      })
    )
  ),
})

// Typescript type is inferred from the Thrift definition
type StructDefinition = t.TypeOf<typeof structDefinition>

// Parse a Thrift buffer to JS object
const javascriptObject = thriftReadToObject(
  someThriftBufferPayload,
  structDefinition
)

// Write JS object to Thrift buffer
const thriftBuffer = thriftWriteFromObject(
  {
    foo: true,
    bar: BigInt(1),
    baz: [
      {
        quz: 'string',
      },
    ],
  },
  structDefinition
)

FAQs

Last updated on 27 May 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc