org.fudgemsg.types
Class SecondaryFieldTypeBase<SecondaryType,ConversionType,PrimitiveType extends ConversionType>

java.lang.Object
  extended by org.fudgemsg.FudgeFieldType<SecondaryType>
      extended by org.fudgemsg.types.SecondaryFieldTypeBase<SecondaryType,ConversionType,PrimitiveType>
Type Parameters:
SecondaryType - secondary type
PrimitiveType - type there is a primary FudgeFieldType for
ConversionType - base type to support mappings from, e.g. use Object to convert from any of the Fudge primitives
All Implemented Interfaces:
Serializable, FudgeTypeConverter<ConversionType,SecondaryType>
Direct Known Subclasses:
JavaUtilCalendarFieldType, JavaUtilDateFieldType, JSR310LocalDateFieldType, JSR310LocalDateTimeFieldType, JSR310LocalTimeFieldType, JSR310OffsetTimeFieldType, SecondaryFieldType

public abstract class SecondaryFieldTypeBase<SecondaryType,ConversionType,PrimitiveType extends ConversionType>
extends FudgeFieldType<SecondaryType>
implements FudgeTypeConverter<ConversionType,SecondaryType>

The base type definition for a secondary field type that converts Java objects to/from more fundamental Fudge types. This approach is more lightweight than the tools available in the mapping package, but also limited as there is no access to the FudgeContext when the conversion takes place. The SecondaryFieldType class provides a simpler interface to use for most extensions.

See Also:
Serialized Form

Constructor Summary
protected SecondaryFieldTypeBase(FudgeFieldType<PrimitiveType> type, Class<SecondaryType> javaType)
          Creates a new secondary type on top of an existing Fudge type.
 
Method Summary
 FudgeFieldType<PrimitiveType> getPrimaryType()
          Returns the underlying (primary) Fudge type.
 int getVariableSize(SecondaryType value, FudgeTaxonomy taxonomy)
          Calculates the resultant size by converting to the primary object and invoking the delegate.
 SecondaryType readValue(DataInput input, int dataSize)
          Reads a value of this type to the output.
abstract  PrimitiveType secondaryToPrimary(SecondaryType object)
          Converts an object from the secondary type to a primitive Fudge type for writing.
 void writeValue(DataOutput output, SecondaryType value)
          Writes a value of this type to the output.
 
Methods inherited from class org.fudgemsg.FudgeFieldType
equals, getFixedSize, getJavaType, getTypeId, hashCode, isVariableSize, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.fudgemsg.types.FudgeTypeConverter
canConvertPrimary, primaryToSecondary
 

Constructor Detail

SecondaryFieldTypeBase

protected SecondaryFieldTypeBase(FudgeFieldType<PrimitiveType> type,
                                 Class<SecondaryType> javaType)
Creates a new secondary type on top of an existing Fudge type.

Parameters:
type - existing Fudge primitive type
javaType - Java type for conversion
Method Detail

getPrimaryType

public FudgeFieldType<PrimitiveType> getPrimaryType()
Returns the underlying (primary) Fudge type.

Returns:
the primary type

secondaryToPrimary

public abstract PrimitiveType secondaryToPrimary(SecondaryType object)
Converts an object from the secondary type to a primitive Fudge type for writing. An implementation may assume that the object parameter is not null.

Parameters:
object - the secondary instance
Returns:
the underlying Fudge data to write out

getVariableSize

public int getVariableSize(SecondaryType value,
                           FudgeTaxonomy taxonomy)
Calculates the resultant size by converting to the primary object and invoking the delegate. If conversion overhead is noticeable, a subclass should consider overriding this and calculating the value directly.

Overrides:
getVariableSize in class FudgeFieldType<SecondaryType>
Parameters:
value - the value to convert (if it will not be a fixed width type)
taxonomy - the taxonomy used to encode
Returns:
the size in bytes

writeValue

public void writeValue(DataOutput output,
                       SecondaryType value)
                throws IOException
Writes a value of this type to the output.

This is intended for use by variable width types and must write the given value. The implementation must write exactly the number of bytes returned by the size calculation.

Overrides:
writeValue in class FudgeFieldType<SecondaryType>
Parameters:
output - the output target to write the value to, not null
value - the value to write
Throws:
IOException - if an error occurs, which must be wrapped by the caller

readValue

public SecondaryType readValue(DataInput input,
                               int dataSize)
                        throws IOException
Reads a value of this type to the output.

This is intended for use by variable width types and must read the given value. The implementation must read exactly the number of bytes passed into the method.

Overrides:
readValue in class FudgeFieldType<SecondaryType>
Parameters:
input - the input source to read the value from, not null
dataSize - the number of bytes of data to read
Returns:
the value that was read
Throws:
IOException - if an error occurs, which must be wrapped by the caller


Copyright 2009-Present by OpenGamma Inc. and individual contributors
Released under the Apache License, Version 2.0