1 /* 2 * Copyright 2010, Lloyd Hilaiel. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * 3. Neither the name of Lloyd Hilaiel nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef __YAJL_BUF_H__ 34 #define __YAJL_BUF_H__ 35 36 #include "yajl_common.h" 37 #include "yajl_alloc.h" 38 39 /* 40 * Implementation/performance notes. If this were moved to a header 41 * only implementation using #define's where possible we might be 42 * able to sqeeze a little performance out of the guy by killing function 43 * call overhead. YMMV. 44 */ 45 46 /** 47 * yajl_buf is a buffer with exponential growth. the buffer ensures that 48 * you are always null padded. 49 */ 50 typedef struct yajl_buf_t * yajl_buf; 51 52 /* allocate a new buffer */ 53 yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc); 54 55 /* free the buffer */ 56 void yajl_buf_free(yajl_buf buf); 57 58 /* append a number of bytes to the buffer */ 59 void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len); 60 61 /* empty the buffer */ 62 void yajl_buf_clear(yajl_buf buf); 63 64 /* get a pointer to the beginning of the buffer */ 65 const unsigned char * yajl_buf_data(yajl_buf buf); 66 67 /* get the length of the buffer */ 68 unsigned int yajl_buf_len(yajl_buf buf); 69 70 /* truncate the buffer */ 71 void yajl_buf_truncate(yajl_buf buf, unsigned int len); 72 73 #endif 74