Exemplo n.º 1
0
TEST(byte_buffer, assign) {
  const char s1[] = "hogehoge";
  const char s2[] = "fuga";
  const char s3[] = "hehehe";

  // for empty byte_buffers
  byte_buffer buf;
  buf.assign(s1, sizeof(s1));
  EXPECT_EQ(sizeof(s1), buf.size());
  EXPECT_STREQ(s1, buf.ptr());

  // for non-empty byte buffers
  buf.assign(s2, sizeof(s2));
  EXPECT_EQ(sizeof(s2), buf.size());
  EXPECT_STREQ(s2, buf.ptr());

  // for byte_buffers which shares buffers
  const byte_buffer copied = buf;
  const char* const copied_ptr = copied.ptr();
  const size_t copied_size = copied.size();
  buf.assign(s3, sizeof(s3));
  EXPECT_EQ(sizeof(s3), buf.size());
  EXPECT_STREQ(s3, buf.ptr());
  // should not affect any other objects (esp. shared one)
  EXPECT_NE(buf.ptr(), copied.ptr());
  EXPECT_EQ(copied_ptr, copied.ptr());
  EXPECT_EQ(copied_size, copied.size());
}
Exemplo n.º 2
0
  void put_diff(const byte_buffer& mixed,
                common::mprpc::rpc_result_object& result) const {
    cout << "put_diff " << mixed.size() << endl;

    msgpack::unpacked msg;
    msgpack::unpack(&msg, mixed.ptr(), mixed.size());
    vector<string> tmp = msg.get().as<vector<string> >();
    mixed_.swap(tmp);
  }
 void mix_impl(
     const byte_buffer& lhs,
     const byte_buffer& rhs,
     byte_buffer& mixed) const {
   std::stringstream ss;
   ss << "(" << string(lhs.ptr(), lhs.size()) << "+"
      << string(rhs.ptr(), rhs.size()) << ")";
   string s = ss.str();
   mixed.assign(s.data(), s.size());
 }
	std::vector<byte> get_payload_byte_arr() const override {
		return std::vector<byte>(payload_.data(), payload_.data()+payload_.size());
	}
	std::vector<byte> get_header_byte_arr() const override {
		return std::vector<byte>(hdr_.data(), hdr_.data()+hdr_.size());
	}
	size_t get_payload_length() const override { return payload_.size(); }
	size_t get_header_length() const override { return hdr_.size(); }