pdcomm::SecsItem
Class
Owned, immutable SECS-II data item (SEMI E5 section 9).
class SecsItemA SecsItem is either a list of child items or a primitive value in one of the SECS-II formats (PDCOMM_SECS_ASCII, PDCOMM_SECS_BINARY, PDCOMM_SECS_U4, and so on). Primitive payloads are the raw wire bytes: numeric values are big-endian, and ASCII bytes must be 0 to 127. Each item stores the PdcommSecsLimits it was created with and uses them again for children and encoding.
Items are values, not views: every factory and getter returns an independent copy, so releasing a parent never invalidates a child, and items returned by GEM results stay valid after the result and endpoint are gone.
const std::vector<uint8_t> temperature = {0x41, 0xac, 0, 0}; // F4 21.5
auto value = pdcomm::SecsItem::primitive(PDCOMM_SECS_F4, temperature, limits);
auto lot = pdcomm::SecsItem::primitive(
PDCOMM_SECS_ASCII, std::vector<uint8_t>{'L', 'O', 'T', '-', '0', '0', '1'}, limits);
auto pair = pdcomm::SecsItem::list({&value, &lot}, limits);
std::vector<uint8_t> wire = pair.bytes(); // encoded L[2] F4 ANotes
- Move-only RAII wrapper over
PdcommSecsItem. A default-constructed or moved-from item is empty; test it withoperator bool. Read-only calls (info(), child(), bytes(), payload()) may run concurrently on one item, but destruction must not race with them.
Members
SecsItem
Constructor
Creates an empty item that owns no native handle.
SecsItem() noexcept = defaultUse an empty item to mean "no value", for example when a GEM result has no body.
SecsItem
Constructor
Takes ownership of the native handle owned by other.
SecsItem(SecsItem &&other) noexceptParameters
| Name | Description |
|---|---|
other | Source wrapper; it becomes empty. |
SecsItem
Constructor
Copying is disabled; the wrapper exclusively owns its native handle.
SecsItem(const SecsItem &) = deleteadopt
Method
Wraps a native item handle and takes ownership of it.
static SecsItem adopt(PdcommSecsItem *handle) noexceptUse this to manage a handle returned by a C function such as pdcomm_secs_decode().
Parameters
| Name | Description |
|---|---|
handle | Live handle to own, or nullptr for an empty item. It must not be owned or destroyed by anything else afterwards. |
Returns
A wrapper that destroys handle when it goes out of scope.
bytes
Method
Encodes the item into SECS-II wire format.
std::vector<uint8_t> bytes() constItem headers use the minimal length-byte count; primitive payload bytes are kept as is.
Returns
The complete encoded item.
Notes
- Throws
pdcomm::Error:PDCOMM_INVALID_ARGUMENTwhen the item is empty.
child
Method
Returns a copy of one child of a list item.
SecsItem child(size_t index) constParameters
| Name | Description |
|---|---|
index | Zero-based child position. |
Returns
An independent copy of the child; releasing this list does not affect it.
Notes
- Throws
pdcomm::Error:PDCOMM_INVALID_ARGUMENTwhen the item is empty or is not a list;PDCOMM_OUT_OF_RANGEwhenindexis not less than the child count.
decode
Method
Decodes exactly one encoded SECS-II item from a vector.
static SecsItem decode(const std::vector<uint8_t> &data, const PdcommSecsLimits &limits, size_t *errorOffset = nullptr)Parameters
| Name | Description |
|---|---|
data | Encoded item bytes. |
limits | Limits the decoded tree must satisfy; they are stored in the item. |
errorOffset | Optional output that receives the failing field offset. |
Returns
The decoded item.
Notes
- Throws
pdcomm::Error: Same statuses as the pointer-and-length overload of decode().
decode
Method
Decodes exactly one encoded SECS-II item.
static SecsItem decode(const uint8_t *data, size_t length, const PdcommSecsLimits &limits, size_t *errorOffset = nullptr)The input must hold one complete item with no trailing bytes. The decoded values are copied, so data can be released after the call.
Parameters
| Name | Description |
|---|---|
data | Encoded item bytes. |
length | Number of bytes at data. |
limits | Limits the decoded tree must satisfy; they are stored in the item. |
errorOffset | Optional output. On a decode failure it receives the offset of the start of the field that failed, not of the first missing byte. |
Returns
The decoded item.
Notes
- Throws
pdcomm::Error:PDCOMM_TRUNCATEDwhen the input ends early (includingnullptrwith length 0);PDCOMM_INVALID_DATAfor malformed headers, widths, non-ASCII text or trailing data;PDCOMM_LIMIT_EXCEEDEDwhenlimitsare exceeded;PDCOMM_INVALID_ARGUMENTfor invalid pointers or a too-smalllimits.struct_size.
info
Method
Describes the item's format and size.
PdcommSecsInfo info() constReturns
A PdcommSecsInfo with format (a PDCOMM_SECS_* code), count (children for a list, elements for a primitive), encoded_length, node_count and depth.
Notes
- Throws
pdcomm::Error:PDCOMM_INVALID_ARGUMENTwhen the item is empty.
list
Method
Creates a list item that contains copies of children.
static SecsItem list(const std::vector<const SecsItem *> &children, const PdcommSecsLimits &limits)The children are copied after the aggregate size, item count and depth are checked against limits. The caller keeps ownership of the original items.
Parameters
| Name | Description |
|---|---|
children | Items to copy, in order. An empty vector creates an empty list. Every pointer must refer to a non-empty item. |
limits | Limits for the whole new tree; they are stored in the item. |
Returns
The new list item.
Notes
- Throws
pdcomm::Error:PDCOMM_INVALID_ARGUMENTfor anullptror empty child;PDCOMM_LIMIT_EXCEEDEDwhen the tree exceedslimits.
list
Method
Creates a list item that contains copies of children.
static SecsItem list(std::initializer_list<const SecsItem *> children, const PdcommSecsLimits &limits)Parameters
| Name | Description |
|---|---|
children | Items to copy, in order. Every pointer must refer to a non-empty item. |
limits | Limits for the whole new tree; they are stored in the item. |
Returns
The new list item.
Notes
- Throws
pdcomm::Error: Same statuses as the vector overload of list().
nativeHandle
Method
Returns the owned native handle for direct C API calls.
PdcommSecsItem *nativeHandle() noexceptReturns
The handle, or nullptr for an empty item. Ownership stays with this wrapper.
nativeHandle
Method
Returns the owned native handle for read-only C API calls.
const PdcommSecsItem *nativeHandle() const noexceptReturns
The handle, or nullptr for an empty item. Ownership stays with this wrapper.
operator bool
Method
Reports whether the wrapper owns a native item.
explicit operator bool() const noexceptReturns
true when an item is owned; false for an empty or moved-from item.
operator=
Method
Releases the current handle, then takes ownership of the handle owned by other.
SecsItem &operator=(SecsItem &&other) noexceptParameters
| Name | Description |
|---|---|
other | Source wrapper; it becomes empty. |
Returns
This wrapper.
operator=
Method
Copy assignment is disabled; the wrapper exclusively owns its native handle.
SecsItem &operator=(const SecsItem &) = deletepayload
Method
Copies the raw payload bytes of a primitive item.
std::vector<uint8_t> payload() constReturns
The payload in wire order; empty for an empty primitive value.
Notes
- Throws
pdcomm::Error:PDCOMM_INVALID_ARGUMENTwhen the item is empty or is a list, because lists have no primitive payload.
primitive
Method
Creates a primitive item from a payload vector.
static SecsItem primitive(uint8_t format, const std::vector<uint8_t> &data, const PdcommSecsLimits &limits)Parameters
| Name | Description |
|---|---|
format | SECS-II format code; PDCOMM_SECS_LIST is rejected. |
data | Payload in wire order (big-endian for numbers); may be empty. |
limits | Limits for the item; they are stored in the item. |
Returns
The new item.
Notes
- Throws
pdcomm::Error: Same statuses as the pointer-and-length overload of primitive().
primitive
Method
Creates a primitive item from raw payload bytes.
static SecsItem primitive(uint8_t format, const uint8_t *data, size_t length, const PdcommSecsLimits &limits)Parameters
| Name | Description |
|---|---|
format | SECS-II format code such as PDCOMM_SECS_U4 or PDCOMM_SECS_ASCII. PDCOMM_SECS_LIST is rejected; use list() instead. |
data | Payload in wire order (big-endian for numbers). May be nullptr when length is 0, which creates an empty value. |
length | Payload size in bytes. It must be a multiple of the format's element width. |
limits | Limits for the item; they are stored in the item. |
Returns
The new item.
Notes
- Throws
pdcomm::Error:PDCOMM_INVALID_ARGUMENTfor an unknown or list format;PDCOMM_INVALID_DATAfor a length that is not a multiple of the element width or for ASCII bytes above 127;PDCOMM_LIMIT_EXCEEDEDwhenlimitsare exceeded.
~SecsItem
Method
Releases the native handle with pdcomm_secs_destroy().
~SecsItem()An empty item releases nothing.