blob: fc92d6917cd21dcfbbc0b2cf8b944d172478d7f3 (
plain) (
blame)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#pragma once
#include <util/generic/buffer.h>
#include <util/generic/noncopyable.h>
#include <util/system/yassert.h>
namespace NBus {
namespace NPrivate {
class TLeftRightBuffer : TNonCopyable {
private:
TBuffer Buffer;
size_t Left;
void CheckInvariant() {
Y_ASSERT(Left <= Buffer.Size());
}
public:
TLeftRightBuffer()
: Left(0)
{
}
TBuffer& GetBuffer() {
return Buffer;
}
size_t Capacity() {
return Buffer.Capacity();
}
void Clear() {
Buffer.Clear();
Left = 0;
}
void Reset() {
Buffer.Reset();
Left = 0;
}
void Compact() {
Buffer.ChopHead(Left);
Left = 0;
}
char* LeftPos() {
return Buffer.Data() + Left;
}
size_t LeftSize() {
return Left;
}
void LeftProceed(size_t count) {
Y_ASSERT(count <= Size());
Left += count;
}
size_t Size() {
return Buffer.Size() - Left;
}
bool Empty() {
return Size() == 0;
}
char* RightPos() {
return Buffer.Data() + Buffer.Size();
}
size_t Avail() {
return Buffer.Avail();
}
};
}
}
|