1/**
2 * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15
16 * \author Haichao.chc
17 * \date Jun 2021
18 * \brief ForwardData describes the format of forward data
19 */
20
21
22#pragma once
23
24#include <string>
25#include "../constants.h"
26
27namespace proxima {
28namespace be {
29namespace index {
30
31/*
32 * ForwardData packed some meta info with forward data.
33 * It provides serialize and deserilize ability.
34 */
35struct ForwardData {
36 public:
37 /*
38 * ForwardHeader contains some header fields.
39 */
40 struct ForwardHeader {
41 uint64_t primary_key{0U};
42 uint64_t timestamp{0U};
43 uint32_t revision{0U};
44 uint64_t lsn{0U};
45
46 ForwardHeader() {
47 primary_key = INVALID_KEY;
48 }
49 };
50
51 //! Serialize to bytes string
52 void serialize(std::string *buf) const {
53 buf->clear();
54 buf->append((const char *)&header, sizeof(ForwardHeader));
55 buf->append(data);
56 }
57
58 //! Deserialize from bytes string
59 void deserialize(const std::string &buf) {
60 header = *((ForwardHeader *)buf.data());
61 data.assign(buf.data() + sizeof(ForwardHeader),
62 buf.size() - sizeof(ForwardHeader));
63 }
64
65 ForwardHeader header{};
66 std::string data{};
67};
68
69
70} // end namespace index
71} // namespace be
72} // end namespace proxima
73