Class Sofab
sofab) core.
These mirror the normative limits in the SofaBuffers architecture guide
(§6.2). API_VERSION lets callers and the schema-driven code generator
verify compatibility at build or run time.
invalid(String) is here too, and is not a constant: it is the one
way a Visitor — that is, generated code — reports malformed input, and
belongs beside the contract it is part of.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSofaBuffers core API version.static final longLargest array element count / fixed-length byte count,2^31 - 1(INT32_MAX).static final intLargest valid field id,2^31 - 1(INT32_MAX).static final intMaximum nested-sequence depth (§4.9 / §6.2).static final intSmallest output buffer this port accepts for streaming (CORELIB_PLAN §5.1). -
Method Summary
Modifier and TypeMethodDescriptionstatic UncheckedIOExceptionThe carrier a defect in the call is refused through: aSofabError.ARGUMENTSofabException, wrapped likeinvalid(String)so it can leave a callback that declares no checked exception.static UncheckedIOExceptionThe carrier aVisitorrejects malformed input through: anSofabError.INVALID_MSGSofabException, wrapped so it can leave a callback that declares no checked exception.static UncheckedIOExceptionlimitExceeded(String detail) The carrier a receiver-side limit (§6.2.1) is refused through: aSofabError.LIMIT_EXCEEDEDSofabException, wrapped likeinvalid(String)so it can leave a callback that declares no checked exception.
-
Field Details
-
API_VERSION
public static final int API_VERSIONSofaBuffers core API version. Callers and the generator check this for compatibility; the current contract is version1.This tracks the wire contract — normative and identical in every port (CORELIB_PLAN §6.2) — so it moves only when the bytes on the wire change meaning. It is not this library's source-compatibility version: a release that renames or removes a Java method bumps the artifact version in
pom.xmland leavesAPI_VERSIONalone.- See Also:
-
ID_MAX
public static final int ID_MAXLargest valid field id,2^31 - 1(INT32_MAX).- See Also:
-
ARRAY_MAX
public static final long ARRAY_MAXLargest array element count / fixed-length byte count,2^31 - 1(INT32_MAX).- See Also:
-
MIN_OUTPUT_BUFFER
public static final int MIN_OUTPUT_BUFFERSmallest output buffer this port accepts for streaming (CORELIB_PLAN §5.1). It is1: the encoder splits every atomic unit, so no write has to land contiguously and a single usable byte is enough.It binds a buffer installed with a
FlushSink— at construction and at every mid-streamOStream.bufferSet(byte[], int), both of which rejectbuffer.length - offset < MIN_OUTPUT_BUFFERwithIllegalArgumentExceptionwhere the buffer is handed over, never partway through a message. A buffer installed without a sink is subject to no minimum: no flush can occur there, so a caller sizing from the generatedMAX_SIZEkeeps an exact fit.Any size at or above this produces output byte-identical to the one-shot path, so sizing a streaming buffer from this constant trades nothing but flush frequency.
- See Also:
-
MAX_DEPTH
public static final int MAX_DEPTHMaximum nested-sequence depth (§4.9 / §6.2). An encoder must not open more thanMAX_DEPTHnested sequences, and a decoder rejects a message that nests deeper withSofabError.INVALID_MSG, bounding recursion / stack growth.- See Also:
-
-
Method Details
-
invalid
The carrier aVisitorrejects malformed input through: anSofabError.INVALID_MSGSofabException, wrapped so it can leave a callback that declares no checked exception.Every
Visitormethod is declaredthrows-free, because a visitor is called from the middle of the decoder's state machine and most implementations have nothing to report. Generated code does: MESSAGE_SPEC §7 puts the schema bounds — a length above amaxlen, a count above a declared capacity, an index above one, a value outside a declared width, a string that is not UTF-8 — on the side that knows the schema, which is the visitor and not this library. So the rejection travels as an unchecked wrapper, andIStream.feed(byte[], Visitor)recognizes it on the way out: anINVALID_MSGraised by a visitor latches the decode exactly as one raised by the decoder itself does, so it is terminal: every laterIStream.feed(byte[], Visitor)re-throws it and none returns a status (CORELIB_PLAN §5.2). The wrapper itself reaches the caller unchanged; theSofabExceptionis itscause.That makes it a two-sided contract, and this is the side that names it. Throw the result rather than calling it for effect —
throw Sofab.invalid(...)ends the method as far as the compiler is concerned:if (total > 8) { throw Sofab.invalid("name: string length above schema maxlen 8"); }SofabError.LIMIT_EXCEEDED— a receiver-side policy rejection of well-formed bytes (§6.2.1) — is deliberately not this: it travels throughlimitExceeded(String)instead, and is latched under its own code.The wrapper only carries the rejection across the
Visitorinterface:IStream.feed(byte[], Visitor)unwraps it, so the decode's caller catches theSofabExceptionfeeddeclares, as it does for the decoder's own rejections. The same holds forlimitExceeded(String)andargument(String).- Parameters:
detail- human-readable context, naming the field and the bound it broke- Returns:
- the exception to throw
-
limitExceeded
The carrier a receiver-side limit (§6.2.1) is refused through: aSofabError.LIMIT_EXCEEDEDSofabException, wrapped likeinvalid(String)so it can leave a callback that declares no checked exception.It is the twin of
invalid(String)and deliberately not the same thing.INVALID_MSGsays these bytes are broken;LIMIT_EXCEEDEDsays these bytes are fine and this receiver declines to hold that much, so the same message decodes under a looser limit. Both are terminal (§6.3: "a terminal, receiver-local policy rejection") andIStream.feed(byte[], Visitor)latches both, so the decode ends there and every later call repeats the rejection untilIStream.reset(); what keeps them apart is the code they keep — a limit rejection is never reported asINVALID_MSG(§6.3), and is never clamped or truncated into a shortened value.Raised from two places, and only where a cap was actually supplied:
PayloadAcc.string(int, int, byte[], int, int, Bound)/PayloadAcc.blob(int, int, byte[], int, int, Bound)at a payload's announced length, and theSeqrow reservations at a wrapper array's element index. Both take the number as an argument, inside theBoundthat says which of §6.2.1's two rules governs the field.- Parameters:
detail- human-readable context, naming the value and the limit it broke- Returns:
- the exception to throw
-
argument
The carrier a defect in the call is refused through: aSofabError.ARGUMENTSofabException, wrapped likeinvalid(String)so it can leave a callback that declares no checked exception.It is what §6.3 calls
InvalidArgument, and it is deliberately neither of the other two.INVALID_MSGwould mark a well-formed message malformed;LIMIT_EXCEEDEDwould "promise a limit to raise that was never configured" (§6.3). The mistake is in the call, not in the bytes and not in the deployment.Raised where a
Boundthe caller had to state is missing — anullwhere a bound belonged, or the numberlessBound.SCHEMA_BOUNDEDhanded to a call that bounds an array index. §6.2.1 forbids reading an omitted argument as unlimited, so an omission is reported rather than obeyed.- Parameters:
detail- human-readable context, naming what the call failed to state- Returns:
- the exception to throw
-