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 #ifndef TRACE_FILE_HEADER_H 16 #define TRACE_FILE_HEADER_H 17 18 struct TraceFileHeader { 19 static constexpr uint32_t HEADER_SIZE = 1024; // 预留了一些空间,方便后续在头部添加字段 20 static constexpr uint32_t SHA256_SIZE = 256 / 8; 21 static constexpr uint64_t HEADER_MAGIC = 0x464F5250534F484FuLL; 22 static constexpr uint32_t V_MAJOR = 0x0001; 23 static constexpr uint32_t V_MAJOR_BITS = 16; 24 static constexpr uint32_t V_MINOR = 0x0000; 25 static constexpr uint32_t TRACE_VERSION = (V_MAJOR << V_MAJOR_BITS) | V_MINOR; 26 27 struct HeaderData { 28 uint64_t magic_ = HEADER_MAGIC; // 魔数,用于区分离线文件 29 uint64_t length_ = HEADER_SIZE; // 总长度,可用于检验文件是否被截断; 30 uint32_t version_ = TRACE_VERSION; 31 uint32_t segments_ = 0; // 载荷数据中的段个数, 段个数为偶数,一个描述长度 L,一个描述接下来的数据 V 32 uint8_t sha256_[SHA256_SIZE] = {}; // 载荷数据 的 SHA256 ,用于校验 载荷数据是否完整; 33 } __attribute__((packed)); 34 HeaderData data_ = {}; 35 uint8_t padding_[HEADER_SIZE - sizeof(data_)] = {}; 36 }; 37 38 #endif // TRACE_FILE_HEADER_H