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