Apollo 10.0
自动驾驶开放平台
apollo::localization::msf::FileUtility类 参考

#include <file_utility.h>

apollo::localization::msf::FileUtility 的协作图:

静态 Public 成员函数

static void ComputeFileMd5 (const std::string &file_path, unsigned char res[kUcharMd5Length])
 Compute file md5 given a file path.
 
static void ComputeFileMd5 (const std::string &file_path, char res[kCharMd5Lenth])
 
static void ComputeBinaryMd5 (const unsigned char *binary, size_t size, unsigned char res[kUcharMd5Length])
 Compute file md5 given a binary chunk.
 
static void ComputeBinaryMd5 (const unsigned char *binary, size_t size, char res[kCharMd5Lenth])
 

静态 Public 属性

static const size_t kUcharMd5Length = 16
 
static const size_t kCharMd5Lenth = 33
 

详细描述

在文件 file_utility.h35 行定义.

成员函数说明

◆ ComputeBinaryMd5() [1/2]

void apollo::localization::msf::FileUtility::ComputeBinaryMd5 ( const unsigned char *  binary,
size_t  size,
char  res[kCharMd5Lenth] 
)
static

在文件 file_utility.cc107 行定义.

108 {
109 unsigned char md[kUcharMd5Length] = {"\0"};
110 char buf[kCharMd5Lenth] = {'\0'};
111 char tmp[3] = {'\0'};
112
113 ComputeBinaryMd5(binary, size, md);
114
115 for (unsigned int i = 0; i < kUcharMd5Length; i++) {
116 snprintf(tmp, sizeof(tmp), "%02X", md[i]);
117 strncat(buf, tmp, sizeof(tmp));
118 }
119
120 memcpy(res, buf, sizeof(buf));
121}
static void ComputeBinaryMd5(const unsigned char *binary, size_t size, unsigned char res[kUcharMd5Length])
Compute file md5 given a binary chunk.

◆ ComputeBinaryMd5() [2/2]

void apollo::localization::msf::FileUtility::ComputeBinaryMd5 ( const unsigned char *  binary,
size_t  size,
unsigned char  res[kUcharMd5Length] 
)
static

Compute file md5 given a binary chunk.

在文件 file_utility.cc96 行定义.

97 {
98 MD5 md5;
99 md5.init();
100 md5.update(binary, static_cast<unsigned int>(size));
101 md5.finalize();
102 for (uint8_t i = 0; i < kUcharMd5Length; ++i) {
103 res[i] = md5.digest[i];
104 }
105}

◆ ComputeFileMd5() [1/2]

void apollo::localization::msf::FileUtility::ComputeFileMd5 ( const std::string &  file_path,
char  res[kCharMd5Lenth] 
)
static

在文件 file_utility.cc67 行定义.

68 {
69 std::vector<unsigned char> buf(kBufferSize);
70 unsigned char *buf_pt = &buf[0];
71
72 FILE *file = fopen(file_path.c_str(), "rb");
73 size_t total_size = 0;
74 if (file) {
75 int count = 1;
76 while (!feof(file)) {
77 if (count > 1) {
78 buf.resize(kBufferSize * count);
79 buf_pt = &buf[count - 1];
80 }
81
82 size_t size = fread(buf_pt, sizeof(unsigned char), kBufferSize, file);
83 total_size += size;
84
85 ++count;
86 }
87 } else {
88 AERROR << "Can't find the file: " << file_path;
89 return;
90 }
91
92 ComputeBinaryMd5(&buf[0], total_size, res);
93 fclose(file);
94}
#define AERROR
Definition log.h:44

◆ ComputeFileMd5() [2/2]

void apollo::localization::msf::FileUtility::ComputeFileMd5 ( const std::string &  file_path,
unsigned char  res[kUcharMd5Length] 
)
static

Compute file md5 given a file path.

在文件 file_utility.cc38 行定义.

39 {
40 std::vector<unsigned char> buf(kBufferSize);
41 unsigned char *buf_pt = &buf[0];
42
43 FILE *file = fopen(file_path.c_str(), "rb");
44 size_t total_size = 0;
45 if (file) {
46 int count = 1;
47 while (!feof(file)) {
48 if (count > 1) {
49 buf.resize(kBufferSize * count);
50 buf_pt = &buf[count - 1];
51 }
52
53 size_t size = fread(buf_pt, sizeof(unsigned char), kBufferSize, file);
54 total_size += size;
55
56 ++count;
57 }
58 } else {
59 AERROR << "Can't find the file: " << file_path;
60 return;
61 }
62
63 ComputeBinaryMd5(&buf[0], total_size, res);
64 fclose(file);
65}

类成员变量说明

◆ kCharMd5Lenth

const size_t apollo::localization::msf::FileUtility::kCharMd5Lenth = 33
static

在文件 file_utility.h38 行定义.

◆ kUcharMd5Length

const size_t apollo::localization::msf::FileUtility::kUcharMd5Length = 16
static

在文件 file_utility.h37 行定义.


该类的文档由以下文件生成: