Package com.lucimber.dbus.codec.encoder
Class DefaultEncoderFactory
java.lang.Object
com.lucimber.dbus.codec.encoder.DefaultEncoderFactory
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Functional interface for creating encoders with a given byte order. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DefaultEncoderFactory with all standard D-Bus encoders registered. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if an encoder is available for the specified type.createEncoder
(Type type, ByteOrder order) Creates an encoder for the specified D-Bus type.void
registerEncoder
(Type type, DefaultEncoderFactory.EncoderCreator creator) Registers a custom encoder creator for a specific type.
-
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 interfaceEncoderFactory
- Parameters:
type
- the D-Bus type to encodeorder
- 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
Description copied from interface:EncoderFactory
Checks if an encoder is available for the specified type.- Specified by:
canEncode
in interfaceEncoderFactory
- Parameters:
type
- the D-Bus type to check- Returns:
- true if an encoder is available, false otherwise
-
registerEncoder
Registers a custom encoder creator for a specific type.- Parameters:
type
- the D-Bus typecreator
- the encoder creator function
-