endSequence method

void endSequence()

Closes the current sequence, letting it vanish if it received no content; otherwise the single byte 0x07 (CORELIB_PLAN §4.9).

Use it wherever absence encodes the same value as an empty frame: a struct/union field, and an array field whose declared default is the empty collection (MESSAGE_SPEC §2). Where the frame must be visible, close with endSequenceKeep instead.

An end with no matching begin is not rejected: the encoder writes what it is told, and the resulting bytes are then malformed, which is the decoder's verdict to make. Every other port behaves this way; the depth counter stops at zero so the MAX_DEPTH check on begin cannot be fooled by an underflow.

Implementation

void endSequence() {
  if (_nPendingSeq != 0) {
    // The innermost open sequence is the last held-back one and it got no
    // content: drop it — header and end marker both.
    _nPendingSeq--;
    if (_depth > 0) _depth--;
    return;
  }
  _writeByte(0x07);
  if (_depth > 0) _depth--;
}