Search in sources :

Example 1 with ByteBufInput

use of io.protostuff.ByteBufInput in project turbo-rpc by hank-whu.

the class TracerSerializerBenchmark method readByProtostuff.

@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public Tracer readByProtostuff() throws Exception {
    protostuffBuffer.readerIndex(0);
    ByteBufInput input = new ByteBufInput(protostuffBuffer, true);
    Tracer tracer = tracerSchema.newMessage();
    tracerSchema.mergeFrom(input, tracer);
    return tracer;
}
Also used : ByteBufInput(io.protostuff.ByteBufInput) Tracer(rpc.turbo.trace.Tracer) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 2 with ByteBufInput

use of io.protostuff.ByteBufInput in project turbo-rpc by hank-whu.

the class ProtostuffBenchmark method deserializeUser.

@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public User deserializeUser() throws Exception {
    userBuffer.readerIndex(0);
    ByteBufInput input = new ByteBufInput(userBuffer, true);
    User user = userSchema.newMessage();
    userSchema.mergeFrom(input, user);
    return user;
}
Also used : User(rpc.turbo.benchmark.bean.User) ByteBufInput(io.protostuff.ByteBufInput) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 3 with ByteBufInput

use of io.protostuff.ByteBufInput in project turbo-rpc by hank-whu.

the class ProtostuffBenchmark method deserializeUserPage.

@Benchmark
@BenchmarkMode({ Mode.Throughput })
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@SuppressWarnings("unchecked")
public Page<User> deserializeUserPage() throws Exception {
    listBuffer.readerIndex(0);
    ByteBufInput input = new ByteBufInput(listBuffer, true);
    Page<User> userPage = (Page<User>) userPageSchema.newMessage();
    userPageSchema.mergeFrom(input, userPage);
    return userPage;
}
Also used : User(rpc.turbo.benchmark.bean.User) ByteBufInput(io.protostuff.ByteBufInput) Page(rpc.turbo.benchmark.bean.Page) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 4 with ByteBufInput

use of io.protostuff.ByteBufInput in project turbo-rpc by hank-whu.

the class ProtostuffSerializer method readRequest.

public Request readRequest(ByteBuf byteBuf) throws IOException {
    int requestId = byteBuf.readInt();
    int serviceId = ByteBufUtils.readVarInt(byteBuf);
    Tracer tracer = TRACER_SERIALIZER.read(byteBuf);
    Schema<MethodParam> schema = schema(serviceId);
    MethodParam methodParam = null;
    if (EmptyMethodParam.class.equals(schema.typeClass())) {
        methodParam = EmptyMethodParam.empty();
    } else {
        ByteBufInput input = getOrUpdate(INPUT_ATTACHMENT_INDEX, INPUT_SUPPLIER);
        input.setByteBuf(byteBuf, true);
        methodParam = schema.newMessage();
        schema.mergeFrom(input, methodParam);
    }
    Request request = RecycleRequest.newInstance(requestId, serviceId, tracer, methodParam);
    return request;
}
Also used : EmptyMethodParam(rpc.turbo.param.EmptyMethodParam) MethodParam(rpc.turbo.param.MethodParam) Tracer(rpc.turbo.trace.Tracer) ByteBufInput(io.protostuff.ByteBufInput) RecycleRequest(rpc.turbo.protocol.recycle.RecycleRequest) Request(rpc.turbo.protocol.Request)

Example 5 with ByteBufInput

use of io.protostuff.ByteBufInput in project turbo-rpc by hank-whu.

the class ProtostuffSerializer method readResponse.

public Response readResponse(ByteBuf byteBuf) throws IOException {
    // System.out.println("response content: " + new
    // String(ByteBufUtil.getBytes(byteBuf.duplicate())));
    // System.out.println("response length: " + byteBuf.readableBytes());
    ByteBufInput input = getOrUpdate(INPUT_ATTACHMENT_INDEX, INPUT_SUPPLIER);
    input.setByteBuf(byteBuf, true);
    Response response = RecycleResponse.newInstance(0, (byte) 0, null, null);
    responseSchema.mergeFrom(input, response);
    return response;
}
Also used : Response(rpc.turbo.protocol.Response) RecycleResponse(rpc.turbo.protocol.recycle.RecycleResponse) ByteBufInput(io.protostuff.ByteBufInput)

Aggregations

ByteBufInput (io.protostuff.ByteBufInput)5 Benchmark (org.openjdk.jmh.annotations.Benchmark)3 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)3 OutputTimeUnit (org.openjdk.jmh.annotations.OutputTimeUnit)3 User (rpc.turbo.benchmark.bean.User)2 Tracer (rpc.turbo.trace.Tracer)2 Page (rpc.turbo.benchmark.bean.Page)1 EmptyMethodParam (rpc.turbo.param.EmptyMethodParam)1 MethodParam (rpc.turbo.param.MethodParam)1 Request (rpc.turbo.protocol.Request)1 Response (rpc.turbo.protocol.Response)1 RecycleRequest (rpc.turbo.protocol.recycle.RecycleRequest)1 RecycleResponse (rpc.turbo.protocol.recycle.RecycleResponse)1