Java Code Examples for com.esotericsoftware.kryo.Kryo.writeClass()

The following are Jave code examples for showing how to use writeClass() of the com.esotericsoftware.kryo.Kryo class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: gdx-cclibs   File: BSplineSerializer.java   Source Code and License Vote up 6 votes
@Override
public void write(Kryo kryo, Output output, BSpline bSpline) {
    Class<? extends Vector> vectorType = null;
    if (bSpline.controlPoints != null && bSpline.controlPoints.length > 0)
        vectorType = bSpline.controlPoints[0].getClass();
    else if (bSpline.knots != null && bSpline.knots.size > 0)
        vectorType = ((Vector)bSpline.knots.first()).getClass();
    kryo.writeClass(output, vectorType);
    output.writeInt(bSpline.controlPoints != null ? bSpline.controlPoints.length : -1); // -1 for null array
    if (bSpline.controlPoints != null){
        for (int i = 0; i < bSpline.controlPoints.length; i++) {
            kryo.writeObjectOrNull(output, bSpline.controlPoints[i], vectorType);
        }
    }
    kryo.writeObjectOrNull(output, bSpline.knots, Array.class);
    output.writeInt(bSpline.degree, true);
    output.writeBoolean(bSpline.continuous);
    output.writeInt(bSpline.spanCount, true);
}
 
Example 2
Project: gdx-cclibs   File: GraphHeader.java   Source Code and License Vote up 6 votes
@Override
public final void write (Kryo kryo, Output output) {
    if (currentReadWriteVersion == -1)
        throw new RuntimeException("currentReadWriteVersion must be set before writing.");
    if (currentReadWriteVersion < 0 || minimumReadVersion < 0)
        throw new RuntimeException("currentReadWriteVersion and minimumReadVersion must not be less than 0.");
    if (currentReadWriteVersion < minimumReadVersion)
        throw new RuntimeException("currentReadWriteVersion cannot be lower than minimumReadVersion");

    Class type = data == null ? null : data.getClass();
    pushHeader(kryo, this);
    output.writeInt(GRAPH_HEADER_VERSION, true);
    kryo.writeClass(output, type);
    output.writeInt(Version.MAJOR, true);
    output.writeInt(Version.MINOR, true);
    output.writeInt(Version.REVISION, true);
    output.writeInt(currentReadWriteVersion, true);
    output.writeInt(minimumReadVersion, true);
    output.writeString(minimumReadVersionString);
    output.writeBoolean(useCompactColor);
    output.writeBoolean(includePixmapDrawingParams);
    writeExtra(kryo, output);
    if (data != null)
        kryo.writeObject(output, data);
    popHeader(kryo);
}
 
Example 3
Project: gdx-cclibs   File: CatmullRomSplineSerializer.java   Source Code and License Vote up 5 votes
@Override
public void write(Kryo kryo, Output output, CatmullRomSpline catmullRomSpline) {
    Class<? extends Vector> vectorType = null;
    if (catmullRomSpline.controlPoints != null && catmullRomSpline.controlPoints.length > 0)
        vectorType = catmullRomSpline.controlPoints[0].getClass();
    kryo.writeClass(output, vectorType);
    output.writeInt(catmullRomSpline.controlPoints != null ? catmullRomSpline.controlPoints.length : -1); // -1 for null array
    if (catmullRomSpline.controlPoints != null){
        for (int i = 0; i < catmullRomSpline.controlPoints.length; i++) {
            kryo.writeObjectOrNull(output, catmullRomSpline.controlPoints[i], vectorType);
        }
    }
    output.writeBoolean(catmullRomSpline.continuous);
    output.writeInt(catmullRomSpline.spanCount, true);
}
 
Example 4
Project: gdx-cclibs   File: ArrayMapSerializer.java   Source Code and License Vote up 5 votes
public void write (Kryo kryo, Output output, ArrayMap map) {
    output.writeBoolean(map.ordered);
    int length = map.size;
    output.writeVarInt(length, true);
    kryo.writeClass(output, map.keys.getClass().getComponentType());
    kryo.writeClass(output, map.values.getClass().getComponentType());

    Serializer keySerializer = null;
    if (keyGenericType != null) {
        if (keySerializer == null) keySerializer = kryo.getSerializer(keyGenericType);
        keyGenericType = null;
    }
    Serializer valueSerializer = null;
    if (valueGenericType != null) {
        if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType);
        valueGenericType = null;
    }

    for (Iterator iter = map.iterator(); iter.hasNext();) {
        ObjectMap.Entry entry = (ObjectMap.Entry)iter.next();
        if (keySerializer != null) {
            kryo.writeObject(output, entry.key, keySerializer);
        } else
            kryo.writeClassAndObject(output, entry.key);
        if (valueSerializer != null) {
            kryo.writeObjectOrNull(output, entry.value, valueSerializer);
        } else
            kryo.writeClassAndObject(output, entry.value);
    }
}