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