yoursunny / node-memif

Shared Memory Packet Interface (memif) for Node.js

Home Page:https://www.npmjs.com/package/memif

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shared Memory Packet Interface (memif) for Node.js

npm package version GitHub Workflow status GitHub code size

This package is a Node C++ addon of libmemif, which provides high performance packet transmit and receive between Node.js and VPP/DPDK applications. It works on Linux only and requires libmemif 4.0 installed at /usr/local/lib/libmemif.so.

API Example

import { Memif } from "memif";

// Memif class is a Node.js Duplex stream.
const memif = new Memif({
  role: "client",
  socketName: "/run/memif.sock",
  id: 0,
  dataroom: 2048,
  ringCapacity: 1024,
});

// Readable side of the stream gives access to received packets.
memif.on("data", (pkt) => {
  // pkt is a Uint8Array containing received packet.
  // Fragmented messages with MEMIF_BUFFER_FLAG_NEXT are concatenated.
});

// Writable side of the stream allows transmitting packets.
// It accepts ArrayBufferView (including Uint8Array and Buffer) and ArrayBuffer.
// If packet is longer than dataroom, it is fragmented with MEMIF_BUFFER_FLAG_NEXT.
memif.send(Uint8Array.of(0x01, 0x02));

// Be sure to close the interface when no longer needed.
memif.close();

Limitations

Each Memif instance must have a distinct socketName.

About

Shared Memory Packet Interface (memif) for Node.js

https://www.npmjs.com/package/memif

License:ISC License


Languages

Language:C++ 48.8%Language:TypeScript 33.3%Language:JavaScript 15.5%Language:Python 2.4%