/* * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HDC_SERIAL_STRUCT_H #define HDC_SERIAL_STRUCT_H #include "serial_struct_define.h" #include #include namespace Hdc { using std::string; namespace BaseStruct { struct SessionHandShake { string banner; // must first index // auth none uint8_t authType; uint32_t sessionId; string connectKey; string buf; string version; std::string ToDebugString() const { std::ostringstream oss; oss << "SessionHandShake ["; oss << " banner:" << banner; oss << " sessionId:" << sessionId; oss << " authType:" << unsigned(authType); oss << " connectKey:" << connectKey; oss << " buf:" << buf; oss << " version:" << version; oss << " ]"; return oss.str(); } }; struct PayloadProtect { // reserve for encrypt and decrypt uint32_t channelId; uint32_t commandFlag; uint8_t checkSum; // enable it will be lose about 20% speed uint8_t vCode; }; struct TransferConfig { uint64_t fileSize; uint64_t atime; // ns uint64_t mtime; // ns string options; string path; string optionalName; bool updateIfNew; uint8_t compressType; bool holdTimestamp; string functionName; string clientCwd; string reserve1; string reserve2; }; struct FileMode { uint64_t perm; uint64_t u_id; uint64_t g_id; string context; string fullName; }; // used for HdcTransferBase. just base class use, not public struct TransferPayload { uint64_t index; uint8_t compressType; uint32_t compressSize; uint32_t uncompressSize; }; } // BaseStruct namespace RustStruct { struct SessionHandShake { const char* banner; // must first index // auth none uint8_t authType; uint32_t sessionId; const char* connectKey; const char* buf; const char* version; }; struct PayloadProtect { // reserve for encrypt and decrypt uint32_t channelId; uint32_t commandFlag; uint8_t checkSum; // enable it will be lose about 20% speed uint8_t vCode; }; struct TransferConfig { uint64_t fileSize; uint64_t atime; // ns uint64_t mtime; // ns const char* options; const char* path; const char* optionalName; uint8_t updateIfNew; uint8_t compressType; uint8_t holdTimestamp; const char* functionName; const char* clientCwd; const char* reserve1; const char* reserve2; }; struct FileMode { uint64_t perm; uint64_t u_id; uint64_t g_id; const char* context; const char* fullName; }; struct TransferPayload { uint64_t index; uint8_t compressType; uint32_t compressSize; uint32_t uncompressSize; }; struct PayloadHead { uint8_t flag[2]; uint8_t reserve[2]; // encrypt'flag or others options uint8_t protocolVer; uint16_t headSize; uint32_t data_size; } __attribute__((packed)); struct USBHead { uint8_t flag[2]; uint8_t option; uint32_t sessionId; uint32_t data_size; } __attribute__((packed)); struct UartHead { uint8_t flag[2]; uint16_t option; uint32_t sessionId; uint32_t data_size; uint32_t package_index; uint32_t data_checksum; uint32_t head_checksum; } __attribute__((packed)); } // RustStruct namespace SerialStruct { constexpr int fieldOne = 1; constexpr int fieldTwo = 2; constexpr int fieldThree = 3; constexpr int fieldFour = 4; constexpr int fieldFive = 5; constexpr int fieldSix = 6; constexpr int fieldSeven = 7; constexpr int fieldEight = 8; constexpr int fieldNine = 9; constexpr int fieldTen = 10; constexpr int field11 = 11; constexpr int field12 = 12; constexpr int field13 = 13; template<> struct Descriptor { static auto type() { return Message(Field("fileSize"), Field("atime"), Field("mtime"), Field("options"), Field("path"), Field("optionalName"), Field("updateIfNew"), Field("compressType"), Field("holdTimestamp"), Field("functionName"), Field("clientCwd"), Field("reserve1"), Field("reserve2")); } }; template<> struct Descriptor { static auto type() { return Message(Field("perm"), Field("u_id"), Field("g_id"), Field("context"), Field("fullName")); } }; template<> struct Descriptor { static auto type() { return Message(Field("index"), Field("compressType"), Field("compressSize"), Field("uncompressSize")); } }; template<> struct Descriptor { static auto type() { return Message(Field("banner"), Field("authType"), Field("sessionId"), Field("connectKey"), Field("buf"), Field("version")); } }; template<> struct Descriptor { static auto type() { return Message(Field("channelId"), Field("commandFlag"), Field("checkSum"), Field("vCode")); } }; } // SerialStruct } // Hdc #endif // HDC_SERIAL_STRUCT_H