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()));
}
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();
}
}
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();
}
Aggregations