Search in sources :

Example 11 with UnsafeByteArrayOutputStream

use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.

the class BuilderTest method testBuilder_MyMap.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testBuilder_MyMap() throws Exception {
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    Builder<MyMap> b2 = Builder.register(MyMap.class);
    MyMap map = new MyMap();
    map.put("name", "qianlei");
    map.put("displayName", "钱磊");
    map.code = 4321;
    b2.writeTo(map, os);
    byte[] b = os.toByteArray();
    System.out.println(b.length + ":" + Bytes.bytes2hex(b));
    map = b2.parseFrom(b);
    assertEquals(map.size(), 2);
    assertEquals(map.code, 4321);
    assertEquals(map.id, "feedback");
}
Also used : UnsafeByteArrayOutputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream) Test(org.junit.Test)

Example 12 with UnsafeByteArrayOutputStream

use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.

the class BuilderTest method testWithFC.

@Test
public void testWithFC() throws Exception {
    Builder<SimpleDO> builder = Builder.register(SimpleDO.class);
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    SimpleDO sd = new SimpleDO();
    sd.a = 1;
    sd.b = 2;
    sd.c = 3;
    sd.str1 = "12345";
    sd.str2 = "54321";
    builder.writeTo(sd, os);
    byte[] b = os.toByteArray();
    System.out.println(b.length + ":" + Bytes.bytes2hex(b));
    sd = builder.parseFrom(b);
    assertEquals(sd.a, 1);
    assertEquals(sd.b, 2);
    assertEquals(sd.c, 3);
    assertEquals(sd.str1, "124");
    System.out.println(sd.str2);
}
Also used : UnsafeByteArrayOutputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream) Test(org.junit.Test)

Example 13 with UnsafeByteArrayOutputStream

use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.

the class BuilderTest method testPrimaryTypeBuilder.

@Test
public void testPrimaryTypeBuilder() throws Exception {
    System.out.println((new byte[2]).hashCode());
    Builder<String> builder = Builder.register(String.class);
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    String v = "123";
    builder.writeTo(v, os);
    byte[] b = os.toByteArray();
    System.out.println(b.length + ":" + Bytes.bytes2hex(b));
    v = builder.parseFrom(b);
    builder.writeTo(v, os);
    b = os.toByteArray();
    System.out.println(b.length + ":" + Bytes.bytes2hex(b));
}
Also used : UnsafeByteArrayOutputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream) Test(org.junit.Test)

Example 14 with UnsafeByteArrayOutputStream

use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.

the class BuilderTest method testObjectArrayBuilder.

@Test
public void testObjectArrayBuilder() throws Exception {
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    Builder<Object[]> builder = Builder.register(Object[].class);
    Object[] obj = new Object[5];
    obj[0] = "1234";
    obj[1] = new Double(109.23);
    obj[2] = "3455";
    obj[3] = null;
    obj[4] = Boolean.TRUE;
    builder.writeTo(obj, os);
    byte[] b = os.toByteArray();
    System.out.println("Object array:" + b.length + ":" + Bytes.bytes2hex(b));
    Assert.assertArrayEquals(obj, builder.parseFrom(b));
}
Also used : UnsafeByteArrayOutputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream) Test(org.junit.Test)

Example 15 with UnsafeByteArrayOutputStream

use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.

the class DataInputOutputTest method testMain.

public void testMain() throws Exception {
    // write.
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    DataOutput cos = new GenericDataOutput(os);
    writeTest(cos);
    // read.
    byte[] b = os.toByteArray();
    DataInput cis = new GenericDataInput(new UnsafeByteArrayInputStream(b));
    readTest(cis);
}
Also used : DataInput(com.alibaba.dubbo.common.serialize.DataInput) GenericDataInput(com.alibaba.dubbo.common.serialize.support.dubbo.GenericDataInput) DataOutput(com.alibaba.dubbo.common.serialize.DataOutput) GenericDataOutput(com.alibaba.dubbo.common.serialize.support.dubbo.GenericDataOutput) GenericDataOutput(com.alibaba.dubbo.common.serialize.support.dubbo.GenericDataOutput) UnsafeByteArrayOutputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream) UnsafeByteArrayInputStream(com.alibaba.dubbo.common.io.UnsafeByteArrayInputStream) GenericDataInput(com.alibaba.dubbo.common.serialize.support.dubbo.GenericDataInput)

Aggregations

UnsafeByteArrayOutputStream (com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream)19 Test (org.junit.Test)13 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)3 Serialization (com.alibaba.dubbo.common.serialize.Serialization)3 UnsafeByteArrayInputStream (com.alibaba.dubbo.common.io.UnsafeByteArrayInputStream)2 IOException (java.io.IOException)2 JavaBeanDescriptor (com.alibaba.dubbo.common.beanutil.JavaBeanDescriptor)1 DataInput (com.alibaba.dubbo.common.serialize.DataInput)1 DataOutput (com.alibaba.dubbo.common.serialize.DataOutput)1 GenericDataInput (com.alibaba.dubbo.common.serialize.support.dubbo.GenericDataInput)1 GenericDataOutput (com.alibaba.dubbo.common.serialize.support.dubbo.GenericDataOutput)1 RemotingException (com.alibaba.dubbo.remoting.RemotingException)1 Response (com.alibaba.dubbo.remoting.exchange.Response)1 Result (com.alibaba.dubbo.rpc.Result)1 RpcException (com.alibaba.dubbo.rpc.RpcException)1 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)1 RpcResult (com.alibaba.dubbo.rpc.RpcResult)1 GenericException (com.alibaba.dubbo.rpc.service.GenericException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1