Package com.lucimber.dbus.codec.decoder
Class DecoderUtils
java.lang.Object
com.lucimber.dbus.codec.decoder.DecoderUtils
Utility methods used by the ByteBuffer-based implementations of the decoders.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
calculateAlignmentPadding
(Type type, int byteCount) Calculates the number of padding bytes needed for proper alignment.static <R extends DBusType>
DecoderResult<R>decode
(DBusSignature signature, ByteBuffer buffer, int offset) Decodes D-Bus data types from a buffer.static <R extends DBusBasicType>
DecoderResult<R>decodeBasicType
(TypeCode code, ByteBuffer buffer, int offset) Decodes a D-Bus basic type from the buffer.static <R extends DBusContainerType>
DecoderResult<R>decodeContainerType
(DBusSignature signature, ByteBuffer buffer, int offset) Decodes a D-Bus container type from the buffer.static int
skipPadding
(ByteBuffer buffer, int offset, Type type) Skips alignment padding bytes in the buffer for the given type.static void
verifyArrayLength
(DBusUInt32 length) Verifies that an array length is within D-Bus limits.
-
Method Details
-
skipPadding
Skips alignment padding bytes in the buffer for the given type.- Parameters:
buffer
- the ByteBuffer to advanceoffset
- the current byte offsettype
- the D-Bus type requiring alignment- Returns:
- the number of padding bytes skipped
-
calculateAlignmentPadding
Calculates the number of padding bytes needed for proper alignment.- Parameters:
type
- the D-Bus type requiring alignmentbyteCount
- the current byte count/offset- Returns:
- the number of padding bytes needed
-
verifyArrayLength
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 typebuffer
- buffer containing the expected data typeoffset
- 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 typebuffer
- buffer containing the dataoffset
- 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 typebuffer
- buffer containing the dataoffset
- offset inside the buffer- Returns:
- decoded basic type
- Throws:
DecoderException
- if decoding fails
-