PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/google/protobuf-c/protobuf-c-data-buffer.h

http://protobuf-c.googlecode.com/
C Header | 143 lines | 70 code | 22 blank | 51 comment | 0 complexity | cd9c5943a979441845d43c76f5aab3d7 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*
  2. * Copyright (c) 2008-2011, Dave Benson.
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with
  7. * or without modification, are permitted provided that the
  8. * following conditions are met:
  9. *
  10. * Redistributions of source code must retain the above
  11. * copyright notice, this list of conditions and the following
  12. * disclaimer.
  13. * Redistributions in binary form must reproduce
  14. * the above copyright notice, this list of conditions and
  15. * the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * Neither the name
  19. * of "protobuf-c" nor the names of its contributors
  20. * may be used to endorse or promote products derived from
  21. * this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  24. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  25. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  26. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
  28. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  30. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  31. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  32. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  33. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. #ifndef __PROTOBUF_C_DATA_BUFFER_H_
  39. #define __PROTOBUF_C_DATA_BUFFER_H_
  40. #include "protobuf-c.h"
  41. #include <stdarg.h>
  42. typedef struct _ProtobufCDataBuffer ProtobufCDataBuffer;
  43. typedef struct _ProtobufCDataBufferFragment ProtobufCDataBufferFragment;
  44. struct _ProtobufCDataBufferFragment
  45. {
  46. ProtobufCDataBufferFragment *next;
  47. unsigned buf_start; /* offset in buf of valid data */
  48. unsigned buf_length; /* length of valid data in buf */
  49. };
  50. struct _ProtobufCDataBuffer
  51. {
  52. size_t size;
  53. ProtobufCDataBufferFragment *first_frag;
  54. ProtobufCDataBufferFragment *last_frag;
  55. ProtobufCAllocator *allocator;
  56. };
  57. void protobuf_c_data_buffer_init (ProtobufCDataBuffer *buffer,
  58. ProtobufCAllocator *allocator);
  59. void protobuf_c_data_buffer_clear (ProtobufCDataBuffer *buffer);
  60. void protobuf_c_data_buffer_reset (ProtobufCDataBuffer *buffer);
  61. size_t protobuf_c_data_buffer_read (ProtobufCDataBuffer *buffer,
  62. void* data,
  63. size_t max_length);
  64. size_t protobuf_c_data_buffer_peek (const ProtobufCDataBuffer* buffer,
  65. void* data,
  66. size_t max_length);
  67. size_t protobuf_c_data_buffer_discard (ProtobufCDataBuffer *buffer,
  68. size_t max_discard);
  69. char *protobuf_c_data_buffer_read_line (ProtobufCDataBuffer *buffer);
  70. char *protobuf_c_data_buffer_parse_string0 (ProtobufCDataBuffer *buffer);
  71. /* Returns first char of buffer, or -1. */
  72. int protobuf_c_data_buffer_peek_char (const ProtobufCDataBuffer *buffer);
  73. int protobuf_c_data_buffer_read_char (ProtobufCDataBuffer *buffer);
  74. int protobuf_c_data_buffer_index_of(ProtobufCDataBuffer *buffer,
  75. char char_to_find);
  76. /*
  77. * Appending to the buffer.
  78. */
  79. void protobuf_c_data_buffer_append (ProtobufCDataBuffer *buffer,
  80. const void *data,
  81. size_t length);
  82. void protobuf_c_data_buffer_append_string (ProtobufCDataBuffer *buffer,
  83. const char *string);
  84. void protobuf_c_data_buffer_append_char (ProtobufCDataBuffer *buffer,
  85. char character);
  86. void protobuf_c_data_buffer_append_repeated_char(ProtobufCDataBuffer *buffer,
  87. char character,
  88. size_t count);
  89. #define protobuf_c_data_buffer_append_zeros(buffer, count) \
  90. protobuf_c_data_buffer_append_repeated_char ((buffer), 0, (count))
  91. /* XXX: protobuf_c_data_buffer_append_repeated_data() is UNIMPLEMENTED */
  92. void protobuf_c_data_buffer_append_repeated_data(ProtobufCDataBuffer *buffer,
  93. const void *data_to_repeat,
  94. size_t data_length,
  95. size_t count);
  96. void protobuf_c_data_buffer_append_string0 (ProtobufCDataBuffer *buffer,
  97. const char *string);
  98. /* Take all the contents from src and append
  99. * them to dst, leaving src empty.
  100. */
  101. size_t protobuf_c_data_buffer_drain (ProtobufCDataBuffer *dst,
  102. ProtobufCDataBuffer *src);
  103. /* Like `drain', but only transfers some of the data. */
  104. size_t protobuf_c_data_buffer_transfer (ProtobufCDataBuffer *dst,
  105. ProtobufCDataBuffer *src,
  106. size_t max_transfer);
  107. /* file-descriptor mucking */
  108. int protobuf_c_data_buffer_writev (ProtobufCDataBuffer *read_from,
  109. int fd);
  110. int protobuf_c_data_buffer_writev_len (ProtobufCDataBuffer *read_from,
  111. int fd,
  112. size_t max_bytes);
  113. int protobuf_c_data_buffer_read_in_fd (ProtobufCDataBuffer *write_to,
  114. int read_from);
  115. /* This deallocates memory used by the buffer-- you are responsible
  116. * for the allocation and deallocation of the ProtobufCDataBuffer itself. */
  117. void protobuf_c_data_buffer_destruct (ProtobufCDataBuffer *to_destroy);
  118. /* Free all unused buffer fragments. */
  119. void protobuf_c_data_buffer_cleanup_recycling_bin ();
  120. #endif