当前位置: 首页>>代码示例>>Java>>正文


Java Codec类代码示例

本文整理汇总了Java中com.baidu.bjf.remoting.protobuf.Codec的典型用法代码示例。如果您正苦于以下问题:Java Codec类的具体用法?Java Codec怎么用?Java Codec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Codec类属于com.baidu.bjf.remoting.protobuf包,在下文中一共展示了Codec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRequest

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Test
public void testRequest() {
	ReqLoginMessage request = new ReqLoginMessage();
	request.setAccountId(123456L);
	request.setPassword("kingston");
	Codec<ReqLoginMessage> simpleTypeCodec = ProtobufProxy
			.create(ReqLoginMessage.class);
	try {
		// 序列化
		byte[] bb = simpleTypeCodec.encode(request);
		// 反序列化
		ReqLoginMessage request2 = simpleTypeCodec.decode(bb);
		Assert.assertTrue(request2.getAccountId() == request.getAccountId());
		Assert.assertTrue(request2.getPassword().equals(request.getPassword()));
	} catch (IOException e) {
		e.printStackTrace();
	}

}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:20,代码来源:TestJProtobuf.java

示例2: testEncodeDecode

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Test
public void testEncodeDecode() {
    
    InterClassName icn = InterClassName.newBuilder().addList3("a").addList3("b").build();
    
    byte[] oldbb = icn.toByteArray();
    System.out.println(Arrays.toString(oldbb));
    
    
    RequrieRepeatedNumberTypePOJOClass type = new RequrieRepeatedNumberTypePOJOClass();
    
    type.list3 = new ArrayList<String>();
    type.list3.add("a");
    type.list3.add("b");
    
    
    Codec<RequrieRepeatedNumberTypePOJOClass> proxy = ProtobufProxy.create(RequrieRepeatedNumberTypePOJOClass.class);
    try {
        byte[] bb = proxy.encode(type);
        Assert.assertArrayEquals(oldbb, bb);
        System.out.println(Arrays.toString(bb));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:26,代码来源:RequrieRepeatedNumberTypeTest.java

示例3: testEncodeDecode

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Test
public void testEncodeDecode() {
    
    InterClassName icn = InterClassName.newBuilder().addList2(10000D).addList2(20000.1D).build();
    
    byte[] oldbb = icn.toByteArray();
    System.out.println(Arrays.toString(oldbb));
    
    
    RequrieRepeatedNumberTypePOJOClass3 type = new RequrieRepeatedNumberTypePOJOClass3();
    
    type.list2 = new ArrayList<Double>();
    type.list2.add(10000D);
    type.list2.add(20000.1D);
    
    
    Codec<RequrieRepeatedNumberTypePOJOClass3> proxy = ProtobufProxy.create(RequrieRepeatedNumberTypePOJOClass3.class);
    try {
        byte[] bb = proxy.encode(type);
        System.out.println(Arrays.toString(bb));
        Assert.assertArrayEquals(oldbb, bb);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:26,代码来源:RequrieRepeatedNumberType3Test.java

示例4: testEncodeDecode

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Test
public void testEncodeDecode() {
    
    InterClassName icn = InterClassName.newBuilder().addList1(10000).addList1(20000).build();
    
    byte[] oldbb = icn.toByteArray();
    System.out.println(Arrays.toString(oldbb));
    
    
    RequrieRepeatedNumberTypePOJOClass2 type = new RequrieRepeatedNumberTypePOJOClass2();
    
    type.list1 = new ArrayList<Integer>();
    type.list1.add(10000);
    type.list1.add(20000);
    
    
    Codec<RequrieRepeatedNumberTypePOJOClass2> proxy;
    proxy = ProtobufProxy.create(RequrieRepeatedNumberTypePOJOClass2.class, false);
    try {
        byte[] bb = proxy.encode(type);
        Assert.assertArrayEquals(oldbb, bb);
        System.out.println(Arrays.toString(bb));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:27,代码来源:RequrieRepeatedNumberType2Test.java

示例5: testSimpleMap

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Ignore
@Test
public void testSimpleMap() throws IOException {
    InputStream is = MapTypeIDLProxyTest.class.getResourceAsStream("simple-map.proto");
    IDLProxyObject idlProxyMap = ProtobufIDLProxy.createSingle(is);
    
    
    idlProxyMap.put("name", "hello");
    Map<String, String> map = new HashMap<String, String>();
    
    map.put("hello", "world");
    idlProxyMap.put("stringMap", map);
    
    byte[] bytes = idlProxyMap.encode();
    
    Codec<SimpleMapPOJO> codec = ProtobufProxy.create(SimpleMapPOJO.class);
    SimpleMapPOJO simpleMapPOJO = codec.decode(bytes);
    Assert.assertEquals("hello", simpleMapPOJO.name);
    Assert.assertEquals(1, simpleMapPOJO.getStringMap().size());
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:21,代码来源:MapTypeIDLProxyTest.java

示例6: testSimplePOJO

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Test
public void testSimplePOJO() {
    
    Codec<SimplePOJO> codec = ProtobufProxy.create(SimplePOJO.class);
    
    SimplePOJO  target = new SimplePOJO();
    
    IDLProxyObject idlProxyObject = new IDLProxyObject(codec, target, SimplePOJO.class);
    
    idlProxyObject.put("name", "hello");
    Assert.assertEquals("hello", idlProxyObject.get("name"));
    Assert.assertEquals("hello", target.getName());
    Assert.assertEquals("hello", ((SimplePOJO) idlProxyObject.getTarget()).getName());
    
    
    idlProxyObject.put("age", 100);
    Assert.assertEquals(100, idlProxyObject.get("age"));
    Assert.assertEquals(100, target.getAge());
    Assert.assertEquals(100, ((SimplePOJO) idlProxyObject.getTarget()).getAge());
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:21,代码来源:IDLProxyObjectTest.java

示例7: testComplexPOJO

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Test
public void testComplexPOJO() {
    Codec<ComplexPOJO> codec = ProtobufProxy.create(ComplexPOJO.class);
    
    ComplexPOJO  target = new ComplexPOJO();
    
    IDLProxyObject idlProxyObject = new IDLProxyObject(codec, target, ComplexPOJO.class);
    
    idlProxyObject.put("name", "hello");
    Assert.assertEquals("hello", idlProxyObject.get("name"));
    Assert.assertEquals("hello", target.getName());
    Assert.assertEquals("hello", ((ComplexPOJO) idlProxyObject.getTarget()).getName());
    
    
    idlProxyObject.put("age", 100);
    Assert.assertEquals(100, idlProxyObject.get("age"));
    Assert.assertEquals(100, target.getAge());
    Assert.assertEquals(100, ((ComplexPOJO) idlProxyObject.getTarget()).getAge());
    
    //test sub
    idlProxyObject.put("simplePOJO.name", "hello");
    Assert.assertEquals("hello", idlProxyObject.get("simplePOJO.name"));
    Assert.assertEquals("hello", target.getSimplePOJO().getName());
    Assert.assertEquals("hello", ((ComplexPOJO) idlProxyObject.getTarget()).getSimplePOJO().getName());
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:26,代码来源:IDLProxyObjectTest.java

示例8: getProtoBytes2

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
private byte[] getProtoBytes2() throws IOException {
    Codec<SimpleMapPOJO> simpleMapPojoCodec = ProtobufProxy.create(SimpleMapPOJO.class, false);

    // initialize map
    SimpleMapPOJO pojo = new SimpleMapPOJO();
    pojo.name = "xiemalin";

    Map<String, String> stringMap = new HashMap<String, String>();
    stringMap.put("hello", "world");
    stringMap.put("welcome", "China");
    pojo.setStringMap(stringMap);

    Map<Integer, Integer> intMap = new HashMap<Integer, Integer>();
    intMap.put(100, 200);
    pojo.setMyIntMap(intMap);

    pojo.longMap = new HashMap<Long, Long>();
    pojo.longMap.put(Long.MIN_VALUE, Long.MAX_VALUE);

    pojo.booleanMap = new HashMap<Boolean, Boolean>();
    pojo.booleanMap.put(Boolean.TRUE, Boolean.FALSE);

    byte[] bytes = simpleMapPojoCodec.encode(pojo);
    return bytes;
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:26,代码来源:SimpleMapTest.java

示例9: testEnum

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Test
public void testEnum() throws IOException {
    
    
    Codec<EnumPOJOClass> codec = ProtobufProxy.create(EnumPOJOClass.class, false);
    EnumPOJOClass ec = new EnumPOJOClass();
    ec.enumAttr = EnumAttrPOJO.INT;
    
    byte[] bytes = codec.encode(ec);
    System.out.println(Arrays.toString(bytes));
    EnumPOJOClass decode = codec.decode(bytes);
    Assert.assertEquals(EnumAttrPOJO.INT, decode.enumAttr);
    
    byte[] byteArray = EnumClassInternal.newBuilder().setStatus(
            com.baidu.bjf.remoting.protobuf.enumeration.EnumClass.EnumAttr.INT).build().toByteArray();
    Assert.assertArrayEquals(bytes, byteArray);
    
    EnumClassInternal enumClass = com.baidu.bjf.remoting.protobuf.enumeration.EnumClass.EnumClassInternal.parseFrom(bytes);
 
    Assert.assertEquals(com.baidu.bjf.remoting.protobuf.enumeration.EnumClass.EnumAttr.INT, enumClass.getStatus());
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:22,代码来源:EnumClassTest.java

示例10: testEnum2

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Test
public void testEnum2() throws IOException {
    
    
    Codec<EnumPOJOClass2> codec = ProtobufProxy.create(EnumPOJOClass2.class);
    EnumPOJOClass2 ec = new EnumPOJOClass2();
    ec.setEnumAttr(EnumAttrPOJO.INT);
    
    byte[] bytes = codec.encode(ec);
    EnumPOJOClass2 decode = codec.decode(bytes);
    Assert.assertEquals(EnumAttrPOJO.INT, decode.getEnumAttr());
    
    byte[] byteArray = EnumClassInternal.newBuilder().setStatus(
            com.baidu.bjf.remoting.protobuf.enumeration.EnumClass.EnumAttr.INT).build().toByteArray();
    Assert.assertArrayEquals(bytes, byteArray);
    EnumClassInternal enumClass = com.baidu.bjf.remoting.protobuf.enumeration.EnumClass.EnumClassInternal.parseFrom(bytes);
 
    Assert.assertEquals(com.baidu.bjf.remoting.protobuf.enumeration.EnumClass.EnumAttr.INT, enumClass.getStatus());
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:20,代码来源:EnumClassTest.java

示例11: getProtoBytes2

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
private byte[] getProtoBytes2() throws IOException {
    Codec<AddressBookProtosPOJO> simpleMapPojoCodec = ProtobufProxy.create(AddressBookProtosPOJO.class, false);

    // initialize

    AddressBookProtosPOJO addressBook = new AddressBookProtosPOJO();
    List<PersonPOJO> list = new ArrayList<PersonPOJO>();
    addressBook.setList(list);

    PersonPOJO pojo = new PersonPOJO();
    pojo.name = "xiemalin";
    pojo.id = 100;
    list.add(pojo);

    byte[] bytes = simpleMapPojoCodec.encode(addressBook);
    return bytes;
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:18,代码来源:DescritporTest.java

示例12: testGetDescriptor

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
@Test
public void testGetDescriptor() throws IOException {
    Descriptor descriptor2 = AddressBookProtos.AddressBook.getDescriptor();

    FieldDescriptor stringMapFD = descriptor2.findFieldByName("person");
    byte[] bytes = getProtoBytes2();
    DynamicMessage parseFrom = DynamicMessage.parseFrom(descriptor2, bytes);
    Object field = parseFrom.getField(stringMapFD);
    Assert.assertTrue(field instanceof List);
    
    Codec<AddressBookProtosPOJO> codec = ProtobufProxy.create(AddressBookProtosPOJO.class, false);
    Descriptor descriptor = codec.getDescriptor();
    
    stringMapFD = descriptor.findFieldByName("list");

    bytes = getProtoBytes2();

    parseFrom = DynamicMessage.parseFrom(descriptor, bytes);

    Object field2 = parseFrom.getField(stringMapFD);
    Assert.assertTrue(field2 instanceof List);

}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:24,代码来源:DescritporTest.java

示例13: testEncodeDecode

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
/**
 * Test encode decode.
 */
@Test
public void testEncodeDecode() {
    
    InterClassName icn = InterClassName.newBuilder().addList3("a").addList3("b").build();
    
    byte[] oldbb = icn.toByteArray();
    System.out.println(Arrays.toString(oldbb));
    
    
    RequrieRepeatedNumberTypePOJOClass type = new RequrieRepeatedNumberTypePOJOClass();
    
    type.list3 = new ArrayList<String>();
    type.list3.add("a");
    type.list3.add("b");
    
    
    Codec<RequrieRepeatedNumberTypePOJOClass> proxy = ProtobufProxy.create(RequrieRepeatedNumberTypePOJOClass.class);
    try {
        byte[] bb = proxy.encode(type);
        Assert.assertArrayEquals(oldbb, bb);
        System.out.println(Arrays.toString(bb));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:29,代码来源:RequrieRepeatedNumberTypeTest.java

示例14: testEncodeDecode

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
/**
 * Test encode decode.
 */
@Test
public void testEncodeDecode() {
    
    InterClassName icn = InterClassName.newBuilder().addList2(10000D).addList2(20000.1D).build();
    
    byte[] oldbb = icn.toByteArray();
    System.out.println(Arrays.toString(oldbb));
    
    
    RequrieRepeatedNumberTypePOJOClass3 type = new RequrieRepeatedNumberTypePOJOClass3();
    
    type.list2 = new ArrayList<Double>();
    type.list2.add(10000D);
    type.list2.add(20000.1D);
    
    
    Codec<RequrieRepeatedNumberTypePOJOClass3> proxy = ProtobufProxy.create(RequrieRepeatedNumberTypePOJOClass3.class);
    try {
        byte[] bb = proxy.encode(type);
        System.out.println(Arrays.toString(bb));
        Assert.assertArrayEquals(oldbb, bb);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:29,代码来源:RequrieRepeatedNumberType3Test.java

示例15: main

import com.baidu.bjf.remoting.protobuf.Codec; //导入依赖的package包/类
/**
 * The main method.
 *
 * @param args the arguments
 */
public static void main(String[] args) {
    A a = new A();
    a.a = 100;
    a.b = 200;
    
    Codec<A> codec = ProtobufProxy.create(A.class);
    try {
        byte[] encode = codec.encode(a);
        System.out.println(Arrays.toString(encode));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:21,代码来源:ByteTypeTest.java


注:本文中的com.baidu.bjf.remoting.protobuf.Codec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。