1 /*------------------------------------------------------------------------------ 2 * 3 * Copyright (c) 2011-2021, EURid vzw. All rights reserved. 4 * The YADIFA TM software product is provided under the BSD 3-clause license: 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * * Neither the name of EURid nor the names of its contributors may be 16 * used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 *------------------------------------------------------------------------------ 32 * 33 */ 34 35 /** @defgroup streaming Streams 36 * @ingroup dnscore 37 * @brief 38 * 39 * 40 * 41 * @{ 42 * 43 *----------------------------------------------------------------------------*/ 44 #pragma once 45 46 #include <dnscore/output_stream.h> 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 /* 53 * The buffer will be freed (free) on close. 54 */ 55 56 #define BYTEARRAY_OWNED 1 57 58 /* 59 * The buffer's size can be changed. 60 */ 61 62 #define BYTEARRAY_DYNAMIC 2 63 64 /* 65 * The internal context has been allocated by a malloc (the default except if the _static variant is used) 66 * YOU MOSTLY WILL NOT USE THAT FLAG 67 */ 68 69 #define BYTEARRAY_ZALLOC_CONTEXT 4 70 71 typedef char bytearray_output_stream_context[sizeof(void*) + 9]; 72 73 void bytearray_output_stream_init(output_stream* out_stream, u8* array,u32 size); 74 void bytearray_output_stream_init_ex(output_stream* out_stream, u8* array,u32 size, u8 flags); 75 76 /* 77 * most of bytearray_output_stream usages function-enclosed : init, work on, close 78 * this variant of initialisation avoids an malloc 79 */ 80 81 void bytearray_output_stream_init_ex_static(output_stream* out_stream, u8* array,u32 size, u8 flags, bytearray_output_stream_context *ctx); 82 83 void bytearray_output_stream_reset(output_stream* out_stream); 84 // can only work if the buffer is owned 85 ya_result bytearray_output_stream_ensure(output_stream* out_stream, u32 size); 86 u32 bytearray_output_stream_size(output_stream* out_stream); 87 u8* bytearray_output_stream_buffer(output_stream* out_stream); 88 u8* bytearray_output_stream_detach(output_stream* out_stream); 89 90 void bytearray_output_stream_set(output_stream* out_stream, u8 *buffer, u32 buffer_size, bool owned); 91 92 /** 93 94 * @param out_stream 95 * @param by 96 * @return the actual rewind_count 97 */ 98 99 u32 bytearray_output_stream_rewind(output_stream* out_stream, u32 rewind_count); 100 101 u8* bytearray_output_stream_zdup(output_stream* out_stream); 102 u8* bytearray_output_stream_dup(output_stream* out_stream); 103 104 #ifdef __cplusplus 105 } 106 #endif 107 108 /** @} */ 109