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()); }
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()); }
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); }