• 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 FRAMEHEADER_H
17 #define FRAMEHEADER_H
18 
19 #include <cstdint>
20 #include "communicator_type_define.h"
21 
22 namespace DistributedDB {
23 /*
24  * packetType: Bit0:   FragmentFlag: 1: Fragmented 0: Not Fragmented
25  *             Bit1~3: Reserved
26  *             Bit4~7: FrameType
27  */
28 struct CommPhyHeader {
29     uint16_t magic;         // Magic code to discern byte stream
30     uint16_t version;       // Version to differentiate fields layout
31     uint32_t packetLen;     // Length of total packet, include CommHeader and Padding
32     uint64_t checkSum;      // Check sum of data that follows CommPhyHeader
33     uint64_t sourceId;      // Indicate where this packet from
34     uint32_t frameId;       // FrameId to identify frame
35     uint8_t packetType;     // Some bits works individually, the high four bits indicates frameType
36     uint8_t paddingLen;     // Unit byte, range from 0 to 7.
37     uint16_t dbIntVer;      // Auxiliary info to help recognize db version in the future
38 };
39 
40 /*
41  * Whether a physical packet contains CommPhyOptHeader depend on FragmentFlag of packetType in CommPhyHeader
42  */
43 struct CommPhyOptHeader {
44     uint32_t frameLen;      // Indicate length of frame before fragmentation. Frame include CommHeader no padding
45     uint16_t fragCount;     // Indicate how many fragments this frame is divided into
46     uint16_t fragNo;        // Indicate which fragment this packet is. start from 0.
47 };
48 
49 /*
50  * Whether a physical packet contains CommDivergeHeader depend on FrameType of packetType in CommPhyHeader
51  */
52 struct CommDivergeHeader {
53     uint16_t version;       // Version to differentiate fields layout
54     uint16_t reserved;      // Reserved for future usage
55     uint32_t payLoadLen;    // Indicate length of data that follows CommDivergeHeader
56     uint8_t commLabel[COMM_LABEL_LENGTH]; // Indicate which communicator to hand out this frame
57 };
58 
59 /*
60  * MessageHeader used to describe a message
61  */
62 struct MessageHeader {
63     uint16_t version;       // Version to differentiate fields layout
64     uint16_t messageType;   // Distinguish request/response/notify
65     uint32_t messageId;     // Indicate message command
66     uint32_t sessionId;     // For matching request and response
67     uint32_t sequenceId;    // Sequence of message
68     uint32_t errorNo;       // Indicate no error when zero
69     uint32_t dataLen;       // Indicate length of data that follows MessageHeader
70 };
71 } // namespace DistributedDB
72 
73 #endif // FRAMEHEADER_H
74