@binstruct/ethernet@0.1.1
latest
hertzg/jsr-monorepoEthernet II binstruct coder (encode, decode)
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




JSR Score
100%
Published
a month ago (0.1.1)
Ethernet frame encoding and decoding utilities using binary structures.
This module provides coders for Ethernet frame structures including:
- Ethernet II frames with standard headers
- MAC address encoding/decoding
- EtherType field handling
- Frame payload management
Basic Ethernet frame encoding and decoding
Basic Ethernet frame encoding and decoding
import { assertEquals } from "@std/assert"; import { ethernet2Frame } from "@binstruct/ethernet"; const frameCoder = ethernet2Frame(); const testFrame = { dstMac: new Uint8Array([0x00, 0x11, 0x22, 0x33, 0x44, 0x55]), srcMac: new Uint8Array([0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB]), etherType: 0x0800, // IPv4 payload: new Uint8Array([0x45, 0x00, 0x00, 0x14]) }; const buffer = new Uint8Array(1500); const bytesWritten = frameCoder.encode(testFrame, buffer); const [decodedFrame, bytesRead] = frameCoder.decode(buffer); assertEquals(bytesRead, buffer.length); assertEquals(bytesWritten, 18); assertEquals(decodedFrame.dstMac, testFrame.dstMac); assertEquals(decodedFrame.srcMac, testFrame.srcMac); assertEquals(decodedFrame.etherType, testFrame.etherType);
Add Package
deno add jsr:@binstruct/ethernet
Import symbol
import * as ethernet from "@binstruct/ethernet";
Import directly with a jsr specifier
import * as ethernet from "jsr:@binstruct/ethernet";
Add Package
pnpm i jsr:@binstruct/ethernet
pnpm dlx jsr add @binstruct/ethernet
Import symbol
import * as ethernet from "@binstruct/ethernet";
Add Package
yarn add jsr:@binstruct/ethernet
yarn dlx jsr add @binstruct/ethernet
Import symbol
import * as ethernet from "@binstruct/ethernet";
Add Package
vlt install jsr:@binstruct/ethernet
Import symbol
import * as ethernet from "@binstruct/ethernet";
Add Package
npx jsr add @binstruct/ethernet
Import symbol
import * as ethernet from "@binstruct/ethernet";
Add Package
bunx jsr add @binstruct/ethernet
Import symbol
import * as ethernet from "@binstruct/ethernet";