-Client::Client(int sock)
- : sock(sock),
- state(Client::READING_REQUEST),
- header_bytes_sent(0),
- bytes_sent(0)
-{
- request.reserve(1024);
-}
-
-Client::Client(const ClientProto &serialized)
- : sock(serialized.sock()),
- state(State(serialized.state())),
- request(serialized.request()),
- stream_id(serialized.stream_id()),
- header(serialized.header()),
- header_bytes_sent(serialized.header_bytes_sent()),
- bytes_sent(serialized.bytes_sent())
-{
-}
-
-ClientProto Client::serialize() const
-{
- ClientProto serialized;
- serialized.set_sock(sock);
- serialized.set_state(state);
- serialized.set_request(request);
- serialized.set_stream_id(stream_id);
- serialized.set_header(header);
- serialized.set_header_bytes_sent(serialized.header_bytes_sent());
- serialized.set_bytes_sent(bytes_sent);
- return serialized;
-}
-
-Stream::Stream(const string &stream_id)
- : stream_id(stream_id),
- data(new char[BACKLOG_SIZE]),
- data_size(0)
-{
- memset(data, 0, BACKLOG_SIZE);
-}
-
-Stream::~Stream()
-{
- delete[] data;
-}
-
-Stream::Stream(const StreamProto &serialized)
- : stream_id(serialized.stream_id()),
- header(serialized.header()),
- data(new char[BACKLOG_SIZE]),
- data_size(serialized.data_size())
-{
- assert(serialized.data().size() == BACKLOG_SIZE);
- memcpy(data, serialized.data().data(), BACKLOG_SIZE);
-}
-
-StreamProto Stream::serialize() const
-{
- StreamProto serialized;
- serialized.set_header(header);
- serialized.set_data(string(data, data + BACKLOG_SIZE));
- serialized.set_data_size(data_size);
- serialized.set_stream_id(stream_id);
- return serialized;
-}
-