Java Code Examples for com.esotericsoftware.kryo.io.Output#writeVarInt()

The following examples show how to use com.esotericsoftware.kryo.io.Output#writeVarInt() . 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: FastClassResolver.java    From turbo-rpc with Apache License 2.0 6 votes vote down vote up
public Registration writeClass(Output output, Class type) {
	if (type == null) {
		if (TRACE || (DEBUG && kryo.getDepth() == 1))
			log("Write", null);
		output.writeVarInt(Kryo.NULL, true);
		return null;
	}
	Registration registration = kryo.getRegistration(type);
	if (registration.getId() == NAME)
		writeName(output, type, registration);
	else {
		if (TRACE)
			trace("kryo", "Write class " + registration.getId() + ": " + className(type));
		output.writeVarInt(registration.getId() + 2, true);
	}
	return registration;
}
 
Example 2
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 3
Source File: ClusterSerializableSerializer.java    From atomix-vertx with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, T object) {
  Buffer buffer = Buffer.buffer();
  object.writeToBuffer(buffer);
  byte[] bytes = buffer.getBytes();
  output.writeVarInt(bytes.length, true);
  output.writeBytes(bytes);
}