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


Java Codec.encode方法代码示例

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


在下文中一共展示了Codec.encode方法的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().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 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

示例5: 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 proxy;
    proxy = ProtobufProxy.create(RequrieRepeatedNumberTypePOJOClass2.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,代码行数:27,代码来源:RequrieRepeatedNumberType2Test.java

示例6: testEnum2

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
/**
 * Test enum2.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@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,代码行数:25,代码来源:EnumClassTest.java

示例7: testEnum2

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
@Test
public void testEnum2() throws IOException {
    
    
    Codec codec = ProtobufProxy.create(EnumPOJOClass2.class);
    EnumPOJOClass2 ec = new EnumPOJOClass2();
    ec.setEnumAttr(EnumAttrPOJO.INT);
    
    byte[] bytes = codec.encode(ec);
    EnumPOJOClass2 decode = (EnumPOJOClass2) 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

示例8: testEncodeDecode

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
@Test
public void testEncodeDecode() {
    
    StringMessage message = StringMessage.newBuilder().setList("你好!").build();
    
    byte[] byteArray = message.toByteArray();
    System.out.println(Arrays.toString(byteArray));
    
    StringTypePOJOClass pojo = new StringTypePOJOClass();
    pojo.setStr("你好!");
    
    Codec codec = ProtobufProxy.create(StringTypePOJOClass.class);
    try {
        byte[] bb = codec.encode(pojo);
        System.out.println(Arrays.toString(bb));
        Assert.assertArrayEquals(byteArray, bb);
        
        StringTypePOJOClass newPojo = (StringTypePOJOClass) codec.decode(bb);
        System.out.println(newPojo.getStr());
        Assert.assertEquals("你好!", newPojo.getStr());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:26,代码来源:StringTypeClassTest.java

示例9: serialize

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
@Override
public byte[] serialize(Object o) {
	Codec codec = ProtobufProxy.create(o.getClass());
	try {
		return codec.encode(o);
	} catch (IOException e) {
		throw new IllegalArgumentException("serialize error", e);
	}
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:10,代码来源:ProtobufRedisSerializer.java

示例10: wrapMessageBody

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
private byte[] wrapMessageBody(short module, short cmd, Message message) {
	//写入具体消息的内容
	byte[] body = null;
	@SuppressWarnings("unchecked")
	Class<Message> msgClazz = (Class<Message>) MessageFactory.INSTANCE.getMessage(module, cmd);
	try {
		Codec<Message> codec = ProtobufProxy.create(msgClazz);
		body = codec.encode(message);
	} catch (IOException e) {
		logger.error("", e);
	}
	return body;
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:14,代码来源:MessageEncoder.java

示例11: valueOf

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
public static Packet valueOf(Message message) {
	Packet packet  = new Packet();
	packet.module = message.getModule();
	packet.cmd        = message.getCmd();
	try {
		Codec codec = ProtobufProxy.create(message.getClass());
		packet.body = codec.encode(message);
	}catch (Exception e){
		throw new IllegalArgumentException("parse packet attachment failed",e);
	}

	return packet;
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:14,代码来源:Packet.java

示例12: testTypeClass2

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
@Test
public void testTypeClass2() throws IOException  {
    Codec codec = ProtobufProxy.create(ByteTypeClass2.class);
    
    ByteTypeClass2 o = new ByteTypeClass2();
    o.bytes = new byte[] {1, 2};
    byte[] bb = codec.encode(o);
    
    ByteTypeClass2 class1 = (ByteTypeClass2) codec.decode(bb);
    Assert.assertArrayEquals(o.bytes, class1.bytes);
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:12,代码来源:ByteTypeTest.java

示例13: testTypeClass3

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
@Test
public void testTypeClass3() throws IOException  {
    Codec codec = ProtobufProxy.create(ByteTypeClass3.class);
    
    ByteTypeClass3 o = new ByteTypeClass3();
    o.setBytes(new byte[] {1, 2});
    byte[] bb = codec.encode(o);
    
    ByteTypeClass3 class1 = (ByteTypeClass3) codec.decode(bb);
    Assert.assertArrayEquals(o.getBytes(), class1.getBytes());
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:12,代码来源:ByteTypeTest.java

示例14: testEncodeDecode

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
/**
 * Test encode decode.
 */
@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,代码行数:30,代码来源:RequrieRepeatedNumberType2Test.java

示例15: testDynamiceEncode

import com.baidu.bjf.remoting.protobuf.Codec; //导入方法依赖的package包/类
/**
 * Test dynamice encode.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testDynamiceEncode() throws IOException {
    long time = System.currentTimeMillis();
    Codec<AllTypesDojoClass> dojoClassProxy = ProtobufProxy.create(AllTypesDojoClass.class);
    //AllTypesDojoClass$$BJFProtoBufClass dojoClassProxy = new AllTypesDojoClass$$BJFProtoBufClass();
    AllTypesDojoClass c = new AllTypesDojoClass();
    c.boolF = false;
    c.bytesF = new byte[] {1,2};
    c.doubleF = 101D;
    c.fixed32F = 1;
    c.fixed64F = 2L;
    c.floatF = 102F;
    c.int32F = 3;
    c.int64F = 4L;
    c.sfixed32F = 5;
    c.sfixed64F = 6L;
    c.sint32F = 7;
    c.sint64F = 8L;
    c.stringF = "hello";
    c.uint32F = 9;
    c.uint64F = 10L;
    
    long averageEncode = 0;
    
    for (int i = 0; i < times; i++) {
        byte[] bb = dojoClassProxy.encode(c);
        
    }
    averageEncode = System.currentTimeMillis() - time;
    System.out.println("dynamic encode average time:" + (averageEncode / times));
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:37,代码来源:AllTypesPressureTest.java


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