Class EnvelopeCodec
java.lang.Object
com.iantapply.relay.core.EnvelopeCodec
Encodes, decodes, and validates Relay's JSON wire envelope.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum length of an application header name.static final intMaximum length of an application header value.static final intMaximum number of application headers accepted in one envelope. -
Constructor Summary
ConstructorsConstructorDescriptionEnvelopeCodec(int maximumPayloadBytes, Duration maximumAge) Creates an envelope codec with inbound and outbound limits. -
Method Summary
Modifier and TypeMethodDescriptionDeserializes and validates an envelope relative to the supplied clock value.byte[]encode(WireEnvelope envelope) Validates and serializes an envelope as UTF-8 JSON.
-
Field Details
-
MAXIMUM_HEADERS
public static final int MAXIMUM_HEADERSMaximum number of application headers accepted in one envelope.- See Also:
-
MAXIMUM_HEADER_KEY_LENGTH
public static final int MAXIMUM_HEADER_KEY_LENGTHMaximum length of an application header name.- See Also:
-
MAXIMUM_HEADER_VALUE_LENGTH
public static final int MAXIMUM_HEADER_VALUE_LENGTHMaximum length of an application header value.- See Also:
-
-
Constructor Details
-
EnvelopeCodec
Creates an envelope codec with inbound and outbound limits.- Parameters:
maximumPayloadBytes- largest accepted decoded payloadmaximumAge- maximum accepted message age, or zero to disable age checks
-
-
Method Details
-
encode
Validates and serializes an envelope as UTF-8 JSON.- Parameters:
envelope- envelope to encode- Returns:
- encoded wire payload
- Throws:
IllegalArgumentException- if the envelope violates the wire contract
-
decode
Deserializes and validates an envelope relative to the supplied clock value.- Parameters:
encoded- UTF-8 JSON envelopenow- reference time used for age validation- Returns:
- decoded envelope
- Throws:
IllegalArgumentException- if the input is malformed or violates the wire contract
-