Skip to main content
Home

Ethernet II binstruct coder (encode, decode)

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with 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

Examples

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);

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@binstruct/ethernet

Import symbol

import * as ethernet from "@binstruct/ethernet";
or

Import directly with a jsr specifier

import * as ethernet from "jsr:@binstruct/ethernet";

Add Package

pnpm i jsr:@binstruct/ethernet
or (using pnpm 10.8 or older)
pnpm dlx jsr add @binstruct/ethernet

Import symbol

import * as ethernet from "@binstruct/ethernet";

Add Package

yarn add jsr:@binstruct/ethernet
or (using Yarn 4.8 or older)
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";