本文整理匯總了Java中com.baidu.bjf.remoting.protobuf.Codec.decode方法的典型用法代碼示例。如果您正苦於以下問題:Java Codec.decode方法的具體用法?Java Codec.decode怎麽用?Java Codec.decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.baidu.bjf.remoting.protobuf.Codec
的用法示例。
在下文中一共展示了Codec.decode方法的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();
}
}
示例2: 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());
}
示例3: 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());
}
示例4: 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());
}
示例5: 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());
}
示例6: testEncodeDecode
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
/**
* Test encode decode.
*/
@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<StringTypePOJOClass> codec = ProtobufProxy.create(StringTypePOJOClass.class);
try {
byte[] bb = codec.encode(pojo);
System.out.println(Arrays.toString(bb));
Assert.assertArrayEquals(byteArray, bb);
StringTypePOJOClass newPojo = codec.decode(bb);
System.out.println(newPojo.getStr());
Assert.assertEquals("你好!", newPojo.getStr());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例7: deserialize
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
@Override
public <T> T deserialize(byte[] src, Class<T> cls) {
Codec<T> codec = ProtobufProxy.create(cls);
try {
return codec.decode(src);
} catch (IOException e) {
throw new IllegalArgumentException("deserialize error", e);
}
}
示例8: readMessage
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
private Message readMessage(short module, short cmd, byte[] body) {
Class<?> msgClazz = MessageFactory.INSTANCE.getMessage(module, cmd);
try {
Codec<?> codec = ProtobufProxy.create(msgClazz);
Message message = (Message) codec.decode(body);
return message;
} catch (IOException e) {
logger.error("讀取消息出錯,模塊號{},類型{},異常{}", new Object[]{module, cmd ,e});
}
return null;
}
示例9: asMessage
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
public static Message asMessage(Packet packet) {
Class<?> msgClazz = MessageFactory.INSTANCE.getMessage((short)packet.module, (short)packet.cmd);
try {
Codec<?> codec = ProtobufProxy.create(msgClazz);
Message message = (Message) codec.decode(packet.body);
return message;
} catch (IOException e) {
logger.error("讀取消息出錯,模塊號{},類型{},異常{}", new Object[]{packet.module, packet.cmd} );
}
return null;
}
示例10: testDecodeListFields2
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
@Test
public void testDecodeListFields2() throws IOException {
InterClassName icn = InterClassName.newBuilder().addList("abc").build();
byte[] byteArray = icn.toByteArray();
Codec<RequrieRepeatedDojoClass2> create = ProtobufProxy.create(RequrieRepeatedDojoClass2.class);
RequrieRepeatedDojoClass2 decode = create.decode(byteArray);
Assert.assertEquals(1, decode.getList().size());
Assert.assertEquals("abc", decode.getList().get(0));
}
示例11: testDecodeListFields2
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
/**
* Test decode list fields2.
*
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
public void testDecodeListFields2() throws IOException {
InterClassName icn = InterClassName.newBuilder().addList("abc").build();
byte[] byteArray = icn.toByteArray();
Codec<RequrieRepeatedDojoClass2> create = ProtobufProxy.create(RequrieRepeatedDojoClass2.class);
RequrieRepeatedDojoClass2 decode = create.decode(byteArray);
Assert.assertEquals(1, decode.getList().size());
Assert.assertEquals("abc", decode.getList().get(0));
}
示例12: testDecodeListFields
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
@Test
public void testDecodeListFields() throws IOException {
InterClassName icn = InterClassName.newBuilder().addList("abc").build();
byte[] byteArray = icn.toByteArray();
Codec<RequrieRepeatedDojoClass> create = ProtobufProxy.create(RequrieRepeatedDojoClass.class);
RequrieRepeatedDojoClass decode = create.decode(byteArray);
Assert.assertEquals(1, decode.list.size());
Assert.assertEquals("abc", decode.list.get(0));
}
示例13: testEnumIDLProxy
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
/**
* Test enum idl proxy.
*
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
public void testEnumIDLProxy() throws IOException {
String idl = ProtobufIDLGenerator.getIDL(EnumPOJOClass.class);
IDLProxyObject idlProxyObject = ProtobufIDLProxy.createSingle(idl);
idlProxyObject.put("enumAttr", "STRING");
byte[] bytes = idlProxyObject.encode();
Codec<EnumPOJOClass> codec = ProtobufProxy.create(EnumPOJOClass.class);
EnumPOJOClass enumPOJOClass = codec.decode(bytes);
Assert.assertEquals(enumPOJOClass.enumAttr.value(), EnumAttrPOJO.STRING.value());
}
示例14: testTypeClass3
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
@Test
public void testTypeClass3() throws IOException {
Codec<ByteTypeClass3> codec = ProtobufProxy.create(ByteTypeClass3.class);
ByteTypeClass3 o = new ByteTypeClass3();
o.setBytes(new byte[] {1, 2});
byte[] bb = codec.encode(o);
ByteTypeClass3 class1 = codec.decode(bb);
Assert.assertArrayEquals(o.getBytes(), class1.getBytes());
}
示例15: testDecodeListFields2
import com.baidu.bjf.remoting.protobuf.Codec; //導入方法依賴的package包/類
@Test
public void testDecodeListFields2() throws IOException {
InterClassName icn = InterClassName.newBuilder().addList("abc").build();
byte[] byteArray = icn.toByteArray();
Codec create = ProtobufProxy.create(RequrieRepeatedDojoClass2.class);
RequrieRepeatedDojoClass2 decode = (RequrieRepeatedDojoClass2) create.decode(byteArray);
Assert.assertEquals(1, decode.getList().size());
Assert.assertEquals("abc", decode.getList().get(0));
}