Class EnvelopeCodec

java.lang.Object
com.iantapply.relay.core.EnvelopeCodec

public final class EnvelopeCodec extends Object
Encodes, decodes, and validates Relay's JSON wire envelope.
  • Field Details

    • MAXIMUM_HEADERS

      public static final int MAXIMUM_HEADERS
      Maximum number of application headers accepted in one envelope.
      See Also:
    • MAXIMUM_HEADER_KEY_LENGTH

      public static final int MAXIMUM_HEADER_KEY_LENGTH
      Maximum length of an application header name.
      See Also:
    • MAXIMUM_HEADER_VALUE_LENGTH

      public static final int MAXIMUM_HEADER_VALUE_LENGTH
      Maximum length of an application header value.
      See Also:
  • Constructor Details

    • EnvelopeCodec

      public EnvelopeCodec(int maximumPayloadBytes, Duration maximumAge)
      Creates an envelope codec with inbound and outbound limits.
      Parameters:
      maximumPayloadBytes - largest accepted decoded payload
      maximumAge - maximum accepted message age, or zero to disable age checks
  • Method Details

    • encode

      public byte[] encode(WireEnvelope envelope)
      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

      public WireEnvelope decode(byte[] encoded, Instant now)
      Deserializes and validates an envelope relative to the supplied clock value.
      Parameters:
      encoded - UTF-8 JSON envelope
      now - reference time used for age validation
      Returns:
      decoded envelope
      Throws:
      IllegalArgumentException - if the input is malformed or violates the wire contract