Allow the streamer to be used in a jvm-neutral way, streaming fields in alphabetical order. Sun JVMs use the order they're defined in the file, IBM JVMs apparently use the reverse of that, and Dalvik/Android JVMs stream in alphabetical order. Ideally, the alphabetical mode would be the default but this would break all kinds of legacy stuff, so I'm not going to make that the default. (I had done this before on the narya-1.5 tags - doing correctly on trunk now.)
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6520 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -30,7 +30,8 @@ import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -526,6 +527,15 @@ public class Streamer
|
||||
// reflect on all the object's fields and remove all marked with NotStreamable
|
||||
List<Field> fields = Lists.newArrayList();
|
||||
ClassUtil.getFields(_target, fields);
|
||||
|
||||
/** Checks whether or not we should stream the fields in alphabetical order. This ensures
|
||||
* cross-JVM compatibility since Class.getDeclaredFields() does not define an order. Due
|
||||
* to legacy issues, this is false by default.
|
||||
*/
|
||||
if (Boolean.getBoolean("com.threerings.io.streamFieldsAlphabetically")) {
|
||||
Collections.sort(fields, FIELD_ALPHA_COMPARATOR);
|
||||
}
|
||||
|
||||
_fields = Iterables.toArray(Iterables.filter(fields, _isStreamableFieldPred), Field.class);
|
||||
int fcount = _fields.length;
|
||||
|
||||
@@ -550,6 +560,13 @@ public class Streamer
|
||||
}
|
||||
}
|
||||
|
||||
protected Comparator<Field> FIELD_ALPHA_COMPARATOR = new Comparator<Field>() {
|
||||
public int compare (Field arg0, Field arg1)
|
||||
{
|
||||
return arg0.getName().compareTo(arg1.getName());
|
||||
}
|
||||
};
|
||||
|
||||
/** Used to coerce the type system into quietude when reading enums from the wire. */
|
||||
protected static enum EnumReader implements ByteEnum {
|
||||
NOT_USED;
|
||||
|
||||
Reference in New Issue
Block a user