2 #ifndef __PROTOBUF_C_DATA_BUFFER_H_
3 #define __PROTOBUF_C_DATA_BUFFER_H_
5 #include "protobuf-c.h"
9 typedef struct _ProtobufCDataBuffer ProtobufCDataBuffer;
10 typedef struct _ProtobufCDataBufferFragment ProtobufCDataBufferFragment;
12 struct _ProtobufCDataBufferFragment
14 ProtobufCDataBufferFragment *next;
15 unsigned buf_start; /* offset in buf of valid data */
16 unsigned buf_length; /* length of valid data in buf */
19 struct _ProtobufCDataBuffer
23 ProtobufCDataBufferFragment *first_frag;
24 ProtobufCDataBufferFragment *last_frag;
25 ProtobufCAllocator *allocator;
28 void protobuf_c_data_buffer_init (ProtobufCDataBuffer *buffer,
29 ProtobufCAllocator *allocator);
30 void protobuf_c_data_buffer_clear (ProtobufCDataBuffer *buffer);
31 void protobuf_c_data_buffer_reset (ProtobufCDataBuffer *buffer);
33 size_t protobuf_c_data_buffer_read (ProtobufCDataBuffer *buffer,
36 size_t protobuf_c_data_buffer_peek (const ProtobufCDataBuffer* buffer,
39 size_t protobuf_c_data_buffer_discard (ProtobufCDataBuffer *buffer,
41 char *protobuf_c_data_buffer_read_line (ProtobufCDataBuffer *buffer);
43 char *protobuf_c_data_buffer_parse_string0 (ProtobufCDataBuffer *buffer);
44 /* Returns first char of buffer, or -1. */
45 int protobuf_c_data_buffer_peek_char (const ProtobufCDataBuffer *buffer);
46 int protobuf_c_data_buffer_read_char (ProtobufCDataBuffer *buffer);
48 int protobuf_c_data_buffer_index_of(ProtobufCDataBuffer *buffer,
51 * Appending to the buffer.
53 void protobuf_c_data_buffer_append (ProtobufCDataBuffer *buffer,
56 void protobuf_c_data_buffer_append_string (ProtobufCDataBuffer *buffer,
58 void protobuf_c_data_buffer_append_char (ProtobufCDataBuffer *buffer,
60 void protobuf_c_data_buffer_append_repeated_char(ProtobufCDataBuffer *buffer,
63 #define protobuf_c_data_buffer_append_zeros(buffer, count) \
64 protobuf_c_data_buffer_append_repeated_char ((buffer), 0, (count))
66 /* XXX: protobuf_c_data_buffer_append_repeated_data() is UNIMPLEMENTED */
67 void protobuf_c_data_buffer_append_repeated_data(ProtobufCDataBuffer *buffer,
68 const void *data_to_repeat,
73 void protobuf_c_data_buffer_append_string0 (ProtobufCDataBuffer *buffer,
77 /* Take all the contents from src and append
78 * them to dst, leaving src empty.
80 size_t protobuf_c_data_buffer_drain (ProtobufCDataBuffer *dst,
81 ProtobufCDataBuffer *src);
83 /* Like `drain', but only transfers some of the data. */
84 size_t protobuf_c_data_buffer_transfer (ProtobufCDataBuffer *dst,
85 ProtobufCDataBuffer *src,
88 /* file-descriptor mucking */
89 int protobuf_c_data_buffer_writev (ProtobufCDataBuffer *read_from,
91 int protobuf_c_data_buffer_writev_len (ProtobufCDataBuffer *read_from,
94 int protobuf_c_data_buffer_read_in_fd (ProtobufCDataBuffer *write_to,
97 /* This deallocates memory used by the buffer-- you are responsible
98 * for the allocation and deallocation of the ProtobufCDataBuffer itself. */
99 void protobuf_c_data_buffer_destruct (ProtobufCDataBuffer *to_destroy);
101 /* Free all unused buffer fragments. */
102 void protobuf_c_data_buffer_cleanup_recycling_bin ();