コード例 #1
0
  /*
   * (non-Javadoc)
   *
   * @see com.baidu.jprotobuf.pbrpc.RpcHandler#doRealHandle(byte[])
   */
  protected RpcData doRealHandle(RpcData data) throws Exception {
    Object input = null;
    Object[] param;
    Object ret = null;
    if (data.getData() != null && inputCodec != null) {
      input = inputCodec.decode(data.getData());
      param = new Object[] {input};
    } else {
      param = new Object[0];
    }

    RpcData retData = new RpcData();
    // process attachment
    if (getAttachmentHandler() != null) {
      byte[] responseAttachment =
          getAttachmentHandler()
              .handleAttachement(data.getAttachment(), getServiceName(), getMethodName(), param);
      retData.setAttachment(responseAttachment);
    }

    ret = getMethod().invoke(getService(), param);
    if (ret == null) {
      return retData;
    }

    if (outputCodec != null) {
      byte[] response = outputCodec.encode(ret);
      retData.setData(response);
    }

    return retData;
  }
コード例 #2
0
  /** 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();
    }
  }