forked from anqin/trident
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompressed_stream.h
More file actions
62 lines (47 loc) · 2.27 KB
/
compressed_stream.h
File metadata and controls
62 lines (47 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2014 The Trident Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file is modified from `protobuf-zerocopy-compression':
// https://github.com/JohannesEbke/protobuf-zerocopy-compression
// Copyright (c) 2013, Johannes Ebke and Peter Waller. All rights reserved.
// Author: peter.waller@gmail.com (Peter Waller)
// Author: johannes@ebke.org (Johannes Ebke)
#ifndef _TRIDENT_COMPRESSION_COMPRESSED_STREAM_H_
#define _TRIDENT_COMPRESSION_COMPRESSED_STREAM_H_
#include <google/protobuf/io/zero_copy_stream.h>
#include <trident/rpc_option.pb.h>
#define HAVE_SNAPPY 1
namespace trident {
/// Base class for all compressed output streams with additional methods
class AbstractCompressedOutputStream : public google::protobuf::io::ZeroCopyOutputStream {
public:
/// Make sure that all data is compressed and written
virtual bool Flush() = 0;
virtual bool Close() = 0;
};
/// Base class for all compressed input streams with an ExpectAtEnd method.
class AbstractCompressedInputStream : public google::protobuf::io::ZeroCopyInputStream {
public:
/// ExpectAtEnd returns true if there is no more compressed data to process
virtual bool ExpectAtEnd() = 0;
};
/////////////////////////////////////////////////
// Compress type defined in `rpc_option.proto':
// enum CompressType {
// CompressTypeNone = 0;
// CompressTypeGzip = 1;
// CompressTypeZlib = 2;
// CompressTypeSnappy = 3;
// CompressTypeLZ4 = 4;
// }
/////////////////////////////////////////////////
/// Get a pointer to a compressed output stream given an underlying ZeroCopyOutputStream.
/// Specify any of the above compression types, and a compression level (for use in ZLIB).
AbstractCompressedOutputStream * get_compressed_output_stream(
google::protobuf::io::ZeroCopyOutputStream * ostream, CompressType type, int level=1);
/// Get a pointer to a compressed input stream given an underlying ZeroCopyInputStream.
/// Specify any of the above compression types.
AbstractCompressedInputStream * get_compressed_input_stream(
google::protobuf::io::ZeroCopyInputStream * istream, CompressType type);
} // namespace trident
#endif // _TRIDENT_COMPRESSION_COMPRESSED_STREAM_H_