Java Code Examples for com.alibaba.dubbo.common.serialize.support.dubbo.Builder#parseFrom()

The following examples show how to use com.alibaba.dubbo.common.serialize.support.dubbo.Builder#parseFrom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuilderTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Ignore
   @Test
   @SuppressWarnings({ "rawtypes", "unchecked" })
   public void testBuilder_MyList() throws Exception
{
       Builder<MyList> b1 = Builder.register(MyList.class);
	MyList list = new MyList();
	list.add(new boolean[]{ true,false });
	list.add(new int[]{ 1,2,3,4,5 });
	list.add("String");
	list.add(4);
	list.code = 4321;
	
	UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
	b1.writeTo(list, os);
	byte[] b = os.toByteArray();
	System.out.println(b.length+":"+Bytes.bytes2hex(b));
	MyList result = b1.parseFrom(b);

	assertEquals(4, result.size());
	assertEquals(result.code, 4321);
	assertEquals(result.id, "feedback");
}
 
Example 2
Source File: SerializationCompareTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuilderPerm() throws Exception
{
	Builder<Bean> bb = Builder.register(Bean.class);
	Bean bean = new Bean();
	int len = 0;
	long now = System.currentTimeMillis();
	for(int i=0;i<500;i++)
	{
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		bb.writeTo(bean, os);
		os.close();
		if( i == 0 )
			len = os.toByteArray().length;
		
		ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
		Bean b = bb.parseFrom(is);
		assertEquals(b.getClass(), Bean.class);
	}
	System.out.println("Builder write and parse 500 times in " + (System.currentTimeMillis()-now)+"ms, size " + len);
}
 
Example 3
Source File: BuilderTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 4
Source File: BuilderTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 5
Source File: BuilderTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example 6
Source File: BuilderTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@Ignore
   @Test
   @SuppressWarnings({ "rawtypes", "unchecked" })
   public void testBuilder_MyList() throws Exception
{
       Builder<MyList> b1 = Builder.register(MyList.class);
	MyList list = new MyList();
	list.add(new boolean[]{ true,false });
	list.add(new int[]{ 1,2,3,4,5 });
	list.add("String");
	list.add(4);
	list.code = 4321;
	
	UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
	b1.writeTo(list, os);
	byte[] b = os.toByteArray();
	System.out.println(b.length+":"+Bytes.bytes2hex(b));
	MyList result = b1.parseFrom(b);

	assertEquals(4, result.size());
	assertEquals(result.code, 4321);
	assertEquals(result.id, "feedback");
}
 
Example 7
Source File: BuilderTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 8
Source File: BuilderTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@Ignore
   @Test
   @SuppressWarnings({ "rawtypes", "unchecked" })
   public void testBuilder_MyList() throws Exception
{
       Builder<MyList> b1 = Builder.register(MyList.class);
	MyList list = new MyList();
	list.add(new boolean[]{ true,false });
	list.add(new int[]{ 1,2,3,4,5 });
	list.add("String");
	list.add(4);
	list.code = 4321;
	
	UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
	b1.writeTo(list, os);
	byte[] b = os.toByteArray();
	System.out.println(b.length+":"+Bytes.bytes2hex(b));
	MyList result = b1.parseFrom(b);

	assertEquals(4, result.size());
	assertEquals(result.code, 4321);
	assertEquals(result.id, "feedback");
}
 
Example 9
Source File: BuilderTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example 10
Source File: SerializationCompareTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuilderPerm() throws Exception
{
	Builder<Bean> bb = Builder.register(Bean.class);
	Bean bean = new Bean();
	int len = 0;
	long now = System.currentTimeMillis();
	for(int i=0;i<500;i++)
	{
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		bb.writeTo(bean, os);
		os.close();
		if( i == 0 )
			len = os.toByteArray().length;
		
		ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
		Bean b = bb.parseFrom(is);
		assertEquals(b.getClass(), Bean.class);
	}
	System.out.println("Builder write and parse 500 times in " + (System.currentTimeMillis()-now)+"ms, size " + len);
}
 
Example 11
Source File: BuilderTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example 12
Source File: BuilderTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Ignore
   @Test
   @SuppressWarnings({ "rawtypes", "unchecked" })
   public void testBuilder_MyList() throws Exception
{
       Builder<MyList> b1 = Builder.register(MyList.class);
	MyList list = new MyList();
	list.add(new boolean[]{ true,false });
	list.add(new int[]{ 1,2,3,4,5 });
	list.add("String");
	list.add(4);
	list.code = 4321;
	
	UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
	b1.writeTo(list, os);
	byte[] b = os.toByteArray();
	System.out.println(b.length+":"+Bytes.bytes2hex(b));
	MyList result = b1.parseFrom(b);

	assertEquals(4, result.size());
	assertEquals(result.code, 4321);
	assertEquals(result.id, "feedback");
}
 
Example 13
Source File: BuilderTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 14
Source File: SerializationCompareTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuilderPerm() throws Exception
{
	Builder<Bean> bb = Builder.register(Bean.class);
	Bean bean = new Bean();
	int len = 0;
	long now = System.currentTimeMillis();
	for(int i=0;i<500;i++)
	{
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		bb.writeTo(bean, os);
		os.close();
		if( i == 0 )
			len = os.toByteArray().length;
		
		ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
		Bean b = bb.parseFrom(is);
		assertEquals(b.getClass(), Bean.class);
	}
	System.out.println("Builder write and parse 500 times in " + (System.currentTimeMillis()-now)+"ms, size " + len);
}
 
Example 15
Source File: BuilderTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 16
Source File: BuilderTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 17
Source File: BuilderTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 18
Source File: BuilderTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 19
Source File: BuilderTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 20
Source File: BuilderTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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);
}