use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.
the class BuilderTest method testEnumBuilder.
@Test
public void testEnumBuilder() throws Exception {
Builder<Type> builder = Builder.register(Type.class);
UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
Type v = Type.High;
builder.writeTo(v, os);
byte[] b = os.toByteArray();
System.out.println(b.length + ":" + Bytes.bytes2hex(b));
v = builder.parseFrom(b);
}
use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.
the class BuilderTest method testSerializableBean.
@Test
@SuppressWarnings("unchecked")
public void testSerializableBean() throws Exception {
System.out.println("testSerializableBean");
UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
SerializableBean sb = new SerializableBean();
Builder<SerializableBean> sbb = Builder.register(SerializableBean.class);
sbb.writeTo(sb, os);
byte[] b = os.toByteArray();
System.out.println(b.length + ":" + Bytes.bytes2hex(b));
assertEquals(sbb.parseFrom(os.toByteArray()), sb);
}
use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.
the class BuilderTest method testThrowableBuilder.
@Test
public void testThrowableBuilder() throws Exception {
Builder<Throwable> builder = Builder.register(Throwable.class);
Throwable th = new Throwable();
UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
builder.writeTo(th, os);
byte[] b = os.toByteArray();
System.out.println(b.length + ":" + Bytes.bytes2hex(b));
th = builder.parseFrom(b);
}
use of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream in project dubbo by alibaba.
the class BuilderTest method testInterfaceBuilder.
@Test
public void testInterfaceBuilder() throws Exception {
UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
Builder<TestDO> builder = Builder.register(TestDO.class);
TestDO d = new TestDOImpl();
builder.writeTo(d, os);
byte[] b = os.toByteArray();
d = builder.parseFrom(b);
assertTrue(TestDO.class.isAssignableFrom(d.getClass()));
assertEquals("name", d.getName());
assertEquals(28, d.getArg());
assertEquals(Type.High, d.getType());
}
Aggregations