1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PARSE_RESULT_H 17 #define PARSE_RESULT_H 18 19 #include <set> 20 #include <cstdint> 21 #include "communicator_type_define.h" 22 23 namespace DistributedDB { 24 class ParseResult { 25 public: SetFrameId(uint32_t inFrameId)26 void SetFrameId(uint32_t inFrameId) 27 { 28 frameId_ = inFrameId; 29 } SetSourceId(uint64_t inSourceId)30 void SetSourceId(uint64_t inSourceId) 31 { 32 sourceId_ = inSourceId; 33 } SetPacketLen(uint32_t inPacketLen)34 void SetPacketLen(uint32_t inPacketLen) 35 { 36 packetLen_ = inPacketLen; 37 } SetPaddingLen(uint32_t inPaddingLen)38 void SetPaddingLen(uint32_t inPaddingLen) 39 { 40 paddingLen_ = inPaddingLen; 41 } SetFragmentFlag(bool inFlag)42 void SetFragmentFlag(bool inFlag) 43 { 44 isFragment_ = inFlag; 45 } SetFrameTypeInfo(FrameType inFrameType)46 void SetFrameTypeInfo(FrameType inFrameType) 47 { 48 frameType_ = inFrameType; 49 } SetFrameLen(uint32_t inFrameLen)50 void SetFrameLen(uint32_t inFrameLen) 51 { 52 frameLen_ = inFrameLen; 53 } SetFragCount(uint16_t inFragCount)54 void SetFragCount(uint16_t inFragCount) 55 { 56 fragCount_ = inFragCount; 57 } SetFragNo(uint16_t inFragNo)58 void SetFragNo(uint16_t inFragNo) 59 { 60 fragNo_ = inFragNo; 61 } SetPayloadLen(uint32_t inPayloadLen)62 void SetPayloadLen(uint32_t inPayloadLen) 63 { 64 payloadLen_ = inPayloadLen; 65 } SetCommLabel(const LabelType & inCommLabel)66 void SetCommLabel(const LabelType &inCommLabel) 67 { 68 commLabel_ = inCommLabel; 69 } SetLabelExchangeDistinctValue(uint64_t inDistinctValue)70 void SetLabelExchangeDistinctValue(uint64_t inDistinctValue) 71 { 72 labelExchangeDistinctValue_ = inDistinctValue; 73 } SetLabelExchangeSequenceId(uint64_t inSequenceId)74 void SetLabelExchangeSequenceId(uint64_t inSequenceId) 75 { 76 labelExchangeSequenceId_ = inSequenceId; 77 } SetLatestCommLabels(const std::set<LabelType> & inLatestCommLabels)78 void SetLatestCommLabels(const std::set<LabelType> &inLatestCommLabels) 79 { 80 latestCommLabels_ = inLatestCommLabels; 81 } 82 GetFrameId()83 uint32_t GetFrameId() const 84 { 85 return frameId_; 86 } GetSourceId()87 uint64_t GetSourceId() const 88 { 89 return sourceId_; 90 } GetPacketLen()91 uint32_t GetPacketLen() const 92 { 93 return packetLen_; 94 } GetPaddingLen()95 uint32_t GetPaddingLen() const 96 { 97 return paddingLen_; 98 } IsFragment()99 bool IsFragment() const 100 { 101 return isFragment_; 102 } GetFrameTypeInfo()103 FrameType GetFrameTypeInfo() const 104 { 105 return frameType_; 106 } GetFrameLen()107 uint32_t GetFrameLen() const 108 { 109 return frameLen_; 110 } GetFragCount()111 uint16_t GetFragCount() const 112 { 113 return fragCount_; 114 } GetFragNo()115 uint16_t GetFragNo() const 116 { 117 return fragNo_; 118 } GetPayloadLen()119 uint32_t GetPayloadLen() const 120 { 121 return payloadLen_; 122 } GetCommLabel()123 LabelType GetCommLabel() const 124 { 125 return commLabel_; 126 } GetLabelExchangeDistinctValue()127 uint64_t GetLabelExchangeDistinctValue() const 128 { 129 return labelExchangeDistinctValue_; 130 } GetLabelExchangeSequenceId()131 uint64_t GetLabelExchangeSequenceId() const 132 { 133 return labelExchangeSequenceId_; 134 } GetLatestCommLabels()135 const std::set<LabelType>& GetLatestCommLabels() const 136 { 137 return latestCommLabels_; 138 } 139 SetDbVersion(uint16_t dbVersion)140 void SetDbVersion(uint16_t dbVersion) 141 { 142 dbVersion_ = dbVersion; 143 } 144 GetDbVersion()145 uint16_t GetDbVersion() const 146 { 147 return dbVersion_; 148 } 149 private: 150 // For CommPhyHeader 151 uint32_t frameId_ = 0; 152 uint64_t sourceId_ = 0; 153 uint32_t packetLen_ = 0; 154 uint8_t paddingLen_ = 0; 155 bool isFragment_ = false; 156 FrameType frameType_ = FrameType::INVALID_MAX_FRAME_TYPE; 157 158 // For CommPhyOptHeader 159 uint32_t frameLen_ = 0; 160 uint16_t fragCount_ = 0; 161 uint16_t fragNo_ = 0; 162 163 // For Application Layer Frame 164 uint32_t payloadLen_ = 0; 165 LabelType commLabel_; 166 167 // For Communication Layer Frame 168 uint64_t labelExchangeDistinctValue_ = 0; // For Both LabelExchange And LabelExchangeAck Frame 169 uint64_t labelExchangeSequenceId_ = 0; // For Both LabelExchange And LabelExchangeAck Frame 170 std::set<LabelType> latestCommLabels_; // For Only LabelExchange Frame 171 uint16_t dbVersion_ = 0; 172 }; 173 } 174 175 #endif // PARSE_RESULT_H 176