Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flatbuffers

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flatbuffers

Memory Efficient Serialization Library

  • 24.12.23
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
453K
decreased by-19.06%
Maintainers
2
Weekly downloads
 
Created

What is flatbuffers?

FlatBuffers is an efficient cross-platform serialization library for C++, C#, C, Go, Java, JavaScript, TypeScript, PHP, and Python. It allows you to create and access serialized data without parsing/unpacking it, making it ideal for performance-critical applications.

What are flatbuffers's main functionalities?

Creating a FlatBuffer

This code demonstrates how to create a FlatBuffer with a string and a vector of strings. The buffer is then finished and converted to a Uint8Array.

const flatbuffers = require('flatbuffers');
const builder = new flatbuffers.Builder(1024);

// Create a string
const str = builder.createString('Hello, FlatBuffers!');

// Create a vector of strings
const strings = builder.createVectorOfStrings(['foo', 'bar', 'baz']);

// Finish the buffer
builder.finish(strings);

// Get the buffer
const buf = builder.asUint8Array();
console.log(buf);

Reading a FlatBuffer

This code demonstrates how to read a FlatBuffer. It assumes that the buffer contains data for a 'Monster' object, and it accesses the 'name' and 'hp' fields of the object.

const flatbuffers = require('flatbuffers');
const MyGame = require('./mygame_generated'); // Generated code

// Assume buf is a Uint8Array containing the FlatBuffer data
const buf = new Uint8Array([/* FlatBuffer data */]);

// Get the root object
const bb = new flatbuffers.ByteBuffer(buf);
const root = MyGame.Example.Monster.getRootAsMonster(bb);

// Access data
console.log(root.name());
console.log(root.hp());

Other packages similar to flatbuffers

Keywords

FAQs

Package last updated on 23 Dec 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