Class HeaderFieldExtractor

java.lang.Object
com.lucimber.dbus.util.HeaderFieldExtractor

public final class HeaderFieldExtractor extends Object
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 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 fields
      field - the header field to extract
      expectedType - 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 fields
      field - the header field to extract
      expectedType - 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 fields
      field - 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 fields
      field - the header field to extract
      Returns:
      the string value
      Throws:
      io.netty.handler.codec.CorruptedFrameException - if the field is missing or not a string