Search in sources :

Example 1 with ProtobufOutput

use of io.protostuff.ProtobufOutput in project java-chassis by ServiceComb.

the class HighwayOutputStream method write.

public void write(WrapSchema headerSchema, Object header, WrapSchema bodySchema, Object body) throws Exception {
    // 写protobuf数据
    LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
    ProtobufOutput output = new ProtobufOutput(linkedBuffer);
    // 写header
    if (headerSchema != null) {
        headerSchema.writeObject(output, header);
    }
    int headerSize = output.getSize();
    // void时bodySchema为null
    if (bodySchema != null) {
        bodySchema.writeObject(output, body);
    }
    writeLength(output.getSize(), headerSize);
    LinkedBuffer.writeTo(this, linkedBuffer);
}
Also used : LinkedBuffer(io.protostuff.LinkedBuffer) ProtobufOutput(io.protostuff.ProtobufOutput)

Example 2 with ProtobufOutput

use of io.protostuff.ProtobufOutput in project java-chassis by ServiceComb.

the class TestHighwayServerConnection method createBuffer.

protected Buffer createBuffer(WrapSchema schema, Object value) throws Exception {
    Buffer headerBuffer;
    LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
    ProtobufOutput output = new ProtobufOutput(linkedBuffer);
    schema.writeObject(output, value);
    try (BufferOutputStream os = new BufferOutputStream()) {
        LinkedBuffer.writeTo(os, linkedBuffer);
        headerBuffer = os.getBuffer();
    }
    return headerBuffer;
}
Also used : LinkedBuffer(io.protostuff.LinkedBuffer) Buffer(io.vertx.core.buffer.Buffer) LinkedBuffer(io.protostuff.LinkedBuffer) BufferOutputStream(io.servicecomb.foundation.vertx.stream.BufferOutputStream) ProtobufOutput(io.protostuff.ProtobufOutput)

Example 3 with ProtobufOutput

use of io.protostuff.ProtobufOutput in project java-chassis by ServiceComb.

the class GrpcCodec method encodeRequest.

public static Buffer encodeRequest(Invocation invocation, OperationProtobuf operationProtobuf) throws Exception {
    try (BufferOutputStream os = new BufferOutputStream()) {
        // 写protobuf数据
        LinkedBuffer linkedBuffer = LinkedBuffer.allocate(BUFFER_SIZE);
        ProtobufOutput output = new ProtobufOutput(linkedBuffer);
        operationProtobuf.getRequestSchema().writeObject(output, invocation.getArgs());
        os.write(0);
        // 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 4 with ProtobufOutput

use of io.protostuff.ProtobufOutput in project incubator-servicecomb-java-chassis by apache.

the class TestArgsNotWrapSchema method testWriteObject.

@Test
public void testWriteObject() {
    boolean status = true;
    LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
    ProtobufOutput output = new ProtobufOutput(linkedBuffer);
    String[] stringArray = new String[1];
    try {
        argsNotWrapSchema.writeObject(output, stringArray);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : LinkedBuffer(io.protostuff.LinkedBuffer) ProtobufOutput(io.protostuff.ProtobufOutput) Test(org.junit.Test)

Example 5 with ProtobufOutput

use of io.protostuff.ProtobufOutput in project incubator-servicecomb-java-chassis by apache.

the class TestArgsNotWrapSchema method testWriteObjectToSchema.

@Test
public void testWriteObjectToSchema() {
    boolean status = true;
    LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
    ProtobufOutput output = new ProtobufOutput(linkedBuffer);
    String[] stringArray = new String[1];
    stringArray[0] = "abc";
    try {
        argsNotWrapSchema.writeObject(output, stringArray);
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : LinkedBuffer(io.protostuff.LinkedBuffer) ProtobufOutput(io.protostuff.ProtobufOutput) Test(org.junit.Test)

Aggregations

LinkedBuffer (io.protostuff.LinkedBuffer)18 ProtobufOutput (io.protostuff.ProtobufOutput)18 Test (org.junit.Test)7 BufferOutputStream (io.servicecomb.foundation.vertx.stream.BufferOutputStream)3 ByteArrayInput (io.protostuff.ByteArrayInput)2 Buffer (io.vertx.core.buffer.Buffer)2 IOException (java.io.IOException)2 Input (io.protostuff.Input)1 ModelProtostuff (io.protostuff.runtime.model.ModelProtostuff)1 MultiWrapper (io.servicecomb.common.javassist.MultiWrapper)1 LoginRequest (io.servicecomb.transport.highway.message.LoginRequest)1 RequestHeader (io.servicecomb.transport.highway.message.RequestHeader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 MultiWrapper (org.apache.servicecomb.common.javassist.MultiWrapper)1 BufferOutputStream (org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream)1