T - The type of the object to be marshalled/unmarshalled.public class WireMarshaller<T> extends Object
| Modifier and Type | Field and Description |
|---|---|
static net.openhft.chronicle.core.util.ClassLocal<WireMarshaller> |
WIRE_MARSHALLER_CL |
| Modifier | Constructor and Description |
|---|---|
protected |
WireMarshaller(@NotNull Class<T> tClass,
@NotNull net.openhft.chronicle.wire.WireMarshaller.FieldAccess[] fields,
boolean isLeaf)
Constructs a new instance of the WireMarshaller with the specified parameters.
|
| Modifier and Type | Method and Description |
|---|---|
T |
defaultValue()
Returns the default value of type T.
|
WireMarshaller<T> |
excludeFields(String... fieldNames)
Excludes specified fields from the current marshaller and returns a new instance of the marshaller
with the remaining fields.
|
static void |
getAllField(@NotNull Class<?> clazz,
@NotNull Map<String,Field> map)
Recursively fetches all non-static, non-transient fields from the provided class and its superclasses,
up to but not including Object or AbstractCommonMarshallable, and adds them to the provided map.
|
Object |
getField(Object o,
String name)
Fetches the value of the specified field from the provided object.
|
long |
getLongField(@NotNull Object o,
String name)
Retrieves the value of a specified field from the provided object and converts it to a long.
|
boolean |
isEqual(Object o1,
Object o2)
Compares two objects field by field to determine their equality.
|
boolean |
isLeaf()
Checks if the current WireMarshaller is a leaf.
|
protected static boolean |
leafable(net.openhft.chronicle.wire.WireMarshaller.FieldAccess c)
Checks if the provided field accessor corresponds to a "leaf" entity.
|
boolean |
matchesFieldName(StringBuilder sb,
net.openhft.chronicle.wire.WireMarshaller.FieldAccess field)
Checks if the given field name (represented by a StringBuilder) matches the field name of the provided
FieldAccess. |
static <T> @NotNull WireMarshaller<T> |
of(@NotNull Class<T> tClass)
Factory method to create an instance of the WireMarshaller for a specific class type.
|
void |
readMarshallable(T t,
@NotNull WireIn in,
boolean overwrite)
Reads and populates the DTO based on the provided input.
|
void |
readMarshallableDTOOrder(T t,
@NotNull WireIn in,
boolean overwrite)
Reads and populates the DTO based on the provided order.
|
void |
readMarshallableInputOrder(T t,
@NotNull WireIn in,
boolean overwrite)
Reads and populates the DTO based on the input's order.
|
void |
reset(T o)
Resets the fields of the given object 'o' to the default value.
|
void |
setField(Object o,
String name,
Object value)
Sets the value of a specified field in the provided object.
|
void |
setLongField(Object o,
String name,
long value)
Sets a long value to a specified field in the provided object.
|
void |
writeKey(T t,
net.openhft.chronicle.bytes.Bytes<?> bytes)
Writes the key representation of the given object to the provided
Bytes destination. |
void |
writeMarshallable(T t,
net.openhft.chronicle.bytes.Bytes<?> bytes)
Writes the marshallable representation of the given object to the provided
Bytes destination. |
void |
writeMarshallable(T t,
@NotNull WireOut out)
Writes the marshallable representation of the given object to the provided
WireOut destination. |
void |
writeMarshallable(T t,
@NotNull WireOut out,
boolean copy)
Writes the values of the fields from the provided object (DTO) to the output.
|
public static final net.openhft.chronicle.core.util.ClassLocal<WireMarshaller> WIRE_MARSHALLER_CL
protected WireMarshaller(@NotNull
@NotNull Class<T> tClass,
@NotNull
@NotNull net.openhft.chronicle.wire.WireMarshaller.FieldAccess[] fields,
boolean isLeaf)
tClass - The class of the object to be marshalled.fields - An array of field accessors that provide access to the fields of the object.isLeaf - Indicates if the marshaller is for a leaf class.@NotNull public static <T> @NotNull WireMarshaller<T> of(@NotNull @NotNull Class<T> tClass)
tClass - The class type for which the marshaller is to be created.protected static boolean leafable(net.openhft.chronicle.wire.WireMarshaller.FieldAccess c)
c - The field accessor to be checked.true if the field accessor is leafable, false otherwise.public static void getAllField(@NotNull
@NotNull Class<?> clazz,
@NotNull
@NotNull Map<String,Field> map)
clazz - The class type from which fields are to be extracted.map - The map to populate with field names and their corresponding Field objects.public WireMarshaller<T> excludeFields(String... fieldNames)
fieldNames - Names of the fields to be excluded.WireMarshaller with the specified fields excluded.public void writeMarshallable(T t, @NotNull @NotNull WireOut out) throws net.openhft.chronicle.core.io.InvalidMarshallableException
WireOut destination.
This will traverse the fields and use their respective FieldAccess to write each field.
The method also adjusts the hex dump indentation for better readability in the output.t - The object to write.out - The destination WireOut where the object representation will be written.net.openhft.chronicle.core.io.InvalidMarshallableException - If the object fails validation checks before serialization.public void writeMarshallable(T t, net.openhft.chronicle.bytes.Bytes<?> bytes)
Bytes destination.
Unlike the previous method, this doesn't adjust the hex dump indentation. It's a more direct
serialization of the fields to bytes.t - The object to write.bytes - The destination Bytes where the object representation will be written.public void writeMarshallable(T t, @NotNull @NotNull WireOut out, boolean copy) throws net.openhft.chronicle.core.io.InvalidMarshallableException
t - Object whose field values are to be written.out - Output destination where the field values are written to.copy - Flag indicating whether to copy values from the source object to the previous object.net.openhft.chronicle.core.io.InvalidMarshallableException - If there's an error during marshalling.public void readMarshallable(T t, @NotNull @NotNull WireIn in, boolean overwrite) throws net.openhft.chronicle.core.io.InvalidMarshallableException
t - Object to populate with read values.in - Input source from which values are read.overwrite - Flag indicating whether to overwrite the existing value in the target object.net.openhft.chronicle.core.io.InvalidMarshallableException - If there is an error during marshalling.public void readMarshallableDTOOrder(T t, @NotNull @NotNull WireIn in, boolean overwrite) throws net.openhft.chronicle.core.io.InvalidMarshallableException
t - Target object to populate with read values.in - Input source from which values are read.overwrite - Flag indicating whether to overwrite the existing value in the target object.net.openhft.chronicle.core.io.InvalidMarshallableException - If there is an error during marshalling.public void readMarshallableInputOrder(T t, @NotNull @NotNull WireIn in, boolean overwrite) throws net.openhft.chronicle.core.io.InvalidMarshallableException
t - Target object to populate with read values.in - Input source from which values are read.overwrite - Flag indicating whether to overwrite the existing value in the target object.net.openhft.chronicle.core.io.InvalidMarshallableException - If there is an error during marshalling.public boolean matchesFieldName(StringBuilder sb, net.openhft.chronicle.wire.WireMarshaller.FieldAccess field)
FieldAccess.
If the StringBuilder has a length of 0, it's assumed to match any field name.sb - The StringBuilder containing the field name to be checked.field - The FieldAccess whose field name needs to be matched against.public void writeKey(T t, net.openhft.chronicle.bytes.Bytes<?> bytes)
Bytes destination.
As per the assumption, only the first field (key) of the object is written.t - The object whose key needs to be written.bytes - The destination Bytes where the object's key representation will be written.public boolean isEqual(Object o1, Object o2)
FieldAccess to perform the equality check.o1 - The first object to compare.o2 - The second object to compare.public Object getField(Object o, String name) throws NoSuchFieldException
o - The object from which the field value needs to be fetched.name - The name of the field whose value is to be fetched.NoSuchFieldException - If no field with the specified name is found in the object.public long getLongField(@NotNull
@NotNull Object o,
String name)
throws NoSuchFieldException
o - The object from which the field value is to be retrieved.name - The name of the field whose value needs to be fetched.NoSuchFieldException - If no field with the specified name is found in the object.public void setField(Object o, String name, Object value) throws NoSuchFieldException
o - The object in which the field's value needs to be set.name - The name of the field whose value needs to be set.value - The value to set to the field.NoSuchFieldException - If no field with the specified name is found in the object.public void setLongField(Object o, String name, long value) throws NoSuchFieldException
o - The object in which the field's value needs to be set.name - The name of the field whose value needs to be set.value - The long value to set to the field.NoSuchFieldException - If no field with the specified name is found in the object.@Nullable public T defaultValue()
public void reset(T o)
o - The object whose fields are to be reset to the default value.public boolean isLeaf()
Copyright © 2024. All rights reserved.