Add names to the builtin FieldMarshallers to make them differentiable when printed
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6108 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -37,6 +37,16 @@ import static com.threerings.NaryaLog.log;
|
|||||||
*/
|
*/
|
||||||
public abstract class FieldMarshaller
|
public abstract class FieldMarshaller
|
||||||
{
|
{
|
||||||
|
public FieldMarshaller ()
|
||||||
|
{
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldMarshaller (String type)
|
||||||
|
{
|
||||||
|
_type = type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the contents of the supplied field from the supplied stream and sets it in the
|
* Reads the contents of the supplied field from the supplied stream and sets it in the
|
||||||
* supplied object.
|
* supplied object.
|
||||||
@@ -50,6 +60,17 @@ public abstract class FieldMarshaller
|
|||||||
public abstract void writeField (Field field, Object source, ObjectOutputStream out)
|
public abstract void writeField (Field field, Object source, ObjectOutputStream out)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString ()
|
||||||
|
{
|
||||||
|
if (_type != null) {
|
||||||
|
return "FieldMarshaller " + _type;
|
||||||
|
}
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final String _type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a field marshaller appropriate for the supplied field or null if no marshaller
|
* Returns a field marshaller appropriate for the supplied field or null if no marshaller
|
||||||
* exists for the type contained by the field in question.
|
* exists for the type contained by the field in question.
|
||||||
@@ -227,7 +248,7 @@ public abstract class FieldMarshaller
|
|||||||
_marshallers = Maps.newHashMap();
|
_marshallers = Maps.newHashMap();
|
||||||
|
|
||||||
// create a generic marshaller for streamable instances
|
// create a generic marshaller for streamable instances
|
||||||
FieldMarshaller gmarsh = new FieldMarshaller() {
|
FieldMarshaller gmarsh = new FieldMarshaller("Generic") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -247,7 +268,7 @@ public abstract class FieldMarshaller
|
|||||||
_marshallers.put(Object.class, gmarsh);
|
_marshallers.put(Object.class, gmarsh);
|
||||||
|
|
||||||
// create marshallers for the primitive types
|
// create marshallers for the primitive types
|
||||||
_marshallers.put(Boolean.TYPE, new FieldMarshaller() {
|
_marshallers.put(Boolean.TYPE, new FieldMarshaller("boolean") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -259,7 +280,7 @@ public abstract class FieldMarshaller
|
|||||||
out.writeBoolean(field.getBoolean(source));
|
out.writeBoolean(field.getBoolean(source));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_marshallers.put(Byte.TYPE, new FieldMarshaller() {
|
_marshallers.put(Byte.TYPE, new FieldMarshaller("byte") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -271,7 +292,7 @@ public abstract class FieldMarshaller
|
|||||||
out.writeByte(field.getByte(source));
|
out.writeByte(field.getByte(source));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_marshallers.put(Character.TYPE, new FieldMarshaller() {
|
_marshallers.put(Character.TYPE, new FieldMarshaller("char") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -283,7 +304,7 @@ public abstract class FieldMarshaller
|
|||||||
out.writeChar(field.getChar(source));
|
out.writeChar(field.getChar(source));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_marshallers.put(Short.TYPE, new FieldMarshaller() {
|
_marshallers.put(Short.TYPE, new FieldMarshaller("short") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -295,7 +316,7 @@ public abstract class FieldMarshaller
|
|||||||
out.writeShort(field.getShort(source));
|
out.writeShort(field.getShort(source));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_marshallers.put(Integer.TYPE, new FieldMarshaller() {
|
_marshallers.put(Integer.TYPE, new FieldMarshaller("int") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -307,7 +328,7 @@ public abstract class FieldMarshaller
|
|||||||
out.writeInt(field.getInt(source));
|
out.writeInt(field.getInt(source));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_marshallers.put(Long.TYPE, new FieldMarshaller() {
|
_marshallers.put(Long.TYPE, new FieldMarshaller("long") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -319,7 +340,7 @@ public abstract class FieldMarshaller
|
|||||||
out.writeLong(field.getLong(source));
|
out.writeLong(field.getLong(source));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_marshallers.put(Float.TYPE, new FieldMarshaller() {
|
_marshallers.put(Float.TYPE, new FieldMarshaller("float") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -331,7 +352,7 @@ public abstract class FieldMarshaller
|
|||||||
out.writeFloat(field.getFloat(source));
|
out.writeFloat(field.getFloat(source));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_marshallers.put(Double.TYPE, new FieldMarshaller() {
|
_marshallers.put(Double.TYPE, new FieldMarshaller("double") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -343,7 +364,7 @@ public abstract class FieldMarshaller
|
|||||||
out.writeDouble(field.getDouble(source));
|
out.writeDouble(field.getDouble(source));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_marshallers.put(Date.class, new FieldMarshaller() {
|
_marshallers.put(Date.class, new FieldMarshaller("Date") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@@ -364,7 +385,7 @@ public abstract class FieldMarshaller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the field marshaller for pooled strings
|
// create the field marshaller for pooled strings
|
||||||
_internMarshaller = new FieldMarshaller() {
|
_internMarshaller = new FieldMarshaller("intern") {
|
||||||
@Override
|
@Override
|
||||||
public void readField (Field field, Object target, ObjectInputStream in)
|
public void readField (Field field, Object target, ObjectInputStream in)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user