Class WireCodec

java.lang.Object
io.axoniq.framework.springcloud.shared.WireCodec

@Internal public final class WireCodec extends Object
The encoding members share when writing a failure to each other, whatever kind of message it answers.

Commands and queries travel over different endpoints with different shapes, but a failure is described the same way in both. Keeping that here means the two directions cannot drift apart into encodings that no longer read each other.

Marked Internal because it is public only so that the command and query converters, which live in separate packages, can share it. It is not meant to be used outside this module.

Since:
5.4.0
Author:
Allard Buijze
  • Method Details

    • encode

      public static @Nullable String encode(byte @Nullable [] bytes)
      Encodes the given bytes for transport, as null when there is nothing to carry.
      Parameters:
      bytes - the bytes to encode
      Returns:
      the encoded form of the given bytes, or null when there are none
    • decode

      public static byte @Nullable [] decode(@Nullable String encoded)
      Decodes what encode(byte[]) wrote.
      Parameters:
      encoded - the encoded bytes, or null when none were carried
      Returns:
      the bytes the given encoded form represents, or null when it is null
    • messageOf

      public static String messageOf(Throwable cause)
      Describes the given cause, falling back to its type when it carries no message.
      Parameters:
      cause - the failure to describe
      Returns:
      a description of the given cause
    • descriptionsOf

      public static List<String> descriptionsOf(Throwable cause)
      Describes the given cause and the causes behind it, outermost first.

      The chain is followed to a bounded depth, so that a cycle or a pathologically deep chain cannot turn a failure into an unbounded reply.

      Parameters:
      cause - the failure to describe
      Returns:
      descriptions of the given cause and the causes behind it
    • convertedDetailsOf

      public static byte @Nullable [] convertedDetailsOf(Throwable cause, @Nullable Converter converter)
      Returns the application-specific details the given cause carries, as the bytes to write.

      Details that cannot be converted are omitted rather than raised: a failure that cannot be described in full is still worth reporting, and replacing it with a conversion failure would hide what actually went wrong.

      Parameters:
      cause - the failure whose details to write
      converter - the converter to write the details with, or null when none is available
      Returns:
      the bytes to write for the given cause's details, or null when it carries none that can be written