本文整理汇总了Java中com.alibaba.dubbo.common.serialize.support.dubbo.Builder.parseFrom方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.parseFrom方法的具体用法?Java Builder.parseFrom怎么用?Java Builder.parseFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.common.serialize.support.dubbo.Builder
的用法示例。
在下文中一共展示了Builder.parseFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBuilderPerm
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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);
}
示例2: testBuilder_MyList
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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");
}
示例3: testInterfaceBuilder
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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());
}
示例4: testBuilder_MyMap
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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");
}
示例5: testBuilder_MyList
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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");
}
示例6: testBuilder_MyMap
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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");
}
示例7: testBuilderPerm
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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);
}
示例8: testPrimaryTypeBuilder
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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));
}
示例9: testThrowableBuilder
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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);
}
示例10: testObjectBuilder
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@Test
public void testObjectBuilder() throws Exception
{
UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
Builder<Bean> BeanBuilder = Builder.register(Bean.class);
Bean bean = new Bean();
bean.name = "ql";
bean.type = Type.High;
bean.types = new Type[]{ Type.High, Type.High };
BeanBuilder.writeTo(bean, os);
byte[] b = os.toByteArray();
System.out.println(b.length+":"+Bytes.bytes2hex(b));
bean = BeanBuilder.parseFrom(b);
assertNull(bean.time);
assertEquals(bean.i, 123123);
assertEquals(bean.ni, -12344);
assertEquals(bean.d, 12.345);
assertEquals(bean.nd, -12.345);
assertEquals(bean.l, 1281447759383l);
assertEquals(bean.nl, -13445l);
assertEquals(bean.vl, 100l);
assertEquals(bean.type, Type.High);
assertEquals(bean.types.length, 2);
assertEquals(bean.types[0], Type.High);
assertEquals(bean.types[1], Type.High);
assertEquals(bean.list.size(), 3);
assertEquals(bean.list.get(0), 1);
assertEquals(bean.list.get(1), 2);
assertEquals(bean.list.get(2), 1308147);
}
示例11: testEnumBuilder
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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);
}
示例12: testGenericBuilder
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@Test
public void testGenericBuilder() throws Exception
{
UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
Builder<Object> ob = Builder.register(Object.class);
Object o = new Object();
ob.writeTo(o, os);
byte[] b = os.toByteArray();
os = new UnsafeByteArrayOutputStream();
Bean bean = new Bean();
bean.name = "ql";
bean.type = Type.High;
bean.types = new Type[]{ Type.High, Type.High };
ob.writeTo(bean, os);
b = os.toByteArray();
bean = (Bean)ob.parseFrom(b);
assertEquals(bean.i, 123123);
assertEquals(bean.ni, -12344);
assertEquals(bean.d, 12.345);
assertEquals(bean.nd, -12.345);
assertEquals(bean.l, 1281447759383l);
assertEquals(bean.nl, -13445l);
assertEquals(bean.vl, 100l);
assertEquals(bean.type, Type.High);
assertEquals(bean.types.length, 2);
assertEquals(bean.types[0], Type.High);
assertEquals(bean.types[1], Type.High);
assertEquals(bean.list.size(), 3);
assertEquals(bean.list.get(0), 1);
assertEquals(bean.list.get(1), 2);
assertEquals(bean.list.get(2), 1308147);
}
示例13: testEnumBuilder
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@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);
}
示例14: testGenericBuilder
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@Test
public void testGenericBuilder() throws Exception {
UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
Builder<Object> ob = Builder.register(Object.class);
Object o = new Object();
ob.writeTo(o, os);
byte[] b = os.toByteArray();
os = new UnsafeByteArrayOutputStream();
Bean bean = new Bean();
bean.name = "ql";
bean.type = Type.High;
bean.types = new Type[]{Type.High, Type.High};
ob.writeTo(bean, os);
b = os.toByteArray();
bean = (Bean) ob.parseFrom(b);
assertEquals(bean.i, 123123);
assertEquals(bean.ni, -12344);
assertEquals(bean.d, 12.345);
assertEquals(bean.nd, -12.345);
assertEquals(bean.l, 1281447759383l);
assertEquals(bean.nl, -13445l);
assertEquals(bean.vl, 100l);
assertEquals(bean.type, Type.High);
assertEquals(bean.types.length, 2);
assertEquals(bean.types[0], Type.High);
assertEquals(bean.types[1], Type.High);
assertEquals(bean.list.size(), 3);
assertEquals(bean.list.get(0), 1);
assertEquals(bean.list.get(1), 2);
assertEquals(bean.list.get(2), 1308147);
}
示例15: testOthers
import com.alibaba.dubbo.common.serialize.support.dubbo.Builder; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testOthers() throws Exception
{
UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
StringBuffer buf = new StringBuffer();
for(int i=0;i<1024*32+32;i++)
buf.append('A');
Builder<String> sb = Builder.register(String.class);
sb.writeTo(buf.toString(), os);
assertEquals(sb.parseFrom(os.toByteArray()), buf.toString());
os = new UnsafeByteArrayOutputStream();
Builder<HashMap> builder = Builder.register(HashMap.class);
Map services = new HashMap();
HashMap map = new HashMap();
services.put("test.service", "http://127.0.0.1:9010/test.service");
map.put("name", "qianlei");
map.put("password", "123455");
map.put("services", services);
builder.writeTo(map, os);
byte[] b = os.toByteArray();
System.out.println(b.length+":"+Bytes.bytes2hex(b));
map = builder.parseFrom(b);
assertTrue(map.size() > 0);
assertEquals("http://127.0.0.1:9010/test.service", ((Map) map.get("services")).get("test.service"));
services = new ConcurrentHashMap();
services.put("test.service", "http://127.0.0.1:9010/test.service");
map.put("services", services);
os = new UnsafeByteArrayOutputStream();
builder.writeTo(map, os);
b = os.toByteArray();
System.out.println(b.length+":"+Bytes.bytes2hex(b));
map = builder.parseFrom(b);
assertTrue(map.size() > 0);
assertEquals("http://127.0.0.1:9010/test.service", ((Map) map.get("services")).get("test.service"));
Node node1 = new Node();
Node node0 = new Node();
node0.value = "0";
node0.next = node1;
node1.value = "1";
node1.prev = node0;
// write.
Builder<Node> nodebuilder = Builder.register(Node.class);
os = new UnsafeByteArrayOutputStream();
nodebuilder.writeTo(node0, os);
b = os.toByteArray();
System.out.println("Node:"+b.length+":"+Bytes.bytes2hex(b));
// parse
node0 = nodebuilder.parseFrom(b);
assertEquals(node0, node0.prev);
assertEquals(node0, node0.next.prev);
assertEquals(node0.value, "0");
}