memif
TypeScript icon, indicating that this package has built-in type declarations

0.0.20240119 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i memif

Weekly Downloads

1

Version

0.0.20240119

License

ISC

Unpacked Size

19.4 kB

Total Files

7

Last publish

Collaborators

  • yoursunny