com.partnersoft.io.formats.packrat
Class PackratDatatype

java.lang.Object
  extended by com.partnersoft.io.formats.packrat.PackratDatatype
All Implemented Interfaces:
PackratConstants, java.io.Serializable
Direct Known Subclasses:
PackratArray, PackratAssociation, PackratBlob, PackratFloat, PackratInteger, PackratList, PackratString, PackratStructure

public abstract class PackratDatatype
extends java.lang.Object
implements PackratConstants, java.io.Serializable

Representation of a data type in a Packrat file. Complex types may be parameterizeable. Includes a name, so you can also think of it as like a variable declaration in a procedural language.

Author:
Paul Reavis Copyright 2002 Partner Software, Inc.
See Also:
Serialized Form

Field Summary
protected  PackratDatatype[] EMPTY_TYPE_ARRAY
           
protected  int sizeParam
           
 
Fields inherited from interface com.partnersoft.io.formats.packrat.PackratConstants
DATATYPE_ARRAY, DATATYPE_ASSOC, DATATYPE_BLOB, DATATYPE_FLAG_COLLECTION, DATATYPE_FLAG_FIXED, DATATYPE_FLAG_STRUCT, DATATYPE_FLAG_VARIABLE, DATATYPE_FLOAT, DATATYPE_INT, DATATYPE_LIST, DATATYPE_STRING, DATATYPE_STRUCT, DATATYPE_UINT
 
Constructor Summary
PackratDatatype()
           
 
Method Summary
 void appendAllTypes(java.util.List results)
          Adds datatypes and subdatatypes to list as text descriptions.
abstract  java.lang.Object bytesToObject(ByteBuffer input)
          Convert the given bytes to an appropriate object representation.
 int getFixedSizeAmount()
          Override with real fixed size in bytes if isFixedSize() is true.
 java.lang.String getFullDescription()
          Return a full description of the declaration, including name.
 java.lang.String getName()
          This is a presumably human-understandable name for the type declaration.
 int getSizeParam()
           
 PackratDatatype[] getSubtypes()
          Return a list of any subtypes.
abstract  int getTypeCode()
          Return a single-byte code for the type.
abstract  java.lang.String getTypeDescription()
          Return a String description of the data type (e.g.
abstract  boolean isFixedSize()
          If true, datatype requires a fixed number of bytes.
 byte[] objectToByteArray(java.lang.Object input)
          Convenience version of objectToBytes that makes a byte array.
 ByteBuffer objectToByteBuffer(java.lang.Object input)
          Convenience version of objectToBytes that makes a new byte buffer.
abstract  void objectToBytes(java.lang.Object input, ByteBuffer output)
          Convert the given object to its binary representation.
 void objectToBytes(java.lang.Object input, ByteBuffer output, int sizeParam)
           
protected  long readSize(ByteBuffer input, int whereAt)
           
 void setName(java.lang.String newName)
           
 void setSizeParam(int newParam)
           
 java.lang.String toString()
           
protected  void writeSize(long size, ByteBuffer output)
           
protected  void writeSize(long size, ByteBuffer output, int whereAt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_TYPE_ARRAY

protected final PackratDatatype[] EMPTY_TYPE_ARRAY

sizeParam

protected int sizeParam
Constructor Detail

PackratDatatype

public PackratDatatype()
Method Detail

isFixedSize

public abstract boolean isFixedSize()
If true, datatype requires a fixed number of bytes.


getFixedSizeAmount

public int getFixedSizeAmount()
Override with real fixed size in bytes if isFixedSize() is true.


getTypeCode

public abstract int getTypeCode()
Return a single-byte code for the type. Must be unique. Valid codes are defined in PackratConstants.


getTypeDescription

public abstract java.lang.String getTypeDescription()
Return a String description of the data type (e.g. "String", "UInt16", etc.)


objectToBytes

public abstract void objectToBytes(java.lang.Object input,
                                   ByteBuffer output)
Convert the given object to its binary representation. Throws IllegalArgumentException if it doesn't like the input.


objectToBytes

public void objectToBytes(java.lang.Object input,
                          ByteBuffer output,
                          int sizeParam)

bytesToObject

public abstract java.lang.Object bytesToObject(ByteBuffer input)
Convert the given bytes to an appropriate object representation. Throws IllegalArgumentException if it doesn't like the input.


getSubtypes

public PackratDatatype[] getSubtypes()
Return a list of any subtypes. Defaults to an empty array. Subtypes are any datatypes that are part of this type - for example, fields in a structure or values in a list.


writeSize

protected final void writeSize(long size,
                               ByteBuffer output)

writeSize

protected final void writeSize(long size,
                               ByteBuffer output,
                               int whereAt)

readSize

protected final long readSize(ByteBuffer input,
                              int whereAt)

getFullDescription

public java.lang.String getFullDescription()
Return a full description of the declaration, including name.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

objectToByteArray

public byte[] objectToByteArray(java.lang.Object input)
Convenience version of objectToBytes that makes a byte array.


objectToByteBuffer

public ByteBuffer objectToByteBuffer(java.lang.Object input)
Convenience version of objectToBytes that makes a new byte buffer.


appendAllTypes

public void appendAllTypes(java.util.List results)
Adds datatypes and subdatatypes to list as text descriptions.


getName

public java.lang.String getName()
This is a presumably human-understandable name for the type declaration.


setName

public void setName(java.lang.String newName)

getSizeParam

public int getSizeParam()

setSizeParam

public void setSizeParam(int newParam)