function withRefsInContext
withRefsInContext(ctx: Context): Context

Ensures that a context has the necessary reference storage initialized.

This function checks if the given context already has reference storage and initializes it if not. It's typically called before encoding/decoding operations that use references.

Examples

Example 1

import { assertEquals } from "@std/assert";
import { withRefsInContext } from "./ref.ts";
import { createContext } from "../core.ts";

// Create a basic context
const ctx = createContext("encode");

// Initialize it with reference support
const ctxWithRefs = withRefsInContext(ctx);

// Verify the context now has reference storage
assertEquals(ctxWithRefs === ctx, true);

Parameters

ctx: Context

The context to initialize with references

Return Type

Context

The context with reference storage initialized

Usage

import { withRefsInContext } from "ref/ref.ts";