type alias Cidrv4

Represents an IPv4 CIDR block.

Contains only the parsed values from the CIDR notation, in whichever of the two dialects it was written: a prefix length (PrefixedCidrv4) or a network mask (MaskedCidrv4). Every cidrv4* operation accepts both and works on the mask internally; a result that has a dialect matches the input, and mixed inputs give the mask form (ADR 0006).

The two branches exclude each other's key, so an object literal cannot carry both. If a value smuggled past the type checker does carry both, mask wins, because the mask is the form the operations compute on; nothing checks for the case at runtime.

Examples

The two dialects describe the same block

import { assertEquals } from "@std/assert";
import { type Cidrv4, cidrv4Size, parseCidrv4 } from "@hertzg/ip/cidrv4";

const prefixed: Cidrv4 = parseCidrv4("10.0.0.0/8");
const masked: Cidrv4 = { address: prefixed.address, mask: 0xFF000000 };

assertEquals(cidrv4Size(masked), cidrv4Size(prefixed));

Definition

Usage

import { type Cidrv4 } from "mod.ts";