Saltar al contenido principal
Versión: Next

Referencia de funciones del decodificador

Las funciones de la biblioteca de los decodificadores de payload y los límites a los que está sujeto un decodificador. Esta página se genera a partir de la biblioteca de funciones de la plataforma, así que no puede quedarse atrás. No se enumeran las funciones incorporadas del propio lenguaje: size, has y las conversiones int, uint, double y bool.

Funciones​

Un decodificador indica en envVersion la versión de la biblioteca para la que se escribió; esta página describe la versión 1. Lo que hace una función no cambia nunca una vez publicada: una corrección o una variante llega con un nombre nuevo en una versión nueva, de modo que un decodificador guardado sigue dando las mismas respuestas. Las descripciones son el texto de la propia biblioteca y están en inglés en todos los idiomas. Coste es lo que añade la propia llamada, en unidades de coste; cada nombre, literal, operador y conversión de una expresión añade además aproximadamente 1. Una función que recibe bytes los lee de frame o de otra función que devuelve bytes.

Enteros​

FunciónFirmaQué haceCoste
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

Coma flotante​

FunciónFirmaQué haceCoste
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​

FunciónFirmaQué haceCoste
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

Decimal codificado en binario​

FunciónFirmaQué haceCoste
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​

FunciónFirmaQué haceCoste
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

Tramas de texto​

FunciónFirmaQué haceCoste
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

Códecs​

FunciónFirmaQué haceCoste
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

Matemáticas​

FunciónFirmaQué haceCoste
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

Límites​

Un decodificador que supera un límite se rechaza al guardarlo o publicarlo. Una entrada que supera un límite de entrada hace fallar esa decodificación.

LímiteValor
Trama sin procesar, en bytes4,096
Entrada JSON (json o decoded), en bytes65,536
Profundidad de anidamiento del JSON32
El documento completo del decodificador, en bytes32,768
Una expresión, en bytes2,048
Enlaces let16
Secciones8
Lecturas que puede emitir una sección (filas escalares más el maxKeys de las filas de mapa)64
Vectores guardados20
Texto que recibe hex.decode o base64.decode, en bytes8,192
Literales en una lista in16
Nombre de un let, sección o vector, en bytes64
Una clave de salida o un prefijo, en bytes128
Coste estimado de una expresión10,000
Coste estimado de un decodificador completo50,000