0.0.20230715 • Published 10 months ago

memif v0.0.20230715

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

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.