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

#include <compression.h>

类 apollo::localization::msf::ZlibStrategy 继承关系图:
apollo::localization::msf::ZlibStrategy 的协作图:

Public 成员函数

virtual int Encode (BufferStr *buf, BufferStr *buf_compressed)
 
virtual int Decode (BufferStr *buf, BufferStr *buf_uncompressed)
 
- Public 成员函数 继承自 apollo::localization::msf::CompressionStrategy
virtual ~CompressionStrategy ()
 

Protected 成员函数

int ZlibCompress (BufferStr *src, BufferStr *dst)
 
int ZlibUncompress (BufferStr *src, BufferStr *dst)
 

静态 Protected 属性

static const unsigned int zlib_chunk = 16384
 

额外继承的成员函数

- Public 类型 继承自 apollo::localization::msf::CompressionStrategy
typedef std::vector< unsigned char > BufferStr
 

详细描述

在文件 compression.h35 行定义.

成员函数说明

◆ Decode()

int apollo::localization::msf::ZlibStrategy::Decode ( BufferStr buf,
BufferStr buf_uncompressed 
)
virtual

实现了 apollo::localization::msf::CompressionStrategy.

在文件 compression.cc35 行定义.

35 {
36 return ZlibUncompress(buf, buf_uncompressed);
37}
int ZlibUncompress(BufferStr *src, BufferStr *dst)

◆ Encode()

int apollo::localization::msf::ZlibStrategy::Encode ( BufferStr buf,
BufferStr buf_compressed 
)
virtual

实现了 apollo::localization::msf::CompressionStrategy.

在文件 compression.cc31 行定义.

31 {
32 return ZlibCompress(buf, buf_compressed);
33}
int ZlibCompress(BufferStr *src, BufferStr *dst)

◆ ZlibCompress()

int apollo::localization::msf::ZlibStrategy::ZlibCompress ( BufferStr src,
BufferStr dst 
)
protected

在文件 compression.cc39 行定义.

39 {
40 dst->resize(zlib_chunk * 2);
41 int ret, flush;
42 unsigned have;
43 z_stream stream_data;
44 unsigned char* in = &((*src)[0]);
45 unsigned char* out = &((*dst)[0]);
46 unsigned int src_idx = 0;
47 unsigned int dst_idx = 0;
48
49 /* allocate deflate state */
50 stream_data.zalloc = Z_NULL;
51 stream_data.zfree = Z_NULL;
52 stream_data.opaque = Z_NULL;
53 ret = deflateInit(&stream_data, Z_BEST_SPEED);
54 if (ret != Z_OK) {
55 return ret;
56 }
57 /* compress until end of file */
58 do {
59 in = &((*src)[src_idx]);
60 if (src->size() - src_idx > zlib_chunk) {
61 stream_data.avail_in = zlib_chunk;
62 flush = Z_NO_FLUSH;
63 } else {
64 stream_data.avail_in = static_cast<unsigned int>(src->size()) - src_idx;
65 flush = Z_FINISH;
66 }
67 stream_data.next_in = in;
68 src_idx += stream_data.avail_in;
69
70 /* run deflate() on input until output buffer not full, finish
71 compression if all of source has been read in */
72 do {
73 stream_data.avail_out = zlib_chunk;
74 stream_data.next_out = out;
75 ret = deflate(&stream_data, flush); /* no bad return value */
76 DCHECK_NE(ret, Z_STREAM_ERROR); /* state not clobbered */
77 have = zlib_chunk - stream_data.avail_out;
78 dst_idx += have;
79 if (dst_idx + zlib_chunk > dst->size()) {
80 dst->resize(dst_idx + zlib_chunk * 2);
81 }
82 out = &((*dst)[dst_idx]);
83 } while (stream_data.avail_out == 0);
84 DCHECK_EQ(stream_data.avail_in, 0U); /* all input will be used */
85
86 /* done when last data in file processed */
87 } while (flush != Z_FINISH);
88 DCHECK_EQ(ret, Z_STREAM_END); /* stream will be complete */
89
90 /* clean up and return */
91 (void)deflateEnd(&stream_data);
92 dst->resize(dst_idx);
93 return Z_OK;
94}
static const unsigned int zlib_chunk
Definition compression.h:41

◆ ZlibUncompress()

int apollo::localization::msf::ZlibStrategy::ZlibUncompress ( BufferStr src,
BufferStr dst 
)
protected

在文件 compression.cc96 行定义.

96 {
97 dst->resize(zlib_chunk * 2);
98 int ret;
99 unsigned have;
100 z_stream stream_data;
101 unsigned char* in = &((*src)[0]);
102 unsigned char* out = &((*dst)[0]);
103 unsigned int src_idx = 0;
104 unsigned int dst_idx = 0;
105
106 /* allocate inflate state */
107 std::memset(&stream_data, 0, sizeof(z_stream));
108
109 ret = inflateInit(&stream_data);
110 if (ret != Z_OK) {
111 return ret;
112 }
113 /* decompress until deflate stream ends or end of file */
114 do {
115 in = &((*src)[src_idx]);
116 if (src->size() - src_idx > zlib_chunk) {
117 stream_data.avail_in = zlib_chunk;
118 } else {
119 stream_data.avail_in = static_cast<unsigned int>(src->size()) - src_idx;
120 }
121 stream_data.next_in = in;
122 src_idx += stream_data.avail_in;
123 if (stream_data.avail_in == 0) {
124 break;
125 }
126 /* run inflate() on input until output buffer not full */
127 do {
128 stream_data.avail_out = zlib_chunk;
129 stream_data.next_out = out;
130 ret = inflate(&stream_data, Z_NO_FLUSH);
131 DCHECK_NE(ret, Z_STREAM_ERROR); /* state not clobbered */
132 switch (ret) {
133 case Z_NEED_DICT:
134 ret = Z_DATA_ERROR; /* and fall through */
135 case Z_DATA_ERROR:
136 case Z_MEM_ERROR:
137 (void)inflateEnd(&stream_data);
138 return ret;
139 }
140 have = zlib_chunk - stream_data.avail_out;
141 dst_idx += have;
142 if (dst_idx + zlib_chunk > dst->size()) {
143 dst->resize(dst_idx + zlib_chunk * 2);
144 }
145 out = &((*dst)[dst_idx]);
146 } while (stream_data.avail_out == 0);
147
148 /* done when inflate() says it's done */
149 } while (ret != Z_STREAM_END);
150
151 /* clean up and return */
152 (void)inflateEnd(&stream_data);
153 dst->resize(dst_idx);
154 return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
155}

类成员变量说明

◆ zlib_chunk

const unsigned int apollo::localization::msf::ZlibStrategy::zlib_chunk = 16384
staticprotected

在文件 compression.h41 行定义.


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