Skip to content

Commit

Permalink
Create a new TeeSink abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
meditans committed Jun 17, 2020
1 parent 09e6e57 commit 270005f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libutil/serialise.hh
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ struct TeeSource : Source
}
};

struct TeeSink : Sink
{
Sink & orig;
ref<std::string> data;
TeeSink(Sink & orig)
: orig(orig), data(make_ref<std::string>()) { }
void operator () (const unsigned char * data, size_t len) {
this->data->append((const char *) data, len);
Sink::operator()(data, len);
}
void operator () (const std::string & s)
{
*data += s;
Sink::operator()(s);
}
};


/* A reader that consumes the original Source until 'size'. */
struct SizedSource : Source
{
Expand Down

0 comments on commit 270005f

Please sign in to comment.