addressv6ToBytes(): Uint8Array
Writes a 16-byte IPv6 address, either into a fresh buffer or into one you supply.
The address is written in network order (big-endian) as four 32-bit chunks.
The return value is always exactly the sixteen bytes written: a fresh
Uint8Array when into is omitted, and a view into into when it is
given — never the whole of into. Writing through that view writes into
into.
Allocate
Allocate
import { assertEquals } from "@std/assert"; import { addressv6ToBytes } from "@hertzg/ip/bytesv6"; import { parseAddressv6 } from "@hertzg/ip/addressv6"; // deno-fmt-ignore assertEquals(addressv6ToBytes(parseAddressv6("2001:db8::1").address), new Uint8Array([ 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, ]));
Write into an existing frame
Write into an existing frame
import { assertEquals } from "@std/assert"; import { addressv6ToBytes } from "@hertzg/ip/bytesv6"; import { parseAddressv6 } from "@hertzg/ip/addressv6"; const frame = new Uint8Array(40); const written = addressv6ToBytes(parseAddressv6("::1").address, frame, 8); assertEquals(written.length, 16); assertEquals(frame[23], 1);
optional
into: Uint8Array
The buffer to write into, whose size the caller owns; a 16-byte buffer is allocated when omitted
The sixteen bytes written