|
| 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_BYTE_BUFFER_H |
| 20 | +#define GRPC_BYTE_BUFFER_H |
| 21 | + |
| 22 | +#include <grpc/impl/codegen/grpc_types.h> |
| 23 | +#include <grpc/slice_buffer.h> |
| 24 | + |
| 25 | +#ifdef __cplusplus |
| 26 | +extern "C" { |
| 27 | +#endif |
| 28 | + |
| 29 | +/** Returns a RAW byte buffer instance over the given slices (up to \a nslices). |
| 30 | + * |
| 31 | + * Increases the reference count for all \a slices processed. The user is |
| 32 | + * responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/ |
| 33 | +GRPCAPI grpc_byte_buffer *grpc_raw_byte_buffer_create(grpc_slice *slices, |
| 34 | + size_t nslices); |
| 35 | + |
| 36 | +/** Returns a *compressed* RAW byte buffer instance over the given slices (up to |
| 37 | + * \a nslices). The \a compression argument defines the compression algorithm |
| 38 | + * used to generate the data in \a slices. |
| 39 | + * |
| 40 | + * Increases the reference count for all \a slices processed. The user is |
| 41 | + * responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/ |
| 42 | +GRPCAPI grpc_byte_buffer *grpc_raw_compressed_byte_buffer_create( |
| 43 | + grpc_slice *slices, size_t nslices, grpc_compression_algorithm compression); |
| 44 | + |
| 45 | +/** Copies input byte buffer \a bb. |
| 46 | + * |
| 47 | + * Increases the reference count of all the source slices. The user is |
| 48 | + * responsible for calling grpc_byte_buffer_destroy over the returned copy. */ |
| 49 | +GRPCAPI grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb); |
| 50 | + |
| 51 | +/** Returns the size of the given byte buffer, in bytes. */ |
| 52 | +GRPCAPI size_t grpc_byte_buffer_length(grpc_byte_buffer *bb); |
| 53 | + |
| 54 | +/** Destroys \a byte_buffer deallocating all its memory. */ |
| 55 | +GRPCAPI void grpc_byte_buffer_destroy(grpc_byte_buffer *byte_buffer); |
| 56 | + |
| 57 | +/** Reader for byte buffers. Iterates over slices in the byte buffer */ |
| 58 | +struct grpc_byte_buffer_reader; |
| 59 | +typedef struct grpc_byte_buffer_reader grpc_byte_buffer_reader; |
| 60 | + |
| 61 | +/** Initialize \a reader to read over \a buffer. |
| 62 | + * Returns 1 upon success, 0 otherwise. */ |
| 63 | +GRPCAPI int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader, |
| 64 | + grpc_byte_buffer *buffer); |
| 65 | + |
| 66 | +/** Cleanup and destroy \a reader */ |
| 67 | +GRPCAPI void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader); |
| 68 | + |
| 69 | +/** Updates \a slice with the next piece of data from from \a reader and returns |
| 70 | + * 1. Returns 0 at the end of the stream. Caller is responsible for calling |
| 71 | + * grpc_slice_unref on the result. */ |
| 72 | +GRPCAPI int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader, |
| 73 | + grpc_slice *slice); |
| 74 | + |
| 75 | +/** Merge all data from \a reader into single slice */ |
| 76 | +GRPCAPI grpc_slice |
| 77 | +grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader *reader); |
| 78 | + |
| 79 | +/** Returns a RAW byte buffer instance from the output of \a reader. */ |
| 80 | +GRPCAPI grpc_byte_buffer *grpc_raw_byte_buffer_from_reader( |
| 81 | + grpc_byte_buffer_reader *reader); |
| 82 | + |
| 83 | +#ifdef __cplusplus |
| 84 | +} |
| 85 | +#endif |
| 86 | + |
| 87 | +#endif /* GRPC_BYTE_BUFFER_H */ |
0 commit comments