Kwasm.format.binary.value
package kwasm.format.binary.value
Methods
readFloat
fun BinaryParser.readFloat(): Float
Receiver
Name | Description |
---|---|
BinaryParser
|
ReturnValue
Name | Description |
---|---|
Float
|
readDouble
fun BinaryParser.readDouble(): Double
Receiver
Name | Description |
---|---|
BinaryParser
|
ReturnValue
Name | Description |
---|---|
Double
|
readUInt
fun BinaryParser.readUInt(): Int
From the docs:
All integers are encoded using the LEB128 variable-length integer encoding, in either unsigned or signed variant.
Unsigned integers are encoded in unsigned LEB128 format. As an additional constraint, the total number of bytes encoding a value of type uN must not exceed ceil(N/7) bytes.
uN ::= n:byte => n (if n < 2^7 and n < 2^N)
n:byte m:u(N−7) => 2^7 * m + (n - 2^7) (if n >= 2^7 and N > 7)
Signed integers are encoded in signed LEB128 format, which uses a two’s complement
representation. As an additional constraint, the total number of bytes encoding a value of type
sN
must not exceed ceil(N/7)
bytes.
sN ::= n:byte => n (if n<26 and n < 2^(N−1))
n:byte => n - 2^7 (if 26 <= n < 27 and n >= 2^7 - 2^(N−1))
n:byte m:s(N−7) => 2^7 * m + (n - 2^7) (if n >= 27 and N > 7)
Uninterpreted integers are encoded as signed integers.
iN ::= n:sN => i (if n = signed_iN(i))
**Note**
The side conditions `N > 7` in the productions for non-terminal bytes of the `u` and `s`
encodings restrict the encoding’s length. However, “trailing zeros” are still allowed within
these bounds. For example, `0x03` and `0x83 0x00` are both well-formed encodings for the value
`3` as a u8. Similarly, either of `0x7e` and `0xFE 0x7F` and `0xFE 0xFF 0x7F` are well-formed
encodings of the value `−2` as a `s16`.
The side conditions on the value `n` of terminal bytes further enforce that any unused bits in
these bytes must be `0` for positive values and 1 for negative ones. For example, `0x83 0x10` is
malformed as a `u8` encoding. Similarly, both `0x83 0x3E` and `0xFF 0x7B` are malformed as s8
encodings.
Receiver
Name | Description |
---|---|
BinaryParser
|
ReturnValue
Name | Description |
---|---|
Int
|
readInt
fun BinaryParser.readInt(): Int
See BinaryParser.readUInt.
Receiver
Name | Description |
---|---|
BinaryParser
|
ReturnValue
Name | Description |
---|---|
Int
|
readULong
fun BinaryParser.readULong(): Long
See BinaryParser.readUInt.
Receiver
Name | Description |
---|---|
BinaryParser
|
ReturnValue
Name | Description |
---|---|
Long
|
readLong
fun BinaryParser.readLong(): Long
See BinaryParser.readUInt.
Receiver
Name | Description |
---|---|
BinaryParser
|
ReturnValue
Name | Description |
---|---|
Long
|
readName
fun BinaryParser.readName(): String
From the docs:
Names are encoded as a vector of bytes containing the Unicode (Section 3.9) UTF-8 encoding of the name’s character sequence.
name ::= b∗:vec(byte) => name (if utf8(name)=b∗)
Receiver
Name | Description |
---|---|
BinaryParser
|
ReturnValue
Name | Description |
---|---|
String
|
readVector
fun BinaryParser.readVector(): List<Byte>
From the docs:
Vectors are encoded with their u32 length followed by the encoding of their element sequence.
vec(B) ::= n:u32 (x:B)n => x^n
Receiver
Name | Description |
---|---|
BinaryParser
|
ReturnValue
Name | Description |
---|---|
List<Byte>
|
readVector
fun <T> BinaryParser.readVector(block: BinaryParser.()->T): List<T>
From the docs:
Vectors are encoded with their u32 length followed by the encoding of their element sequence.
vec(B) ::= n:u32 (x:B)n => x^n
Receiver
Name | Description |
---|---|
BinaryParser
|
Parameters
Name | Description |
---|---|
block: BinaryParser.()->T
|
ReturnValue
Name | Description |
---|---|
List<T>
|
From the docs:
Floating-point values are encoded directly by their IEEE 754-2019 (Section 3.4) bit pattern in little endian byte order: