Updated copyright year.
[umurmur.git] / src / google / protobuf-c / protobuf-c-data-buffer.h
1
2 #ifndef __PROTOBUF_C_DATA_BUFFER_H_
3 #define __PROTOBUF_C_DATA_BUFFER_H_
4
5 #include "protobuf-c.h"
6 #include <stdarg.h>
7
8
9 typedef struct _ProtobufCDataBuffer ProtobufCDataBuffer;
10 typedef struct _ProtobufCDataBufferFragment ProtobufCDataBufferFragment;
11
12 struct _ProtobufCDataBufferFragment
13 {
14   ProtobufCDataBufferFragment *next;
15   unsigned buf_start;   /* offset in buf of valid data */
16   unsigned buf_length;  /* length of valid data in buf */
17 };
18
19 struct _ProtobufCDataBuffer
20 {
21   size_t size;
22
23   ProtobufCDataBufferFragment    *first_frag;
24   ProtobufCDataBufferFragment    *last_frag;
25   ProtobufCAllocator *allocator;
26 };
27
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);
32
33 size_t   protobuf_c_data_buffer_read                (ProtobufCDataBuffer    *buffer,
34                                                      void*      data,
35                                                      size_t         max_length);
36 size_t   protobuf_c_data_buffer_peek                (const ProtobufCDataBuffer* buffer,
37                                                      void*      data,
38                                                      size_t        max_length);
39 size_t   protobuf_c_data_buffer_discard             (ProtobufCDataBuffer    *buffer,
40                                                      size_t        max_discard);
41 char    *protobuf_c_data_buffer_read_line           (ProtobufCDataBuffer    *buffer);
42
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);
47
48 int      protobuf_c_data_buffer_index_of(ProtobufCDataBuffer *buffer,
49                                          char       char_to_find);
50 /* 
51  * Appending to the buffer.
52  */
53 void     protobuf_c_data_buffer_append              (ProtobufCDataBuffer    *buffer, 
54                                          const void   *data,
55                                          size_t        length);
56 void     protobuf_c_data_buffer_append_string       (ProtobufCDataBuffer    *buffer, 
57                                          const char   *string);
58 void     protobuf_c_data_buffer_append_char         (ProtobufCDataBuffer    *buffer, 
59                                          char          character);
60 void     protobuf_c_data_buffer_append_repeated_char(ProtobufCDataBuffer    *buffer, 
61                                          char          character,
62                                          size_t        count);
63 #define protobuf_c_data_buffer_append_zeros(buffer, count) \
64   protobuf_c_data_buffer_append_repeated_char ((buffer), 0, (count))
65
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,
69                                          size_t        data_length,
70                                          size_t        count);
71
72
73 void     protobuf_c_data_buffer_append_string0      (ProtobufCDataBuffer    *buffer,
74                                          const char   *string);
75
76
77 /* Take all the contents from src and append
78  * them to dst, leaving src empty.
79  */
80 size_t   protobuf_c_data_buffer_drain               (ProtobufCDataBuffer    *dst,
81                                          ProtobufCDataBuffer    *src);
82
83 /* Like `drain', but only transfers some of the data. */
84 size_t   protobuf_c_data_buffer_transfer            (ProtobufCDataBuffer    *dst,
85                                           ProtobufCDataBuffer    *src,
86                                          size_t        max_transfer);
87
88 /* file-descriptor mucking */
89 int      protobuf_c_data_buffer_writev              (ProtobufCDataBuffer       *read_from,
90                                          int              fd);
91 int      protobuf_c_data_buffer_writev_len          (ProtobufCDataBuffer       *read_from,
92                                          int              fd,
93                                          size_t           max_bytes);
94 int      protobuf_c_data_buffer_read_in_fd          (ProtobufCDataBuffer       *write_to,
95                                          int              read_from);
96
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);
100
101 /* Free all unused buffer fragments. */
102 void     protobuf_c_data_buffer_cleanup_recycling_bin ();
103
104 #endif