本文整理汇总了Java中com.jme3.network.serializing.Serializer.getSerializer方法的典型用法代码示例。如果您正苦于以下问题:Java Serializer.getSerializer方法的具体用法?Java Serializer.getSerializer怎么用?Java Serializer.getSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.network.serializing.Serializer
的用法示例。
在下文中一共展示了Serializer.getSerializer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readObject
import com.jme3.network.serializing.Serializer; //导入方法依赖的package包/类
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
byte dimensionCount = data.get();
if (dimensionCount == 0)
return null;
int[] dimensions = new int[dimensionCount];
for (int i = 0; i < dimensionCount; i++)
dimensions[i] = data.getInt();
Serializer elementSerializer = null;
Class elementClass = c;
while (elementClass.getComponentType() != null)
elementClass = elementClass.getComponentType();
if (Modifier.isFinal(elementClass.getModifiers())) elementSerializer = Serializer.getSerializer(elementClass);
// Create array and read in the data.
T array = (T)Array.newInstance(elementClass, dimensions);
readArray(elementSerializer, elementClass, data, array, 0, dimensions);
return array;
}
示例2: writeObject
import com.jme3.network.serializing.Serializer; //导入方法依赖的package包/类
public void writeObject(ByteBuffer buffer, Object object) throws IOException {
if (object == null){
buffer.put((byte)0);
return;
}
int[] dimensions = getDimensions(object);
buffer.put((byte)dimensions.length);
for (int dimension : dimensions) buffer.putInt(dimension);
Serializer elementSerializer = null;
Class elementClass = object.getClass();
while (elementClass.getComponentType() != null) {
elementClass = elementClass.getComponentType();
}
if (Modifier.isFinal(elementClass.getModifiers())) elementSerializer = Serializer.getSerializer(elementClass);
writeArray(elementSerializer, buffer, object, 0, dimensions.length);
}
示例3: writeObject
import com.jme3.network.serializing.Serializer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void writeObject(ByteBuffer buffer, Object object) throws IOException {
Map map = (Map)object;
int length = map.size();
buffer.putInt(length);
if (length == 0) return;
Set<Entry> entries = map.entrySet();
Iterator<Entry> it = entries.iterator();
Entry entry = it.next();
Class keyClass = entry.getKey().getClass();
Class valClass = entry.getValue().getClass();
while (it.hasNext()) {
entry = it.next();
if (entry.getKey().getClass() != keyClass){
keyClass = null;
if (valClass == null)
break;
}
if (entry.getValue().getClass() != valClass){
valClass = null;
if (keyClass == null)
break;
}
}
boolean uniqueKeys = keyClass == null;
boolean uniqueVals = valClass == null;
int flags = 0;
if (!uniqueKeys) flags |= 0x01;
if (!uniqueVals) flags |= 0x02;
buffer.put( (byte) flags );
Serializer keySerial = null, valSerial = null;
if (!uniqueKeys){
Serializer.writeClass(buffer, keyClass);
keySerial = Serializer.getSerializer(keyClass);
}
if (!uniqueVals){
Serializer.writeClass(buffer, valClass);
valSerial = Serializer.getSerializer(valClass);
}
it = entries.iterator();
while (it.hasNext()) {
entry = it.next();
if (uniqueKeys){
Serializer.writeClassAndObject(buffer, entry.getKey());
}else{
keySerial.writeObject(buffer, entry.getKey());
}
if (uniqueVals){
Serializer.writeClassAndObject(buffer, entry.getValue());
}else{
valSerial.writeObject(buffer, entry.getValue());
}
}
}
示例4: initialize
import com.jme3.network.serializing.Serializer; //导入方法依赖的package包/类
public void initialize(Class clazz) {
checkClass(clazz);
List<Field> fields = new ArrayList<Field>();
Class processingClass = clazz;
while (processingClass != Object.class && processingClass != Message.class) {
Collections.addAll(fields, processingClass.getDeclaredFields());
processingClass = processingClass.getSuperclass();
}
List<SavedField> cachedFields = new ArrayList<SavedField>(fields.size());
for (Field field : fields) {
int modifiers = field.getModifiers();
if (Modifier.isTransient(modifiers)) continue;
if (Modifier.isFinal(modifiers)) continue;
if (Modifier.isStatic(modifiers)) continue;
if (field.isSynthetic()) continue;
field.setAccessible(true);
SavedField cachedField = new SavedField();
cachedField.field = field;
if (Modifier.isFinal(field.getType().getModifiers())) {
// The type of this field is implicit in the outer class
// definition and because the type is final, it can confidently
// be determined on the other end.
// Note: passing false to this method has the side-effect that field.getType()
// will be registered as a real class that can then be read/written
// directly as any other registered class. It should be safe to take
// an ID like this because Serializer.initialize() is only called
// during registration... so this is like nested registration and
// doesn't have any ordering problems.
// ...well, as long as the order of fields is consistent from one
// end to the next.
cachedField.serializer = Serializer.getSerializer(field.getType(), false);
}
cachedFields.add(cachedField);
}
Collections.sort(cachedFields, new Comparator<SavedField>() {
public int compare (SavedField o1, SavedField o2) {
return o1.field.getName().compareTo(o2.field.getName());
}
});
savedFields.put(clazz, cachedFields.toArray(new SavedField[cachedFields.size()]));
}
示例5: initialize
import com.jme3.network.serializing.Serializer; //导入方法依赖的package包/类
public void initialize(Class clazz) {
checkClass(clazz);
List<Field> fields = new ArrayList<Field>();
Class processingClass = clazz;
while (processingClass != Object.class ) {
Collections.addAll(fields, processingClass.getDeclaredFields());
processingClass = processingClass.getSuperclass();
}
List<SavedField> cachedFields = new ArrayList<SavedField>(fields.size());
for (Field field : fields) {
int modifiers = field.getModifiers();
if (Modifier.isTransient(modifiers)) continue;
if (Modifier.isFinal(modifiers)) continue;
if (Modifier.isStatic(modifiers)) continue;
if (field.isSynthetic()) continue;
field.setAccessible(true);
SavedField cachedField = new SavedField();
cachedField.field = field;
if (Modifier.isFinal(field.getType().getModifiers())) {
// The type of this field is implicit in the outer class
// definition and because the type is final, it can confidently
// be determined on the other end.
// Note: passing false to this method has the side-effect that field.getType()
// will be registered as a real class that can then be read/written
// directly as any other registered class. It should be safe to take
// an ID like this because Serializer.initialize() is only called
// during registration... so this is like nested registration and
// doesn't have any ordering problems.
// ...well, as long as the order of fields is consistent from one
// end to the next.
cachedField.serializer = Serializer.getSerializer(field.getType(), false);
}
cachedFields.add(cachedField);
}
Collections.sort(cachedFields, new Comparator<SavedField>() {
public int compare (SavedField o1, SavedField o2) {
return o1.field.getName().compareTo(o2.field.getName());
}
});
savedFields.put(clazz, cachedFields.toArray(new SavedField[cachedFields.size()]));
}