pdcomm_secs_decode
Function
Decodes exactly one SECS-II item from encoded bytes.
PdcommStatus pdcomm_secs_decode(const uint8_t *data, size_t length, const PdcommSecsLimits *options, PdcommSecsItem **out, size_t *error_offset)The input is validated against options before any tree allocation and then copied, so the new item does not reference data. Item headers may use more length bytes than necessary; pdcomm_secs_encode() always writes minimal headers.
Parameters
| Name | Description |
|---|---|
data | Encoded item. May be NULL only when length is 0, which reports #PDCOMM_TRUNCATED. |
length | Number of bytes at data. Every byte must belong to the single item. |
options | Limits to enforce; struct_size must be at least sizeof(PdcommSecsLimits). |
out | Receives the new item. Set to NULL first, so it is NULL after every failure. |
error_offset | Optional. Set to 0 at the start; on a decode error it receives the byte offset of the start of the field that failed, not of the first missing byte. May be NULL. |
Returns
#PDCOMM_OK on success; #PDCOMM_INVALID_ARGUMENT when out or options is NULL, options->struct_size is too small, or data is NULL with a nonzero length; #PDCOMM_TRUNCATED when the input ends inside the item; #PDCOMM_INVALID_DATA when the encoding is malformed or bytes follow the item; #PDCOMM_LIMIT_EXCEEDED when a limit in options is exceeded; #PDCOMM_ALLOCATION_FAILED or #PDCOMM_INTERNAL_ERROR.
Notes
- Ownership: release the item with pdcomm_secs_destroy().
outanderror_offsetmust not overlap each other,data, oroptions.