Search in sources :

Example 6 with BufferOutputStream

use of io.servicecomb.foundation.vertx.stream.BufferOutputStream in project java-chassis by ServiceComb.

the class TestStream method testBufferOutputStream.

@Test
public void testBufferOutputStream() {
    @SuppressWarnings({ "resource" }) BufferOutputStream oBufferOutputStream = new BufferOutputStream();
    oBufferOutputStream.writeString("test");
    Assert.assertNotEquals(null, oBufferOutputStream.writerIndex());
    oBufferOutputStream.write(1);
    oBufferOutputStream.write(true);
    Assert.assertEquals(true, (1 < oBufferOutputStream.length()));
}
Also used : BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) Test(org.junit.Test)

Example 7 with BufferOutputStream

use of io.servicecomb.foundation.vertx.stream.BufferOutputStream in project java-chassis by ServiceComb.

the class GrpcCodec method encodeResponse.

public static Buffer encodeResponse(Invocation invocation, Response response, OperationProtobuf operationProtobuf) throws Exception {
    if (response.isFailed()) {
        throw new Exception("not impl");
    }
    try (BufferOutputStream os = new BufferOutputStream()) {
        os.write(0);
        if (response.getResult() != null) {
            // 写protobuf数据
            LinkedBuffer linkedBuffer = LinkedBuffer.allocate(BUFFER_SIZE);
            ProtobufOutput output = new ProtobufOutput(linkedBuffer);
            operationProtobuf.getResponseSchema().writeObject(output, response.getResult());
            // protobuf输出到流
            LinkedBuffer.writeTo(os, linkedBuffer);
        }
        return os.getBuffer();
    }
}
Also used : LinkedBuffer(io.protostuff.LinkedBuffer) BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) ProtobufOutput(io.protostuff.ProtobufOutput)

Example 8 with BufferOutputStream

use of io.servicecomb.foundation.vertx.stream.BufferOutputStream in project java-chassis by ServiceComb.

the class TestResultSerializer method setUp.

@Before
public void setUp() throws Exception {
    resultSerializer = new ResultSerializer();
    outputStream = new BufferOutputStream();
}
Also used : BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) Before(org.junit.Before)

Aggregations

BufferOutputStream (io.servicecomb.foundation.vertx.stream.BufferOutputStream)8 LinkedBuffer (io.protostuff.LinkedBuffer)3 ProtobufOutput (io.protostuff.ProtobufOutput)3 Buffer (io.vertx.core.buffer.Buffer)2 Before (org.junit.Before)2 Test (org.junit.Test)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1