-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext.h
More file actions
43 lines (33 loc) · 866 Bytes
/
context.h
File metadata and controls
43 lines (33 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once
#include <netpoll/net/callbacks.h>
#include "type.h"
namespace chat {
class Context
{
public:
explicit Context(int id) : id_(id) {}
int getId() const { return id_; }
void processCodec(const netpoll::TcpConnectionPtr &conn,
const netpoll::MessageBuffer *buffer);
bool parseOk() { return state_ == kParseOk; }
std::string getText()
{
auto text = std::move(text_);
reset();
return text;
}
static void Send(const netpoll::TcpConnectionPtr &conn,
CommonData const &msg);
private:
uint64_t expectedLength() { return length_ - text_.size(); }
void reset()
{
state_ = kGetLength;
text_.clear();
}
const int id_;
ParseState state_{kGetLength};
uint64_t length_{};
std::string text_{};
};
} // namespace chat