Java Code Examples for com.esotericsoftware.kryo.Kryo#writeObjectOrNull()

The following examples show how to use com.esotericsoftware.kryo.Kryo#writeObjectOrNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectSpace.java    From kryonet with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void write (Kryo kryo, Output output) {
	output.writeInt(objectID, true);
	output.writeInt(cachedMethod.methodClassID, true);
	output.writeByte(cachedMethod.methodIndex);

	Serializer[] serializers = cachedMethod.serializers;
	Object[] args = this.args;
	for (int i = 0, n = serializers.length; i < n; i++) {
		Serializer serializer = serializers[i];
		if (serializer != null)
			kryo.writeObjectOrNull(output, args[i], serializer);
		else
			kryo.writeClassAndObject(output, args[i]);
	}

	output.writeByte(responseData);
}
 
Example 2
Source File: ObjectSpace.java    From RuinsOfRevenge with MIT License 6 votes vote down vote up
public void write (Kryo kryo, Output output) {
	output.writeInt(objectID, true);

	int methodClassID = kryo.getRegistration(method.getDeclaringClass()).getId();
	output.writeInt(methodClassID, true);

	CachedMethod[] cachedMethods = getMethods(kryo, method.getDeclaringClass());
	CachedMethod cachedMethod = null;
	for (int i = 0, n = cachedMethods.length; i < n; i++) {
		cachedMethod = cachedMethods[i];
		if (cachedMethod.method.equals(method)) {
			output.writeByte(i);
			break;
		}
	}

	for (int i = 0, n = cachedMethod.serializers.length; i < n; i++) {
		Serializer serializer = cachedMethod.serializers[i];
		if (serializer != null)
			kryo.writeObjectOrNull(output, args[i], serializer);
		else
			kryo.writeClassAndObject(output, args[i]);
	}

	output.writeByte(responseID);
}
 
Example 3
Source File: KryoMessageFormat.java    From txle with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object[] objects) {
  Output output = new Output(DEFAULT_BUFFER_SIZE, -1);

  Kryo kryo = POOL.borrow();
  kryo.writeObjectOrNull(output, objects, Object[].class);
  POOL.release(kryo);

  return output.toBytes();
}
 
Example 4
Source File: GrpcTxEventEndpointImpl.java    From txle with Apache License 2.0 5 votes vote down vote up
private byte[] serialize(Object[] objects) {
    Output output = new Output(4096, -1);
    Kryo kryo = pool.borrow();
    kryo.writeObjectOrNull(output, objects, Object[].class);
    pool.release(kryo);
    return output.toBytes();
}
 
Example 5
Source File: KryoMessageFormat.java    From servicecomb-pack with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object[] objects) {
  Output output = new Output(DEFAULT_BUFFER_SIZE, -1);

  Kryo kryo = pool.borrow();
  kryo.writeObjectOrNull(output, objects, Object[].class);
  pool.release(kryo);

  return output.toBytes();
}
 
Example 6
Source File: KryoTest.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
public static void writeRoaringToFile(File f,
        RoaringBitmap roaring,
        Serializer<RoaringBitmap> serializer) throws FileNotFoundException {
    Kryo kryo = createKryo();
    Output kryoOutputMap = new Output(new FileOutputStream(f));
    kryo.writeObjectOrNull(kryoOutputMap, roaring, serializer);
    kryoOutputMap.flush();
    kryoOutputMap.close();
}
 
Example 7
Source File: Perceptron.java    From incubator-samoa with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Perceptron p) {
  kryo.writeObjectOrNull(output, new PerceptronData(p), PerceptronData.class);
}
 
Example 8
Source File: TargetMean.java    From incubator-samoa with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, TargetMean t) {
  kryo.writeObjectOrNull(output, new TargetMeanData(t), TargetMeanData.class);
}
 
Example 9
Source File: MastershipTermSerializer.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, MastershipTerm object) {
    kryo.writeObjectOrNull(output, object.master(), nodeIdSerializer());
    output.writeLong(object.termNumber());
}
 
Example 10
Source File: Perceptron.java    From samoa with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Perceptron p) {
	kryo.writeObjectOrNull(output, new PerceptronData(p), PerceptronData.class);
}
 
Example 11
Source File: TargetMean.java    From samoa with Apache License 2.0 4 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, TargetMean t) {
	kryo.writeObjectOrNull(output, new TargetMeanData(t), TargetMeanData.class);
}