예제 #1
0
string easySerialize(const T& a) {
  BinaryProtocolWriter prot;

  size_t bufSize = a.serializedSize(&prot);
  folly::IOBufQueue queue;
  prot.setOutput(&queue, bufSize);
  a.write(&prot);

  auto buf = queue.move();
  buf->coalesce();

  return string(buf->data(), buf->tail());
}
예제 #2
0
TEST(CustomStructs, RoundTripContainer) {
  Container expected = createContainer();

  BinaryProtocolWriter protWriter;
  size_t bufSize = Cpp2Ops<Container>::serializedSize(&protWriter, &expected);
  folly::IOBufQueue queue;
  protWriter.setOutput(&queue, bufSize);
  Cpp2Ops<Container>::write(&protWriter, &expected);

  auto buf = queue.move();
  BinaryProtocolReader protReader;
  protReader.setInput(buf.get());
  Container actual;
  Cpp2Ops<Container>::read(&protReader, &actual);
  EXPECT_EQ(expected, actual);
}
예제 #3
0
TEST_P(RoundtripTestFixture, RoundtripDynamics) {
  const SerializableDynamic expected = GetParam();
  BinaryProtocolWriter protWriter;
  size_t bufSize = Cpp2Ops<SerializableDynamic>::serializedSize(
      &protWriter, &expected);
  folly::IOBufQueue queue;
  protWriter.setOutput(&queue, bufSize);
  Cpp2Ops<SerializableDynamic>::write(&protWriter, &expected);

  auto buf = queue.move();
  BinaryProtocolReader protReader;
  protReader.setInput(buf.get());
  SerializableDynamic actual;
  Cpp2Ops<SerializableDynamic>::read(&protReader, &actual);
  EXPECT_EQ(expected, actual) << "Expected: " << toJson(*expected)
                              << " Actual: " << toJson(*actual);
}
예제 #4
0
파일: UnionTest.cpp 프로젝트: Hsin/fbthrift
  void serializeDeserialize2(cpp2::TestUnion val) {
    BinaryProtocolWriter prot;
    size_t bufSize = cpp2::TestUnion_serializedSize(&prot, &val);
    IOBufQueue queue(IOBufQueue::cacheChainLength());

    prot.setOutput(&queue, bufSize);
    cpp2::TestUnion_write(&prot, &val);

    bufSize = queue.chainLength();
    auto buf = queue.move();

    cpp2::TestUnion out;
    BinaryProtocolReader protReader;
    protReader.setInput(buf.get());
    cpp2::TestUnion_read(&protReader, &out);
    EXPECT_EQ(val, out);
  }
예제 #5
0
TEST_P(RoundtripTestFixture, RoundtripContainer) {
  Container expected;
  expected.data = GetParam();

  BinaryProtocolWriter protWriter;
  size_t bufSize = Cpp2Ops<Container>::serializedSize(
      &protWriter, &expected);
  folly::IOBufQueue queue;
  protWriter.setOutput(&queue, bufSize);
  Cpp2Ops<Container>::write(&protWriter, &expected);

  auto buf = queue.move();
  BinaryProtocolReader protReader;
  protReader.setInput(buf.get());
  Container actual;
  Cpp2Ops<Container>::read(&protReader, &actual);
  EXPECT_EQ(expected, actual) << "Expected: " << toJson(*expected.data)
                              << " Actual: " << toJson(*actual.data);
}
TEST(QualifiedEnums, Defaults) {
  MyQualifiedStruct empty;

  BinaryProtocolWriter protWriter;
  size_t bufSize = Cpp2Ops<MyQualifiedStruct>::serializedSize(&protWriter,
                                                              &empty);
  folly::IOBufQueue queue;
  protWriter.setOutput(&queue, bufSize);
  Cpp2Ops<MyQualifiedStruct>::write(&protWriter, &empty);

  auto buf = queue.move();
  BinaryProtocolReader protReader;
  protReader.setInput(buf.get());
  MyQualifiedStruct actual;
  Cpp2Ops<MyQualifiedStruct>::read(&protReader, &actual);

  EXPECT_EQ(MyQualifiedEnum::BAR, actual.field1);
  EXPECT_EQ(MyQualifiedEnum::FOO, actual.field2);
  EXPECT_EQ(MyEnum1::ME1_1, actual.field3);
  EXPECT_EQ(MyEnum1::ME1_1, actual.field4);
  EXPECT_EQ(MyEnum4::ME4_A, actual.field5);
}