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 <cstdint> 20 #include <set> 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 } SetSendLabelExchange(bool sendLabelExchange)50 void SetSendLabelExchange(bool sendLabelExchange) 51 { 52 sendLabelExchange_ = sendLabelExchange; 53 } SetFrameLen(uint32_t inFrameLen)54 void SetFrameLen(uint32_t inFrameLen) 55 { 56 frameLen_ = inFrameLen; 57 } SetFragCount(uint16_t inFragCount)58 void SetFragCount(uint16_t inFragCount) 59 { 60 fragCount_ = inFragCount; 61 } SetFragNo(uint16_t inFragNo)62 void SetFragNo(uint16_t inFragNo) 63 { 64 fragNo_ = inFragNo; 65 } SetPayloadLen(uint32_t inPayloadLen)66 void SetPayloadLen(uint32_t inPayloadLen) 67 { 68 payloadLen_ = inPayloadLen; 69 } SetCommLabel(const LabelType & inCommLabel)70 void SetCommLabel(const LabelType &inCommLabel) 71 { 72 commLabel_ = inCommLabel; 73 } SetLabelExchangeDistinctValue(uint64_t inDistinctValue)74 void SetLabelExchangeDistinctValue(uint64_t inDistinctValue) 75 { 76 labelExchangeDistinctValue_ = inDistinctValue; 77 } SetLabelExchangeSequenceId(uint64_t inSequenceId)78 void SetLabelExchangeSequenceId(uint64_t inSequenceId) 79 { 80 labelExchangeSequenceId_ = inSequenceId; 81 } SetLatestCommLabels(const std::set<LabelType> & inLatestCommLabels)82 void SetLatestCommLabels(const std::set<LabelType> &inLatestCommLabels) 83 { 84 latestCommLabels_ = inLatestCommLabels; 85 } 86 GetFrameId()87 uint32_t GetFrameId() const 88 { 89 return frameId_; 90 } GetSourceId()91 uint64_t GetSourceId() const 92 { 93 return sourceId_; 94 } GetPacketLen()95 uint32_t GetPacketLen() const 96 { 97 return packetLen_; 98 } GetPaddingLen()99 uint32_t GetPaddingLen() const 100 { 101 return paddingLen_; 102 } IsFragment()103 bool IsFragment() const 104 { 105 return isFragment_; 106 } GetFrameTypeInfo()107 FrameType GetFrameTypeInfo() const 108 { 109 return frameType_; 110 } IsSendLabelExchange()111 bool IsSendLabelExchange() const 112 { 113 return sendLabelExchange_; 114 } GetFrameLen()115 uint32_t GetFrameLen() const 116 { 117 return frameLen_; 118 } GetFragCount()119 uint16_t GetFragCount() const 120 { 121 return fragCount_; 122 } GetFragNo()123 uint16_t GetFragNo() const 124 { 125 return fragNo_; 126 } GetPayloadLen()127 uint32_t GetPayloadLen() const 128 { 129 return payloadLen_; 130 } GetCommLabel()131 LabelType GetCommLabel() const 132 { 133 return commLabel_; 134 } GetLabelExchangeDistinctValue()135 uint64_t GetLabelExchangeDistinctValue() const 136 { 137 return labelExchangeDistinctValue_; 138 } GetLabelExchangeSequenceId()139 uint64_t GetLabelExchangeSequenceId() const 140 { 141 return labelExchangeSequenceId_; 142 } GetLatestCommLabels()143 const std::set<LabelType>& GetLatestCommLabels() const 144 { 145 return latestCommLabels_; 146 } 147 SetDbVersion(uint16_t dbVersion)148 void SetDbVersion(uint16_t dbVersion) 149 { 150 dbVersion_ = dbVersion; 151 } 152 GetDbVersion()153 uint16_t GetDbVersion() const 154 { 155 return dbVersion_; 156 } 157 private: 158 // For CommPhyHeader 159 uint32_t frameId_ = 0; 160 uint64_t sourceId_ = 0; 161 uint32_t packetLen_ = 0; 162 uint8_t paddingLen_ = 0; 163 bool isFragment_ = false; 164 FrameType frameType_ = FrameType::INVALID_MAX_FRAME_TYPE; 165 bool sendLabelExchange_ = true; 166 167 // For CommPhyOptHeader 168 uint32_t frameLen_ = 0; 169 uint16_t fragCount_ = 0; 170 uint16_t fragNo_ = 0; 171 172 // For Application Layer Frame 173 uint32_t payloadLen_ = 0; 174 LabelType commLabel_; 175 176 // For Communication Layer Frame 177 uint64_t labelExchangeDistinctValue_ = 0; // For Both LabelExchange And LabelExchangeAck Frame 178 uint64_t labelExchangeSequenceId_ = 0; // For Both LabelExchange And LabelExchangeAck Frame 179 std::set<LabelType> latestCommLabels_; // For Only LabelExchange Frame 180 uint16_t dbVersion_ = 0; 181 }; 182 } 183 184 #endif // PARSE_RESULT_H 185