yajl_buf.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef __YAJL_BUF_H__
  17. #define __YAJL_BUF_H__
  18. #include "api/yajl_common.h"
  19. #include "yajl_alloc.h"
  20. /*
  21. * Implementation/performance notes. If this were moved to a header
  22. * only implementation using #define's where possible we might be
  23. * able to sqeeze a little performance out of the guy by killing function
  24. * call overhead. YMMV.
  25. */
  26. /**
  27. * yajl_buf is a buffer with exponential growth. the buffer ensures that
  28. * you are always null padded.
  29. */
  30. typedef struct yajl_buf_t * yajl_buf;
  31. /* allocate a new buffer */
  32. yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc);
  33. /* free the buffer */
  34. void yajl_buf_free(yajl_buf buf);
  35. /* append a number of bytes to the buffer */
  36. void yajl_buf_append(yajl_buf buf, const void * data, size_t len);
  37. /* empty the buffer */
  38. void yajl_buf_clear(yajl_buf buf);
  39. /* get a pointer to the beginning of the buffer */
  40. const unsigned char * yajl_buf_data(yajl_buf buf);
  41. /* get the length of the buffer */
  42. size_t yajl_buf_len(yajl_buf buf);
  43. /* get the allocated size of the buffer */
  44. size_t yajl_buf_capacity(yajl_buf buf);
  45. /* truncate the buffer */
  46. void yajl_buf_truncate(yajl_buf buf, size_t len);
  47. #endif