PEEK …int-type… [[BIG | LITTLE] ENDIAN] …string…
PEEK …int-type… [[BIG | LITTLE] ENDIAN] …int_vector…
STRING -> int?
int1[] -> int2
Either read some bytes from a string into an integer, or convert a vector of small unsigned integers into a large integer. Can come handy when receiving arrays of integers from external systems that have no better ways to encode large integers.
The endianness can be specified, and little-endian is the default.
If the destination type is actually narrower than required then the result is merely truncated. But if the destination type is wider than the number of provided bytes then the result will be NULL.
The result is not nullable only when reading from a non nullable vector of non nullable integers.
Some integer widths are not yet implemented.
expression | evaluates to |
---|---|
PEEK U32 LITTLE ENDIAN "\002\001\000\000" | 258 |
PEEK U32 LITTLE ENDIAN "\002\001" | NULL |
PEEK I16 BIG ENDIAN "\002\001" | 513 |
PEEK U8 "\004\003\002\001" | 4 |
PEEK U32 LITTLE ENDIAN [0xC0u8; 0xA8u8; 0x00u8; 0x01u8] | 16820416 |
PEEK U32 BIG ENDIAN CAST([0xC0; 0xA8; 0x00; 0x01] AS U8[4]) | 3232235521 |