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_IMPL_CODEGEN_BYTE_BUFFER_H
20#define GRPC_IMPL_CODEGEN_BYTE_BUFFER_H
21
22// IWYU pragma: private, include <grpc/byte_buffer.h>
23
24#include <grpc/impl/codegen/port_platform.h>
25
26#include <grpc/impl/codegen/grpc_types.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/** Returns a RAW byte buffer instance over the given slices (up to \a nslices).
33 *
34 * Increases the reference count for all \a slices processed. The user is
35 * responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/
36GRPCAPI grpc_byte_buffer* grpc_raw_byte_buffer_create(grpc_slice* slices,
37 size_t nslices);
38
39/** Returns a *compressed* RAW byte buffer instance over the given slices (up to
40 * \a nslices). The \a compression argument defines the compression algorithm
41 * used to generate the data in \a slices.
42 *
43 * Increases the reference count for all \a slices processed. The user is
44 * responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/
45GRPCAPI grpc_byte_buffer* grpc_raw_compressed_byte_buffer_create(
46 grpc_slice* slices, size_t nslices, grpc_compression_algorithm compression);
47
48/** Copies input byte buffer \a bb.
49 *
50 * Increases the reference count of all the source slices. The user is
51 * responsible for calling grpc_byte_buffer_destroy over the returned copy. */
52GRPCAPI grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb);
53
54/** Returns the size of the given byte buffer, in bytes. */
55GRPCAPI size_t grpc_byte_buffer_length(grpc_byte_buffer* bb);
56
57/** Destroys \a byte_buffer deallocating all its memory. */
58GRPCAPI void grpc_byte_buffer_destroy(grpc_byte_buffer* bb);
59
60/** Reader for byte buffers. Iterates over slices in the byte buffer */
61struct grpc_byte_buffer_reader;
62typedef struct grpc_byte_buffer_reader grpc_byte_buffer_reader;
63
64/** Initialize \a reader to read over \a buffer.
65 * Returns 1 upon success, 0 otherwise. */
66GRPCAPI int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader* reader,
67 grpc_byte_buffer* buffer);
68
69/** Cleanup and destroy \a reader */
70GRPCAPI void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader* reader);
71
72/** Updates \a slice with the next piece of data from from \a reader and returns
73 * 1. Returns 0 at the end of the stream. Caller is responsible for calling
74 * grpc_slice_unref on the result. */
75GRPCAPI int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader* reader,
76 grpc_slice* slice);
77
78/** EXPERIMENTAL API - This function may be removed and changed, in the future.
79 *
80 * Updates \a slice with the next piece of data from from \a reader and returns
81 * 1. Returns 0 at the end of the stream. Caller is responsible for making sure
82 * the slice pointer remains valid when accessed.
83 *
84 * NOTE: Do not use this function unless the caller can guarantee that the
85 * underlying grpc_byte_buffer outlasts the use of the slice. This is only
86 * safe when the underlying grpc_byte_buffer remains immutable while slice
87 * is being accessed. */
88GRPCAPI int grpc_byte_buffer_reader_peek(grpc_byte_buffer_reader* reader,
89 grpc_slice** slice);
90
91/** Merge all data from \a reader into single slice */
92GRPCAPI grpc_slice
93grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader* reader);
94
95/** Returns a RAW byte buffer instance from the output of \a reader. */
96GRPCAPI grpc_byte_buffer* grpc_raw_byte_buffer_from_reader(
97 grpc_byte_buffer_reader* reader);
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif /* GRPC_IMPL_CODEGEN_BYTE_BUFFER_H */
104

source code of include/grpc/impl/codegen/byte_buffer.h