Package com.lucimber.dbus.util
Class HeaderFieldExtractor
java.lang.Object
com.lucimber.dbus.util.HeaderFieldExtractor
Utility class for extracting typed values from D-Bus message header fields. This class provides a
generic way to extract and validate header field values, eliminating code duplication in message
decoders.
-
Method Summary
Modifier and TypeMethodDescriptionextractOptional
(Map<HeaderField, DBusVariant> headerFields, HeaderField field, Class<T> expectedType) Extracts an optional header field value of the specified type.extractOptionalString
(Map<HeaderField, DBusVariant> headerFields, HeaderField field) Extracts an optional string header field value.static <T extends DBusType>
TextractRequired
(Map<HeaderField, DBusVariant> headerFields, HeaderField field, Class<T> expectedType) Extracts a required header field value of the specified type.static String
extractRequiredString
(Map<HeaderField, DBusVariant> headerFields, HeaderField field) Extracts a required string header field value.
-
Method Details
-
extractOptional
public static <T extends DBusType> Optional<T> extractOptional(Map<HeaderField, DBusVariant> headerFields, HeaderField field, Class<T> expectedType) Extracts an optional header field value of the specified type.- Type Parameters:
T
- the expected D-Bus type- Parameters:
headerFields
- the map of header fieldsfield
- the header field to extractexpectedType
- the expected type class- Returns:
- an Optional containing the value if present and of correct type
- Throws:
io.netty.handler.codec.CorruptedFrameException
- if the field is present but of wrong type
-
extractRequired
public static <T extends DBusType> T extractRequired(Map<HeaderField, DBusVariant> headerFields, HeaderField field, Class<T> expectedType) Extracts a required header field value of the specified type.- Type Parameters:
T
- the expected D-Bus type- Parameters:
headerFields
- the map of header fieldsfield
- the header field to extractexpectedType
- the expected type class- Returns:
- the value if present and of correct type
- Throws:
io.netty.handler.codec.CorruptedFrameException
- if the field is missing or of wrong type
-
extractOptionalString
public static Optional<String> extractOptionalString(Map<HeaderField, DBusVariant> headerFields, HeaderField field) Extracts an optional string header field value.- Parameters:
headerFields
- the map of header fieldsfield
- the header field to extract- Returns:
- an Optional containing the string value if present
- Throws:
io.netty.handler.codec.CorruptedFrameException
- if the field is present but not a string
-
extractRequiredString
public static String extractRequiredString(Map<HeaderField, DBusVariant> headerFields, HeaderField field) Extracts a required string header field value.- Parameters:
headerFields
- the map of header fieldsfield
- the header field to extract- Returns:
- the string value
- Throws:
io.netty.handler.codec.CorruptedFrameException
- if the field is missing or not a string
-