BinaryFormat.Record
BinaryReturns a binary format that reads a record from binary data.
Syntax
BinaryFormat.Record(record as record) as functionParameters
| Name | Type | Required | Description |
|---|---|---|---|
record | record | Yes | A record where each field specifies a binary format for reading that field's value. Fields with non-format values are echoed as-is without reading data. |
Return Value
function — A binary format function that reads fields sequentially from binary data and returns them as a record.
Remarks
BinaryFormat.Record returns a binary format that reads a record with named fields from binary data. The record parameter defines the structure: each field name maps to a binary format specifier that determines how to read that field's data from the stream.
Fields are read in the order they appear in the record definition, and each binary format reads consecutive bytes from the stream. If a field's value is not a binary format function (e.g., a constant number or text), no data is read for that field, and the value is passed through directly to the result record.
This is one of the most important composite binary format functions, as it enables you to define structured layouts for parsing binary file headers, network packets, and other binary data with named fields.
Examples
Example 1: Read a record with 16-bit and 32-bit integers
let
binaryData = #binary({
0x00, 0x01,
0x00, 0x00, 0x00, 0x02
}),
recordFormat = BinaryFormat.Record([
A = BinaryFormat.UnsignedInteger16,
B = BinaryFormat.UnsignedInteger32
])
in
recordFormat(binaryData)Example 2: Include a constant field in the record
let
binaryData = #binary({0x2A}),
recordFormat = BinaryFormat.Record([
Version = 1,
Value = BinaryFormat.Byte
])
in
recordFormat(binaryData)