function decodeCommandBody
decodeCommandBody<C extends Command>(
command: C,
xml: string
): CommandBody<C>

Reads a command body. Elements that are not among the command's parameters are ignored.

Examples

Ignore elements the command does not declare

import { assertEquals } from "@std/assert";
import { command, decodeCommandBody } from "@hertzg/reolink-api/protocol/command";
import { int, xmlParam } from "@hertzg/reolink-api/protocol/xml";

const linkType = command(93, "GET_LINK_TYPE", [
  xmlParam("LinkType", { channelId: int() }),
]);

assertEquals(decodeCommandBody(linkType, "<body><Other/></body>"), {});

Type Parameters

C extends Command

Parameters

command: C

The command whose parameters to read.

xml: string

The decrypted body XML; "" reads as {}.

Return Type

The parameter values found, by element name.

Throws

Error

When a parameter element misses a field its codec requires.

Usage

import { decodeCommandBody } from "protocol/command.ts";