Class SimpleTypeSerializer<T>
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.structure.io.binary.types.SimpleTypeSerializer<T>
-
- All Implemented Interfaces:
TypeSerializer<T>
- Direct Known Subclasses:
BigDecimalSerializer,BigIntegerSerializer,BindingSerializer,BulkSetSerializer,ByteBufferSerializer,ByteCodeSerializer,CharSerializer,ClassSerializer,DateSerializer,DurationSerializer,EdgeSerializer,EnumSerializer,GraphSerializer,InetAddressSerializer,InstantSerializer,LambdaSerializer,ListSerializer,LocalDateSerializer,LocalDateTimeSerializer,LocalTimeSerializer,MapEntrySerializer,MapSerializer,MetricsSerializer,MonthDaySerializer,OffsetDateTimeSerializer,OffsetTimeSerializer,PathSerializer,PeriodSerializer,PropertySerializer,PSerializer,SetSerializer,SingleTypeSerializer,StringSerializer,TraversalExplanationSerializer,TraversalMetricsSerializer,TraversalStrategySerializer,TraverserSerializer,TreeSerializer,UUIDSerializer,VertexPropertySerializer,VertexSerializer,YearMonthSerializer,ZonedDateTimeSerializer,ZoneOffsetSerializer
public abstract class SimpleTypeSerializer<T> extends Object implements TypeSerializer<T>
Base class for serialization of types that don't contain type specific information only {type_code}, {value_flag} and {value}.
-
-
Constructor Summary
Constructors Constructor Description SimpleTypeSerializer(DataType dataType)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static intcappedInitialCapacity(int size)Caps the initial capacity used to pre-size a growable container (ArrayList,HashMap) from a validated wire count.DataTypegetDataType()Gets theDataTypethat is represented by the givenTypeSerializer.Tread(Buffer buffer, GraphBinaryReader context)Reads the type information and value from the buffer and returns an instance of T.protected static intreadSizePrefix(Buffer buffer)Reads a length or element-count prefix and validates it before it is used to size an allocation.protected abstract TreadValue(Buffer buffer, GraphBinaryReader context)Reads a non-nullable value according to the type format.TreadValue(Buffer buffer, GraphBinaryReader context, boolean nullable)Reads the value from the buffer (not the type information) and returns an instance of T.voidwrite(T value, Buffer buffer, GraphBinaryWriter context)Writes the type code, information and value to a buffer using the provided allocator.protected abstract voidwriteValue(T value, Buffer buffer, GraphBinaryWriter context)Writes a non-nullable value into a buffer using the provided allocator.voidwriteValue(T value, Buffer buffer, GraphBinaryWriter context, boolean nullable)Writes the value to a buffer, composed by the value flag and the sequence of bytes.
-
-
-
Constructor Detail
-
SimpleTypeSerializer
public SimpleTypeSerializer(DataType dataType)
-
-
Method Detail
-
getDataType
public DataType getDataType()
Description copied from interface:TypeSerializerGets theDataTypethat is represented by the givenTypeSerializer.- Specified by:
getDataTypein interfaceTypeSerializer<T>
-
read
public T read(Buffer buffer, GraphBinaryReader context) throws IOException
Description copied from interface:TypeSerializerReads the type information and value from the buffer and returns an instance of T.- Specified by:
readin interfaceTypeSerializer<T>- Throws:
IOException
-
readValue
public T readValue(Buffer buffer, GraphBinaryReader context, boolean nullable) throws IOException
Description copied from interface:TypeSerializerReads the value from the buffer (not the type information) and returns an instance of T.Implementors should throw an exception when a complex type doesn't support reading without the type information.
- Specified by:
readValuein interfaceTypeSerializer<T>- Throws:
IOException
-
readValue
protected abstract T readValue(Buffer buffer, GraphBinaryReader context) throws IOException
Reads a non-nullable value according to the type format.- Parameters:
buffer- A buffer which reader index has been set to the beginning of the {value}.context- The binary reader.- Returns:
- Throws:
IOException
-
readSizePrefix
protected static int readSizePrefix(Buffer buffer) throws IOException
Reads a length or element-count prefix and validates it before it is used to size an allocation. The same check serves both kinds of prefix: a byte length, where each counted unit is one wire byte, and an element count, where each counted element occupies at least one wire byte. A negative value, or one larger than the number of bytes actually remaining in the buffer, therefore cannot be legitimate, so it is rejected rather than allowed to drive a large allocation from a small message.- Throws:
IOException
-
cappedInitialCapacity
protected static int cappedInitialCapacity(int size)
Caps the initial capacity used to pre-size a growable container (ArrayList,HashMap) from a validated wire count. Safe to use only for containers that grow on demand, never for a fixed-size array or a byte buffer that must hold exactlysizeentries.
-
write
public void write(T value, Buffer buffer, GraphBinaryWriter context) throws IOException
Description copied from interface:TypeSerializerWrites the type code, information and value to a buffer using the provided allocator.- Specified by:
writein interfaceTypeSerializer<T>- Throws:
IOException
-
writeValue
public void writeValue(T value, Buffer buffer, GraphBinaryWriter context, boolean nullable) throws IOException
Description copied from interface:TypeSerializerWrites the value to a buffer, composed by the value flag and the sequence of bytes.- Specified by:
writeValuein interfaceTypeSerializer<T>- Throws:
IOException
-
writeValue
protected abstract void writeValue(T value, Buffer buffer, GraphBinaryWriter context) throws IOException
Writes a non-nullable value into a buffer using the provided allocator.- Parameters:
value- A non-nullable value.buffer- The buffer allocator to use.context- The binary writer.- Throws:
IOException
-
-