Class ObjectStrategyComplexTypeStrategy<T>

  • All Implemented Interfaces:
    Comparator<Object>, TypeStrategy<T>

    public class ObjectStrategyComplexTypeStrategy<T>
    extends Object
    implements TypeStrategy<T>
    Default implementation of TypeStrategy for all ComplexMetricSerde implementations that just wraps the ObjectStrategy they are required to implement. This is not likely to be the most efficient way to do things, especially since writing must first produce a byte array before it can be written to the buffer, but it is cheap and should work correctly, which is important.
    • Constructor Detail

      • ObjectStrategyComplexTypeStrategy

        public ObjectStrategyComplexTypeStrategy​(ObjectStrategy<T> objectStrategy,
                                                 TypeSignature<?> signature)
    • Method Detail

      • estimateSizeBytes

        public int estimateSizeBytes​(@Nullable
                                     T value)
        Description copied from interface: TypeStrategy
        Estimate the size in bytes that writing this value to memory would require. This method is not required to be exactly correct, but many implementations might be. Implementations should err on the side of over-estimating if exact sizing is not efficient. Example usage of this method is estimating heap memory usage for an aggregator or the amount of buffer which might need allocated to then TypeStrategy.write(java.nio.ByteBuffer, T, int) a value
        Specified by:
        estimateSizeBytes in interface TypeStrategy<T>
      • write

        public int write​(ByteBuffer buffer,
                         T value,
                         int maxSizeBytes)
        Description copied from interface: TypeStrategy
        Write a non-null value to the ByteBuffer at position Buffer.position(). This will move the underlying position by the size of the value written. This method returns the number of bytes written. If writing the value would take more than 'maxSizeBytes', this method will return a negative value indicating the number of additional bytes that would be required to fully write the value. Partial results may be written to the buffer when in this state, and the position may be left at whatever point the implementation ran out of space while writing the value. Callers should save the starting position if it is necessary to 'rewind' after a partial write. Callers MUST check that the return value is positive which indicates a successful write, while a negative response a partial write.
        Specified by:
        write in interface TypeStrategy<T>
        Returns:
        number of bytes written
      • fromBytes

        public T fromBytes​(byte[] value)
        Description copied from interface: TypeStrategy
        Translate raw byte array into a value. This is primarily useful for transforming self contained values that are serialized into byte arrays, such as happens with 'COMPLEX' types which serialize to base64 strings in JSON responses. 'COMPLEX' types should implement this method to participate in the expression systems built-in function to deserialize base64 encoded values, BuiltInExprMacros.ComplexDecodeBase64ExprMacro.
        Specified by:
        fromBytes in interface TypeStrategy<T>