跳到主要内容
版本:开发版

解码器函数参考

载荷解码器函数库中的函数,以及解码器所受的限制。本页由平台中的函数库自动生成,因此不会落后于实现。语言自身的内置函数不在此列:size、has,以及转换函数 int、uint、double 和 bool。

函数​

解码器在 envVersion 中写明它所针对的函数库版本;本页描述的是版本 1。函数一旦发布,其行为就不会再改变:修复或变体会以新名称出现在新版本中,因此已保存的解码器始终给出相同的结果。说明文字是函数库自带的文本,在所有语言中均为英文。成本是调用本身增加的成本,单位为成本单位;表达式中的每个名称、字面量、运算符和类型转换还各增加约 1。接受 bytes 的函数从 frame 或另一个返回字节的函数读取字节。

整数​

函数签名作用成本
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

浮点数​

函数签名作用成本
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

位​

函数签名作用成本
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

二进制编码十进制​

函数签名作用成本
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)

字节​

函数签名作用成本
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

文本帧​

函数签名作用成本
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 of at most 8192 bytes into at most 4096 bytes.1 per byte of the text, at least 1

编解码器​

函数签名作用成本
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

数学​

函数签名作用成本
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

限制​

超出限制的解码器在保存或发布时会被拒绝。超出输入限制的输入只会使这一次解码失败。

限制取值
原始帧,单位为字节4,096
JSON 输入(json 或 decoded),单位为字节65,536
JSON 嵌套深度32
整个解码器文档,单位为字节32,768
单个表达式,单位为字节2,048
let 绑定16
分段8
单个分段可输出的读数(标量行加上映射行的 maxKeys)64
已保存的测试向量20
传给 hex.decode 或 base64.decode 的文本,单位为字节8,192
单个 in 列表中的字面量16
let、分段或测试向量的名称,单位为字节64
输出键或前缀,单位为字节128
单个表达式的估算成本10,000
整个解码器的估算成本50,000