Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat(util): add restore_read function in rpc_message #442

Merged
merged 3 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/dsn/tool-api/rpc_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ class message_ex : public ref_counter,
size_t body_size() { return (size_t)header->body_length; }
DSN_API void *rw_ptr(size_t offset_begin);

// rpc_read_stream can read a msg many times by restore()
// rpc_read_stream stream1(msg)
// msg->restore()
// rpc_read_stream stream2(msg)
DSN_API void restore();
Smityz marked this conversation as resolved.
Show resolved Hide resolved

bool is_backup_request() const { return header->context.u.is_backup_request; }

private:
Expand Down
7 changes: 7 additions & 0 deletions src/core/core/rpc_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ void message_ex::read_commit(size_t size)
this->_rw_committed = true;
}

void message_ex::restore()
{
this->_rw_index = -1;
this->_rw_committed = true;
this->_rw_offset = 0;
}

void *message_ex::rw_ptr(size_t offset_begin)
{
// printf("%p %s\n", this, __FUNCTION__);
Expand Down