protocol.fields

Read, write, and manipulate field data.

Reader functions take [buf start ctx] and return [end value-or-values] where end is the offset in buf after the read value(s).

Writer functions take [buf value-or-values start ctx] and return end where end is the offset in buf after the written value(s).

int->hex

(int->hex i)

Convert integer i into hex string representation

int->octet

(int->octet n cnt)

Convert integer n into cnt octets/bytes (in MSB first order)

list->lookup

(list->lookup coll & idxs)

Takes columnar collection and one or more k-idx v-idx pairs and returns a map contructed from key/value pairs selected from k-idx/v-idx columns of coll. If v-idx does not exist for a given row then the value defaults to nil.

octet->int

(octet->int octets)

Convert sequence of octets/bytes octets (in MSB first order) into an integer

read-bitfield

(read-bitfield buf start {:keys [path length spec le?], :as ctx})

Read length bytes from buf starting at start and return a map of bitfields based on those bytes and the bitfield spec. The bitfield spec is a sequence [name type bits] entries where name is the bitfield key name, type can be either :int or :bool (for integer and boolean bitfield respectively), and bits is the number of bits to decode for that bitfield.

read-choice

(read-choice buf start {:keys [msg-map readers path choice-path choices], :as ctx})

Read using a reader and context that is selected based on a previously read value. The choice-path vector is looked up in msg-map (using get-in) to get a choice key. The choice key is looked up in choices to get a choice context map. The choice map must contain a :choice-type that specifies the selected reader. Any other entries in the choice context map are merged into the new context for that reader.

read-lookup

(read-lookup buf start {:keys [readers path lookup-type lookup], :as ctx})

Read lookup-type type from buf at start and lookup that key in lookup to get the value to return

read-loop

(read-loop buf start {:keys [readers path loop-type length], :as ctx})

Read a sequence of loop-type elements from buf starting at start. Elements will be read until either length is reached, the end of the buffer is reached, or the loop-type reader returns a three-tuple [end value stop?] with a truthy stop? value.

read-repeat

(read-repeat buf start {:keys [readers path length repeat-type repeat-size], :as ctx})

Read a sequence of repeat-type elements from buf starting at start. The number of elements read is length / repeat-size

readers-BE

Field readers (big endian)

readers-LE

Field readers (little endian)

write-bitfield

(write-bitfield buf bf-map start {:keys [spec path le?], :as ctx})

Write the bitfield values from bf-map into buf starting at start and based on the bitfield spec. The bitfield spec is a sequence [name type bits] entries where name is the bitfield key in bf-map, type can be either :int or :bool (for integer and boolean bitfield respectively), and bits is the number of bits to encode for that bitfield.

write-choice

(write-choice buf value start {:keys [msg-map writers path choice-path choices], :as ctx})

Write using a writer and context that is selected based on another value in msg-map. The choice-path vector is looked up in msg-map (using get-in) to get a choice key. The choice key is looked up in choices to get a choice context map. The choice map must contain a :choice-type that specifies the selected writer. Any other entries in the choice context map are merged into the new context for that writer.

write-lookup

(write-lookup buf k start {:keys [writers path lookup-type lookup], :as ctx})

Lookup k in lookup and write it as a lookup-type type into buf at start

write-loop

(write-loop buf values start {:keys [writers path loop-type], :as ctx})

Write a sequence of loop-type elements into buf starting at start. All elements in values will be written to the buffer.

write-repeat

(write-repeat buf values start {:keys [writers path repeat-type repeat-size], :as ctx})

Write a sequence of repeat-type elements (of size repeat-size) into buf starting at start

writers-BE

Field writers (big endian)

writers-LE

Field writers (little endian)