EncodePacket (open)

Encode a binary packet

Syntax

LOADLIB "wh::system.whlib";

STRING FUNCTION EncodePacket(STRING format, RECORD data)

Parameters

STRING format

Formatting string: field1:<type> [ repeatcounter | ? | * ],field2:<type> [ repeatcounter | ? | * ]

The following types are accepted:

Type Description
x Add 'count' NUL bytes, count defaults to 1. If '?', add as much NUL bytes as specified in the cell
b Signed 64bit long (little endian order, 64-bit)
B Unsigned 64bit long (little endian order, 64-bit)
c Signed character (8 bit)
C Unsigned character (8 bit)
d Signed long long (big endian order, 64-bit)
D Unsigned long long (big endian order, 64-bit)
s Signed short (little endian order, 16-bit)
S Unsigned short (little endian order, 16-bit)
l Signed long (little endian order, 32-bit)
L Unsigned long (little endian order, 32-bit)
b Signed long long (little endian order, 64-bit)
B Unsigned long long (little endian order, 64-bit)
n Signed short (big endian order/network byte order, 16-bit)
N Unsigned short (big endian order/network byte order, 16-bit)
p Signed long (big endian order/network byte order, 32-bit)
P Unsigned long (big endian order/network byte order, 32-bit)
d Signed 64bit long (big endian order, 64-bit)
D Unsigned 64bit long (big endian order, 64-bit)
a NUL-padded string (padded up to specified counter). If '*', simply print string and NUL-terminate
A ASCII-padded string (paddedup to specified counter). If '*', simply print string and space-terminate
r Raw data - inserts a string. If a counter is specified, adds at most that many bytes of the string, if '*', add all data.
f Float (little endian order, 32-bit)
F Double (little endian order, 64-bit)
g Float (big endian order, 32-bit)
G Double (big endian order, 64-bit)
h Datetime (little endian order, 2x32-bit). First day, then mseconds
i Datetime (big endian order, 2x32-bit). First day, then mseconds
j Boolean (8-bit)
@@ Jump to absolute position in packet encoder. Truncate or pad with zeroes if necessary. }
RECORD data

Data to encode

Return value

STRING

The encoded packet, or an empty string if encoding failed.