-
Notifications
You must be signed in to change notification settings - Fork 245
/
Copy pathcppnet_buffer.h
50 lines (36 loc) · 1.44 KB
/
cppnet_buffer.h
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
44
45
46
47
48
49
50
// Use of this source code is governed by a BSD 3-Clause License
// that can be found in the LICENSE file.
// Author: caozhiyi ([email protected])
#ifndef INCLUDE_CPPNET_BUFFER
#define INCLUDE_CPPNET_BUFFER
#include <cstdint>
namespace cppnet {
class Buffer {
public:
Buffer() = default;
virtual ~Buffer() = default;
// read to data to buf but don't move the read point.
// return read size.
virtual uint32_t ReadNotMovePt(char* buf, uint32_t buf_len) = 0;
// read data to res buf and move the read point.
// return read size.
virtual uint32_t Read(char* res, uint32_t len) = 0;
// clear all data
virtual void Clear() = 0;
// do not read when buffer less than len.
// return len when read otherwise return 0
virtual uint32_t ReadUntil(char* res, uint32_t len) = 0;
// move read point
virtual int32_t MoveReadPt(int32_t len) = 0;
// do not read when can't find specified character.
// return read bytes when read otherwise return 0
// when find specified character but res length is too short,
// return 0 and the last param return need length
virtual uint32_t ReadUntil(char* res, uint32_t len, const char* find, uint32_t find_len, uint32_t& need_len) = 0;
// return size of data that can be read
virtual uint32_t GetCanReadLength() = 0;
// return can read bytes
virtual uint32_t FindStr(const char* s, uint32_t s_len) = 0;
};
} // namespace cppnet
#endif