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()); }
virtual std::size_t read(byte_buffer& buffer) { boost::system::error_code error; size_t result = socket_->read_some(asio_buffer(buffer), boost::ref(error)); if(error == boost::asio::error::eof) { return 0; } else if(error) { boost::throw_exception(io_exception("Read socket error "+error.message())); } buffer.move(result); return result; }
std::size_t ConsoleWriteChannel::write(const byte_buffer& buffer) { DWORD result = 0; BOOL succeeded = peer_(hCons_, vpos(buffer), buffer.length() / charSize_, &result, NULL); validate_io(succeeded,"Write console error."); result = result * charSize_; return result; }
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()); }
inline void swap(byte_buffer& one, byte_buffer& another) { // NOLINT one.swap(another); }
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(); }
const byte* get_payload_bytes() const override { return payload_.data(); }
size_t get_header_length() const override { return hdr_.size(); }
const byte* get_header_bytes() const override { return hdr_.data(); }