xref: /aosp_15_r20/external/grpc-grpc/include/grpc/compression.h (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_COMPRESSION_H
20 #define GRPC_COMPRESSION_H
21 
22 #include <stdlib.h>
23 
24 #include <grpc/impl/compression_types.h>  // IWYU pragma: export
25 #include <grpc/slice.h>
26 #include <grpc/support/port_platform.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /** Return if an algorithm is message compression algorithm. */
33 GRPCAPI int grpc_compression_algorithm_is_message(
34     grpc_compression_algorithm algorithm);
35 
36 /** Return if an algorithm is stream compression algorithm. */
37 GRPCAPI int grpc_compression_algorithm_is_stream(
38     grpc_compression_algorithm algorithm);
39 
40 /** Parses the \a slice as a grpc_compression_algorithm instance and updating \a
41  * algorithm. Returns 1 upon success, 0 otherwise. */
42 GRPCAPI int grpc_compression_algorithm_parse(
43     grpc_slice name, grpc_compression_algorithm* algorithm);
44 
45 /** Updates \a name with the encoding name corresponding to a valid \a
46  * algorithm. Note that \a name is statically allocated and must *not* be freed.
47  * Returns 1 upon success, 0 otherwise. */
48 GRPCAPI int grpc_compression_algorithm_name(
49     grpc_compression_algorithm algorithm, const char** name);
50 
51 /** Returns the compression algorithm corresponding to \a level for the
52  * compression algorithms encoded in the \a accepted_encodings bitset.*/
53 GRPCAPI grpc_compression_algorithm grpc_compression_algorithm_for_level(
54     grpc_compression_level level, uint32_t accepted_encodings);
55 
56 GRPCAPI void grpc_compression_options_init(grpc_compression_options* opts);
57 
58 /** Mark \a algorithm as enabled in \a opts. */
59 GRPCAPI void grpc_compression_options_enable_algorithm(
60     grpc_compression_options* opts, grpc_compression_algorithm algorithm);
61 
62 /** Mark \a algorithm as disabled in \a opts. */
63 GRPCAPI void grpc_compression_options_disable_algorithm(
64     grpc_compression_options* opts, grpc_compression_algorithm algorithm);
65 
66 /** Returns true if \a algorithm is marked as enabled in \a opts. */
67 GRPCAPI int grpc_compression_options_is_algorithm_enabled(
68     const grpc_compression_options* opts, grpc_compression_algorithm algorithm);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif /* GRPC_COMPRESSION_H */
75