Class DecoderUtils

java.lang.Object
com.lucimber.dbus.codec.decoder.DecoderUtils

public final class DecoderUtils extends Object
Utility methods used by the ByteBuffer-based implementations of the decoders.
  • Method Details

    • skipPadding

      public static int skipPadding(ByteBuffer buffer, int offset, Type type)
      Skips alignment padding bytes in the buffer for the given type.
      Parameters:
      buffer - the ByteBuffer to advance
      offset - the current byte offset
      type - the D-Bus type requiring alignment
      Returns:
      the number of padding bytes skipped
    • calculateAlignmentPadding

      public static int calculateAlignmentPadding(Type type, int byteCount)
      Calculates the number of padding bytes needed for proper alignment.
      Parameters:
      type - the D-Bus type requiring alignment
      byteCount - the current byte count/offset
      Returns:
      the number of padding bytes needed
    • verifyArrayLength

      public static void verifyArrayLength(DBusUInt32 length)
      Verifies that an array length is within D-Bus limits.
      Parameters:
      length - the array length to verify
      Throws:
      DecoderException - if the length exceeds maximum allowed
    • decode

      public static <R extends DBusType> DecoderResult<R> decode(DBusSignature signature, ByteBuffer buffer, int offset) throws DecoderException
      Decodes D-Bus data types from a buffer.
      Type Parameters:
      R - expected data type
      Parameters:
      signature - signature of the expected data type
      buffer - buffer containing the expected data type
      offset - offset inside the buffer
      Returns:
      decoded data type
      Throws:
      DecoderException - If the expected data type could not be decoded from the buffer.
    • decodeContainerType

      public static <R extends DBusContainerType> DecoderResult<R> decodeContainerType(DBusSignature signature, ByteBuffer buffer, int offset) throws DecoderException
      Decodes a D-Bus container type from the buffer.
      Type Parameters:
      R - expected container type
      Parameters:
      signature - signature of the container type
      buffer - buffer containing the data
      offset - offset inside the buffer
      Returns:
      decoded container type
      Throws:
      DecoderException - if decoding fails
    • decodeBasicType

      public static <R extends DBusBasicType> DecoderResult<R> decodeBasicType(TypeCode code, ByteBuffer buffer, int offset) throws DecoderException
      Decodes a D-Bus basic type from the buffer.
      Type Parameters:
      R - expected basic type
      Parameters:
      code - the type code of the basic type
      buffer - buffer containing the data
      offset - offset inside the buffer
      Returns:
      decoded basic type
      Throws:
      DecoderException - if decoding fails