varlen 3plumb 2012-09-09

NAME

varlen - split up input stream in variable length records by header

SYNPOSIS

[varlen size=NUM offs=NUM len_delta=NUM]

[varlen size=NUM offs=NUM len_delta=NUM order=BYTEORDER maxlen=NUM]

               +--------+
0 (stdin) ---->| varlen |----> (stdout) 1
               +--------+
                   |
                   V
            (stderr)
                   2

DESCRIPTION

Varlen reads the input of variable size records, reads the header of each record to determine record length and splits up the stream into records. Record length field must be an integer present in the header. Offset of the field is described in the offs argument (in bytes from the beginning of the record) and size (in bytes) of the field in the size argument. Supported sizes are 1, 2, 3 and 4. To compensate for the size field and the header/footer of the record, the user may specify a len_delta, which will be added to the length decoded from the record. Size of the length field is _not_ added.

Byte order of the size field is assumed to be MSB (network byte order) unless the user explicitly specifies it to be "LSB" or "MSB" using the order argument.

To avoid allocating large amount of memory and/or crashes because of mangled record headers, a record with negative size or size larger than maxlen is an error. On error a message is printed to stderr and varlen quits.

eof handling

Default.

blocking/flow control

Default.

buffering

Buffers one partial record, size depending on the length field of the record.

EXAMPLE

The following example assumes the binary output of caputre is a stream of records with a header that tells the record type in 4 bytes then the size of the payload in 2 bytes, all in network byte order. After splitting the stream to records, they are each converted to text and sent to a script.
	{capture} | [varlen offs=4 size=2] | [dump format=hex] | [affix suffix="\n"] | {awk -f proc.awk}

SEE ALSO

varlen 3plumb 2012-09-09