Search in sources :

Example 1 with Input

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

the class TestHighwayCodec method testReadRequestHeader.

@Test
public void testReadRequestHeader() {
    boolean status = true;
    try {
        new MockUp<NotWrapSchema>() {

            @Mock
            public Object readObject(Input input) throws IOException {
                return new RequestHeader();
            }
        };
        bodyBuffer = Buffer.buffer("\"abc\"");
        RequestHeader requestHeader = HighwayCodec.readRequestHeader(bodyBuffer);
        Assert.assertNotNull(requestHeader);
        Assert.assertEquals(0, requestHeader.getFlags());
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Input(io.protostuff.Input) RequestHeader(io.servicecomb.transport.highway.message.RequestHeader) MockUp(mockit.MockUp) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Input

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

the class TestArgsNotWrapSchema method testReadObject.

@Test
public void testReadObject() {
    boolean status = true;
    Input input = null;
    try {
        Object object = argsNotWrapSchema.readObject(input);
        Assert.assertNotNull(object);
    // object is created but no values inside to assert
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Input(io.protostuff.Input) Test(org.junit.Test)

Example 3 with Input

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

the class WrapSchema method readObject.

@SuppressWarnings("unchecked")
default <T> T readObject(Buffer buffer, ProtobufFeature protobufFeature) throws Exception {
    if (buffer == null || buffer.length() == 0) {
        // 空串时,protobuf至少为编码为1字节
        return (T) readFromEmpty();
    }
    ByteBuffer nioBuffer = buffer.getByteBuf().nioBuffer();
    Input input = new ByteBufferInput(nioBuffer, false);
    ProtobufFeatureUtils.setProtobufFeature(protobufFeature);
    try {
        return (T) readObject(input);
    } finally {
        ProtobufFeatureUtils.removeProtobufFeature();
    }
}
Also used : Input(io.protostuff.Input) ByteBufferInput(io.protostuff.ByteBufferInput) ByteBufferInput(io.protostuff.ByteBufferInput) ByteBuffer(java.nio.ByteBuffer)

Example 4 with Input

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

the class WrapSchema method readObject.

@SuppressWarnings("unchecked")
default default <T> T readObject(Buffer buffer) throws Exception {
    if (buffer == null || buffer.length() == 0) {
        // 空串时,protobuf至少为编码为1字节
        return (T) readFromEmpty();
    }
    ByteBuffer nioBuffer = buffer.getByteBuf().nioBuffer();
    Input input = new ByteBufferInput(nioBuffer, false);
    return (T) readObject(input);
}
Also used : Input(io.protostuff.Input) ByteBufferInput(io.protostuff.ByteBufferInput) ByteBufferInput(io.protostuff.ByteBufferInput) ByteBuffer(java.nio.ByteBuffer)

Example 5 with Input

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

the class TestArgsNotWrapSchema method testReadObject.

@Test
public void testReadObject() {
    boolean status = true;
    Input input = null;
    try {
        Object object = argsNotWrapSchema.readObject(input);
        Assert.assertNotNull(object);
    // object is created but no values inside to assert
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : Input(io.protostuff.Input) Test(org.junit.Test)

Aggregations

Input (io.protostuff.Input)10 Test (org.junit.Test)7 IOException (java.io.IOException)4 ByteArrayInput (io.protostuff.ByteArrayInput)2 ByteBufferInput (io.protostuff.ByteBufferInput)2 ByteBuffer (java.nio.ByteBuffer)2 MockUp (mockit.MockUp)2 LinkedBuffer (io.protostuff.LinkedBuffer)1 ProtobufOutput (io.protostuff.ProtobufOutput)1 MultiWrapper (io.servicecomb.common.javassist.MultiWrapper)1 RequestHeader (io.servicecomb.transport.highway.message.RequestHeader)1 MultiWrapper (org.apache.servicecomb.common.javassist.MultiWrapper)1 Root (org.apache.servicecomb.foundation.protobuf.internal.model.Root)1 RequestHeader (org.apache.servicecomb.transport.highway.message.RequestHeader)1