Java Code Examples for com.esotericsoftware.kryo.Registration#getSerializer()

The following examples show how to use com.esotericsoftware.kryo.Registration#getSerializer() . 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: FastSerializer.java    From turbo-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * 快速写入
 * 
 * @param kryo
 * @param output
 * @param defaultRegistration
 * @param value
 */
public static void fastWrite(Kryo kryo, Output output, Registration defaultRegistration, Object value) {
	if (value == null) {
		kryo.writeClass(output, null);
		return;
	}

	Class<?> type = value.getClass();

	if (defaultRegistration.getType().equals(type)) {
		if (defaultRegistration.getId() == FastClassResolver.NAME) {
			((FastClassResolver) kryo.getClassResolver()).writeName(output, type, defaultRegistration);
		} else {
			output.writeVarInt(defaultRegistration.getId() + 2, true);
		}

		kryo.writeObject(output, value, defaultRegistration.getSerializer());
	} else {
		Registration registration = kryo.writeClass(output, value.getClass());
		Serializer<?> serializer = registration.getSerializer();
		kryo.writeObject(output, value, serializer);
	}
}
 
Example 2
Source File: FastSerializer.java    From turbo-rpc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static Object slowRead(Kryo kryo, Input input) {
	Registration registration = kryo.readClass(input);
	if (registration == null) {
		return null;
	} else {
		Serializer<?> serializer = registration.getSerializer();
		return kryo.readObject(input, registration.getType(), serializer);
	}
}
 
Example 3
Source File: SparkRunnerKryoRegistratorTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void registerClasses(Kryo kryo) {
  super.registerClasses(kryo);
  Registration registration = kryo.getRegistration(MicrobatchSource.class);
  com.esotericsoftware.kryo.Serializer kryoSerializer = registration.getSerializer();
  assertTrue(kryoSerializer instanceof StatelessJavaSerializer);
}