Search in sources :

Example 1 with ByteBufOutput

use of rpc.turbo.serialization.kryo.ByteBufOutput in project turbo-rpc by hank-whu.

the class KryoByteBufTest method main.

public static void main(String[] args) {
    Kryo kryo = new Kryo();
    // kryo.setWarnUnregisteredClasses(true);
    // kryo.setReferences(false);
    kryo.register(IntObj.class);
    kryo.register(StringUTF8Obj.class);
    kryo.register(LocalDateTimeObj.class);
    kryo.register(ComplexObj.class);
    kryo.register(int[].class);
    kryo.register(ArrayList.class);
    kryo.register(ArrayListObj.class);
    ByteBufAllocator allocator = new PooledByteBufAllocator(true);
    ByteBuf buffer = allocator.directBuffer(2, 1024 * 1024 * 8);
    System.out.println("buffer.nioBufferCount: " + buffer.nioBufferCount());
    System.out.println(buffer.nioBuffer(0, buffer.capacity()));
    ByteBufOutput output = new ByteBufOutput(buffer);
    UserService userService = new UserServiceServerImpl();
    User user = userService.getUser(Long.MAX_VALUE).join();
    while (true) {
        buffer.clear();
        output.setBuffer(buffer);
        kryo.writeObject(output, user);
        ByteBufInput input = new ByteBufInput(buffer);
        User u = kryo.readObject(input, User.class);
        System.out.println(u);
    }
// buffer.clear();
// output.setBuffer(buffer);
// kryo.writeObject(output, user);
// System.out.println("user writeObject: " + output.total());
// 
// ByteBufInput input = new ByteBufInput(buffer);
// System.out.println("user readableBytes: " + buffer.readableBytes());
// System.out.println("user readerIndex: " + buffer.readerIndex());
// System.out.println(kryo.readObject(input, User.class));
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) UserServiceServerImpl(rpc.turbo.benchmark.service.UserServiceServerImpl) User(rpc.turbo.benchmark.bean.User) ByteBufOutput(rpc.turbo.serialization.kryo.ByteBufOutput) UserService(rpc.turbo.benchmark.service.UserService) ByteBufInput(rpc.turbo.serialization.kryo.ByteBufInput) ByteBuf(io.netty.buffer.ByteBuf) Kryo(com.esotericsoftware.kryo.Kryo) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator)

Aggregations

Kryo (com.esotericsoftware.kryo.Kryo)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 User (rpc.turbo.benchmark.bean.User)1 UserService (rpc.turbo.benchmark.service.UserService)1 UserServiceServerImpl (rpc.turbo.benchmark.service.UserServiceServerImpl)1 ByteBufInput (rpc.turbo.serialization.kryo.ByteBufInput)1 ByteBufOutput (rpc.turbo.serialization.kryo.ByteBufOutput)1