Package io.bytestreams.codec.core
Class DataObject
java.lang.Object
io.bytestreams.codec.core.DataObject
- Direct Known Subclasses:
SimpleData
Abstract map-backed data object for use with sequential codecs.
Fields are stored by string key in insertion order. Access is protected — subclasses control which fields are exposed and whether they are mutable.
Use field(String, Codec) to create FieldSpec instances that provide type-safe
access and integrate with SequentialObjectCodec.Builder.
For open access with no restrictions, use SimpleData. For typed, controlled access,
subclass directly:
class Message extends DataObject {
static final FieldSpec<Message, Integer> ID = field("id", Codecs.uint16());
public int getId() { return get(ID); }
// no setter — read-only to consumers, codec can still set via FieldSpec
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic <T extends DataObject,V>
FieldSpec<T, V> Creates a FieldSpec backed by the object's internal map.static <T extends DataObject,V>
FieldSpec<T, V> Creates a FieldSpec backed by the object's internal map with a presence predicate.protected <V> Vget(FieldSpec<? extends DataObject, V> spec) Gets a field value using a FieldSpec.protected <V> VinthashCode()protected <V> voidset(FieldSpec<? extends DataObject, V> spec, V value) Sets a field value using a FieldSpec.protected voidtoString()
-
Constructor Details
-
DataObject
public DataObject()
-
-
Method Details
-
get
-
set
-
get
Gets a field value using a FieldSpec. Delegates toFieldSpec.get(Object). -
set
Sets a field value using a FieldSpec. Delegates toFieldSpec.set(Object, Object). -
field
Creates a FieldSpec backed by the object's internal map.- Type Parameters:
T- the DataObject subclass typeV- the field value type- Parameters:
name- the field name (used as map key)codec- the codec for the field value- Returns:
- a new FieldSpec
-
field
public static <T extends DataObject,V> FieldSpec<T,V> field(String name, Codec<V> codec, Predicate<T> presence) Creates a FieldSpec backed by the object's internal map with a presence predicate.- Type Parameters:
T- the DataObject subclass typeV- the field value type- Parameters:
name- the field name (used as map key)codec- the codec for the field valuepresence- predicate to determine if field is present- Returns:
- a new FieldSpec
-
equals
-
hashCode
public int hashCode() -
toString
-