Skip to main content
Version: 1.8

Decoder Function Reference

The functions of the payload decoder library, and the limits a decoder is held to. This page is generated from the function library in the platform, so it cannot fall behind it. The language's own built-ins are not listed: size, has and the conversions int, uint, double and bool.

Functions​

A decoder names the library version it was written for in envVersion; this page describes version 1. What a function does never changes once it has shipped: a fix or a variant arrives under a new name in a new version, so a saved decoder keeps giving the same answers. The descriptions are the library's own text and are in English in every language. Cost is what the call itself adds, in cost units; every name, literal, operator and conversion in an expression adds about 1 as well. A function that takes bytes reads them from frame or from another function that returns bytes.

Integers​

FunctionSignatureWhat it doesCost
u8u8(bytes, int) -> intReads a 8-bit unsigned value at a byte offset.1
u16beu16be(bytes, int) -> intReads a 16-bit unsigned big-endian value at a byte offset.1
u16leu16le(bytes, int) -> intReads a 16-bit unsigned little-endian value at a byte offset.1
u24beu24be(bytes, int) -> intReads a 24-bit unsigned big-endian value at a byte offset.1
u24leu24le(bytes, int) -> intReads a 24-bit unsigned little-endian value at a byte offset.1
u32beu32be(bytes, int) -> intReads a 32-bit unsigned big-endian value at a byte offset.1
u32leu32le(bytes, int) -> intReads a 32-bit unsigned little-endian value at a byte offset.1
i8i8(bytes, int) -> intReads a 8-bit signed value at a byte offset.1
i16bei16be(bytes, int) -> intReads a 16-bit signed big-endian value at a byte offset.1
i16lei16le(bytes, int) -> intReads a 16-bit signed little-endian value at a byte offset.1
i24bei24be(bytes, int) -> intReads a 24-bit signed big-endian value at a byte offset.1
i24lei24le(bytes, int) -> intReads a 24-bit signed little-endian value at a byte offset.1
i32bei32be(bytes, int) -> intReads a 32-bit signed big-endian value at a byte offset.1
i32lei32le(bytes, int) -> intReads a 32-bit signed little-endian value at a byte offset.1

Floating point​

FunctionSignatureWhat it doesCost
f32bef32be(bytes, int) -> doubleReads an IEEE-754 32-bit big-endian float at a byte offset; a non-finite value is an error.1
f32lef32le(bytes, int) -> doubleReads an IEEE-754 32-bit little-endian float at a byte offset; a non-finite value is an error.1
f64bef64be(bytes, int) -> doubleReads an IEEE-754 64-bit big-endian float at a byte offset; a non-finite value is an error.1
f64lef64le(bytes, int) -> doubleReads an IEEE-754 64-bit little-endian float at a byte offset; a non-finite value is an error.1

Bits​

FunctionSignatureWhat it doesCost
bitbit(bytes, int, int) -> intReads one bit (0 or 1): bit 0 is the least significant bit of the byte at byteOff.1
bitsbits(bytes, int, int, int) -> intReads an unsigned bit field of width 1..32 starting at bitOff, counted from the least significant bit of the byte at byteOff and continuing into the following bytes.1
sbitssbits(bytes, int, int, int) -> intLike bits, sign-extended from the top bit of the field.1

Binary-coded decimal​

FunctionSignatureWhat it doesCost
bcdbcd(bytes, int, int) -> intReads len (1 to 8) bytes of packed binary-coded decimal, most significant digit first; a nibble above 9 is an error.1 per byte read (the len argument)

Bytes​

FunctionSignatureWhat it doesCost
sliceslice(bytes, int, int) -> bytesCopies len bytes starting at off; a range outside the value is an error.1 per byte copied, at least 1

Text frames​

FunctionSignatureWhat it doesCost
hex.decodehex.decode(string) -> bytesDecodes hexadecimal text (even length, no separators) of at most 8192 bytes.1 per byte of the text, at least 1
base64.decodebase64.decode(string) -> bytesDecodes standard padded base64 text into at most 4096 bytes. The text itself may be at most 5467 bytes, line breaks included, so base64 split across many lines can be refused even when it would decode to 4096 bytes or fewer.1 per byte of the text, at least 1

Codecs​

FunctionSignatureWhat it doesCost
lpp.decodelpp.decode(bytes) -> map(string, double)Decodes a Cayenne LPP frame into channel-suffixed keys such as temperature_1; a truncated or unknown record is an error.1 per byte of the frame, at least 1

Maths​

FunctionSignatureWhat it doesCost
math.absmath.abs(double|int) -> double|intAbsolute value.1
math.floormath.floor(double) -> doubleLargest integral value not above the argument.1
math.ceilmath.ceil(double) -> doubleSmallest integral value not below the argument.1
math.roundmath.round(double) -> doubleRounds half away from zero.1
math.sqrtmath.sqrt(double|int) -> doubleSquare root; a negative argument is an error.1
math.powmath.pow(double|int, int) -> doubleInteger power by repeated multiplication.1
math.minmath.min(a, b) -> double|intThe smaller of two numbers.1
math.maxmath.max(a, b) -> double|intThe larger of two numbers.1
math.clampmath.clamp(x, lo, hi) -> double|intx limited to [lo, hi]; lo above hi is an error.1

Limits​

A decoder that is over a limit is refused when you save or publish it. An input over an input limit fails that one decode.

LimitValue
Raw frame, in bytes4,096
JSON input (json or decoded), in bytes65,536
JSON nesting depth32
The whole decoder document, in bytes32,768
One expression, in bytes2,048
let bindings16
Sections8
Readings one section can emit (scalar rows plus the maxKeys of map rows)64
Saved vectors20
Text given to hex.decode or base64.decode, in bytes8,192
Literals in one in list16
A let, section or vector name, in bytes64
An output key or prefix, in bytes128
Estimated cost of one expression10,000
Estimated cost of a whole decoder50,000