forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpika_binlog_transverter.h
91 lines (74 loc) · 2.83 KB
/
pika_binlog_transverter.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2018-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_BINLOG_TRANSVERTER_H_
#define PIKA_BINLOG_TRANSVERTER_H_
#include <vector>
#include <stdint.h>
#include <iostream>
#include <glog/logging.h>
/*
* ***********************************************Type First Binlog Item Format***********************************************
* | <Type> | <Create Time> | <Term Id> | <Binlog Logic Id> | <File Num> | <Offset> | <Content Length> | <Content> |
* 2 Bytes 4 Bytes 4 Bytes 8 Bytes 4 Bytes 8 Bytes 4 Bytes content length Bytes
*
*/
#define BINLOG_ENCODE_LEN 34
enum BinlogType {
TypeFirst = 1,
};
const int BINLOG_ITEM_HEADER_SIZE = 34;
const int PADDING_BINLOG_PROTOCOL_SIZE = 22;
const int SPACE_STROE_PARAMETER_LENGTH = 5;
class BinlogItem {
public:
BinlogItem() :
exec_time_(0),
term_id_(0),
logic_id_(0),
filenum_(0),
offset_(0),
content_("") {}
friend class PikaBinlogTransverter;
uint32_t exec_time() const;
uint32_t term_id() const;
uint64_t logic_id() const;
uint32_t filenum() const;
uint64_t offset() const;
std::string content() const;
std::string ToString() const;
void set_exec_time(uint32_t exec_time);
void set_term_id(uint32_t term_id);
void set_logic_id(uint64_t logic_id);
void set_filenum(uint32_t filenum);
void set_offset(uint64_t offset);
private:
uint32_t exec_time_;
uint32_t term_id_;
uint64_t logic_id_;
uint32_t filenum_;
uint64_t offset_;
std::string content_;
std::vector<std::string> extends_;
};
class PikaBinlogTransverter{
public:
PikaBinlogTransverter() {};
static std::string BinlogEncode(BinlogType type,
uint32_t exec_time,
uint32_t term_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset,
const std::string& content,
const std::vector<std::string>& extends);
static bool BinlogDecode(BinlogType type,
const std::string& binlog,
BinlogItem* binlog_item);
static std::string ConstructPaddingBinlog(BinlogType type, uint32_t size);
static bool BinlogItemWithoutContentDecode(BinlogType type,
const std::string& binlog,
BinlogItem* binlog_item);
};
#endif