Class DefaultEncoderFactory

java.lang.Object
com.lucimber.dbus.codec.encoder.DefaultEncoderFactory
All Implemented Interfaces:
EncoderFactory

public final class DefaultEncoderFactory extends Object implements EncoderFactory
Default implementation of EncoderFactory that provides encoders for all standard D-Bus types.

This factory uses a registry-based approach to create encoders, making it easy to extend with new types and improving performance by avoiding switch statements.

  • Constructor Details

    • DefaultEncoderFactory

      public DefaultEncoderFactory()
      Creates a new DefaultEncoderFactory with all standard D-Bus encoders registered.
  • Method Details

    • createEncoder

      public Encoder<DBusType,ByteBuffer> createEncoder(Type type, ByteOrder order) throws EncoderException
      Description copied from interface: EncoderFactory
      Creates an encoder for the specified D-Bus type.
      Specified by:
      createEncoder in interface EncoderFactory
      Parameters:
      type - the D-Bus type to encode
      order - the byte order to use for encoding
      Returns:
      an encoder capable of encoding the specified type
      Throws:
      EncoderException - if no encoder is available for the type
    • canEncode

      public boolean canEncode(Type type)
      Description copied from interface: EncoderFactory
      Checks if an encoder is available for the specified type.
      Specified by:
      canEncode in interface EncoderFactory
      Parameters:
      type - the D-Bus type to check
      Returns:
      true if an encoder is available, false otherwise
    • registerEncoder

      public void registerEncoder(Type type, DefaultEncoderFactory.EncoderCreator creator)
      Registers a custom encoder creator for a specific type.
      Parameters:
      type - the D-Bus type
      creator - the encoder creator function