FieldIteratorpublic class FieldIterator extends Object For iterating through our fields. |
Fields Summary |
---|
protected int | offset |
Constructors Summary |
---|
public FieldIterator()
|
Methods Summary |
---|
public java.lang.String | calcSize(int fieldNumber, java.lang.String fieldName, java.lang.String size, java.lang.String type)
String result = " + ";
if (type.startsWith("custom:"))
{
String javaFieldName = RecordUtil.getFieldName(fieldNumber, fieldName, 0);
return result + javaFieldName + ".getSize()";
}
else if ("var".equals(size))
{
String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0);
return result + " ("+javaFieldName + ".length() *2)";
}
else if ("varword".equals(size))
{
String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0);
return result + javaFieldName + ".length * 2 + 2";
} else
{
return result + size;
}
| public java.lang.String | fillDecoder(java.lang.String size, java.lang.String type)This utility function returns a fill method entry for a given field
String javaType = RecordUtil.getType(size, type, 0);
String result = "";
if (javaType.equals("short"))
result = "LittleEndian.getShort(data, pos + 0x" + Integer.toHexString(offset) + " + offset)";
else if (javaType.equals("short[]"))
result = "LittleEndian.getShortArray(data, pos + 0x" + Integer.toHexString(offset) + " + offset)";
else if (javaType.equals("int"))
result = "LittleEndian.getInt(data, pos + 0x" + Integer.toHexString(offset) + " + offset)";
else if (javaType.equals("byte"))
result = "data[ pos + 0x" + Integer.toHexString(offset) + " + offset ]";
else if (javaType.equals("double"))
result = "LittleEndian.getDouble(data, pos + 0x" + Integer.toHexString(offset) + " + offset)";
else if (javaType.equals("String") && !type.equals("hbstring"))
result = "StringUtil.getFromUnicode(data, pos + 0x" + Integer.toHexString(offset) + " + offset,("+ size + "-1)/2)";
else if (javaType.equals("String") && type.equals("hbstring"))
result = "StringUtil.getFromUnicodeHigh(data, pos + 0x" + Integer.toHexString(offset) + " + offset, ("+ size+"/2))";
try
{
offset += Integer.parseInt(size);
}
catch (NumberFormatException ignore)
{
}
return result;
| public java.lang.String | fillDecoder2(int position, java.lang.String name, java.lang.String size, java.lang.String type)
if (type.startsWith("custom:"))
{
StringBuffer result = new StringBuffer();
result.append( RecordUtil.getFieldName( position, name, 0 ) );
result.append( " = new " );
String javaType = type.substring( 7 );
result.append(javaType);
result.append( "();\n");
result.append( " pos += " );
result.append(RecordUtil.getFieldName(position, name, 0))
.append(".fillField(data,size,pos + offset + ")
.append(offset)
.append(")");
return result.toString();
}
else
{
return RecordUtil.getFieldName(position, name, 30) +
" = " + fillDecoder(size, type);
}
| public java.lang.String | serialiseEncoder(int fieldNumber, java.lang.String fieldName, java.lang.String size, java.lang.String type)
String javaType = RecordUtil.getType(size, type, 0);
String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0);
String result = "";
if (type.startsWith("custom:"))
result = "pos += " + javaFieldName + ".serializeField( pos + " + (offset+4) + " + offset, data );";
else if (javaType.equals("short"))
result = "LittleEndian.putShort(data, " + (offset+4) + " + offset + pos, " + javaFieldName + ");";
else if (javaType.equals("short[]"))
result = "LittleEndian.putShortArray(data, " + (offset+4) + " + offset + pos, " + javaFieldName + ");";
else if (javaType.equals("int"))
result = "LittleEndian.putInt(data, " + (offset+4) + " + offset + pos, " + javaFieldName + ");";
else if (javaType.equals("byte"))
result = "data[ " + (offset+4) + " + offset + pos ] = " + javaFieldName + ";";
else if (javaType.equals("double"))
result = "LittleEndian.putDouble(data, " + (offset+4) + " + offset + pos, " + javaFieldName + ");";
else if (javaType.equals("String") && !type.equals("hbstring"))
result = "StringUtil.putUncompressedUnicode("+ javaFieldName +", data, offset + pos + 4);";
else if (javaType.equals("String") && type.equals("hbstring"))
result = "StringUtil.putUncompressedUnicodeHigh("+ javaFieldName +", data, "+(offset+4)+" + offset + pos);";
try
{
offset += Integer.parseInt(size);
}
catch (NumberFormatException ignore)
{
}
return result;
|
|