Enum Class SofabError

java.lang.Object
java.lang.Enum<SofabError>
org.sofabuffers.sofab.SofabError
All Implemented Interfaces:
Serializable, Comparable<SofabError>, Constable

public enum SofabError extends Enum<SofabError>
Error categories raised by the encoder and decoder.

Mirrors the C sofab_ret_t status codes (minus OK, which the Java API models as a normal return), plus LIMIT_EXCEEDED, a receiver-side policy category that has no wire-format equivalent (analogous to corelib-go's ErrLimitExceeded sentinel). Every SofabException carries one of these so callers can branch on the cause without string matching.

  • Enum Constant Details

    • ARGUMENT

      public static final SofabError ARGUMENT
      Invalid caller argument (e.g. a field id outside 0..ID_MAX).
    • BUFFER_FULL

      public static final SofabError BUFFER_FULL
      The output buffer is full and no FlushSink is available.
    • INVALID_MSG

      public static final SofabError INVALID_MSG
      The input bytes are not a valid Sofab message (varint overflow, bad type tag, zero-length array, dangling sequence end, ...).

      This is a statement about the wire bytes: they are malformed regardless of what follows or how the receiver is configured. It is deliberately distinct from LIMIT_EXCEEDED, which is a policy decision about otherwise-well-formed bytes.

    • LIMIT_EXCEEDED

      public static final SofabError LIMIT_EXCEEDED
      A well-formed message field exceeds a receiver-configured decode limit for an unbounded (dynamic) field — one whose schema declares no count/maxlen. The limits (max_dyn_array_count, max_dyn_string_len, max_dyn_blob_len) are configured in the sofabgen config and baked into generated code as constants (CORELIB_PLAN §6.2.1: "The numbers and the allocation are not the codec's").

      Where the comparison runs. §6.2.1 leaves that open — "A corelib MAY take a limit as an argument and perform the check itself" — and this library takes it on the calls generated code already makes at the length or index the limit guards: PayloadAcc.string(int, int, byte[], int, int, Bound) / PayloadAcc.blob(int, int, byte[], int, int, Bound), and the Seq row reservations. Each is raised through Sofab.limitExceeded(String). What has no such call — a native array count, the element index of a flat wrapper array — is still guarded by generated code on the count the visitor is handed (arrayBegin(id, kind, count), string/blob(id, total, offset, chunk)), before it allocates. Never both for one rule: §6.2.1 admits one implementation per check.

      Not wire malformation. Exceeding a receiver-configured limit is policy, not a property of the bytes: the same message is accepted by a backend with a higher (or no) limit. This category is therefore kept strictly distinct from INVALID_MSG so that policy divergence between backends with different configured limits is not mistaken for a wire-conformance divergence (e.g. by the Crucible differential fuzzer).

      Always a hard error. A limit violation is never clamped and never truncated; it is raised before the allocation it prevents, and IStream.feed(byte[], Visitor) latches it as it latches INVALID_MSG — §6.3 makes it terminal too — but under this code: the exception a refused decode throws carries LIMIT_EXCEEDED, never INVALID_MSG, which is how §6.3's "MUST NOT be reported as InvalidMessage" is met. §6.3 offers two ways to surface it, "either a fourth decode outcome, or a terminal failure carrying the LimitExceeded code on the error channel"; this library takes the second, so there is no fourth DecodeStatus and no second place the refusal can be read.

      This corelib defines no limit and no default for one. It holds no max_dyn_* value, supplies none to a caller who states none, and never presents a format ceiling (Sofab.ARRAY_MAX, Sofab.ID_MAX) as a receiver cap — breaching one of those is INVALID_MSG. A number it is handed is used for that one comparison and not retained (§6.2.1).

  • Method Details

    • values

      public static SofabError[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SofabError valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null