PostGIS  2.2.7dev-r@@SVN_REVISION@@
bytebuffer.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: bytebuffer.h 12198 2014-01-29 17:49:35Z pramsey $
3  *
4  * PostGIS - Spatial Types for PostgreSQL
5  * Copyright 2015 Nicklas Avén <nicklas.aven@jordogskog.no>
6  *
7  * Redistribution and use in source and binary forms, with or
8  * without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  *
19  * The name of the author may not be used to endorse or promote
20  * products derived from this software without specific prior
21  * written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
24  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34  * THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  **********************************************************************/
37 
38 #ifndef _BYTEBUFFER_H
39 #define _BYTEBUFFER_H 1
40 
41 #include <stdlib.h>
42 #include <stdarg.h>
43 #include <stdint.h>
44 #include "varint.h"
45 
46 #include "lwgeom_log.h"
47 #define BYTEBUFFER_STARTSIZE 128
48 
49 typedef struct
50 {
51  size_t capacity;
52  uint8_t *buf_start;
53  uint8_t *writecursor;
54  uint8_t *readcursor;
55 }
57 
58 void bytebuffer_init_with_size(bytebuffer_t *b, size_t size);
63 void bytebuffer_append_byte(bytebuffer_t *s, const uint8_t val);
64 void bytebuffer_append_varint(bytebuffer_t *s, const int64_t val);
65 void bytebuffer_append_uvarint(bytebuffer_t *s, const uint64_t val);
69 bytebuffer_t* bytebuffer_merge(bytebuffer_t **buff_array, int nbuffers);
71 
72 void bytebuffer_append_bytebuffer(bytebuffer_t *write_to,bytebuffer_t *write_from);
73 void bytebuffer_append_bulk(bytebuffer_t *s, void * start, size_t size);
74 void bytebuffer_append_int(bytebuffer_t *buf, const int val, int swap);
75 void bytebuffer_append_double(bytebuffer_t *buf, const double val, int swap);
76 #endif /* _BYTEBUFFER_H */
uint8_t * writecursor
Definition: bytebuffer.h:53
void bytebuffer_append_bytebuffer(bytebuffer_t *write_to, bytebuffer_t *write_from)
Writes a uint8_t value to the buffer.
Definition: bytebuffer.c:184
bytebuffer_t * bytebuffer_create(void)
Allocate a new bytebuffer_t.
Definition: bytebuffer.c:46
uint8_t * readcursor
Definition: bytebuffer.h:54
void bytebuffer_init_with_size(bytebuffer_t *b, size_t size)
Allocate just the internal buffer of an existing bytebuffer_t struct.
Definition: bytebuffer.c:75
void bytebuffer_append_byte(bytebuffer_t *s, const uint8_t val)
Writes a uint8_t value to the buffer.
Definition: bytebuffer.c:157
bytebuffer_t * bytebuffer_create_with_size(size_t size)
Allocate a new bytebuffer_t.
Definition: bytebuffer.c:56
uint64_t bytebuffer_read_uvarint(bytebuffer_t *s)
Reads a unsigned varInt from the buffer.
Definition: bytebuffer.c:325
void bytebuffer_append_double(bytebuffer_t *buf, const double val, int swap)
Writes a float64 to the buffer.
Definition: bytebuffer.c:271
bytebuffer_t * bytebuffer_merge(bytebuffer_t **buff_array, int nbuffers)
Returns a new bytebuffer were both ingoing bytebuffers is merged.
Definition: bytebuffer.c:348
void bytebuffer_reset_reading(bytebuffer_t *s)
Set the read cursor to the beginning.
Definition: bytebuffer.c:110
size_t capacity
Definition: bytebuffer.h:51
void bytebuffer_clear(bytebuffer_t *s)
Reset the bytebuffer_t.
Definition: bytebuffer.c:121
void bytebuffer_append_varint(bytebuffer_t *s, const int64_t val)
Writes a signed varInt to the buffer.
Definition: bytebuffer.c:199
char * s
Definition: cu_in_wkt.c:23
void bytebuffer_append_uvarint(bytebuffer_t *s, const uint64_t val)
Writes a unsigned varInt to the buffer.
Definition: bytebuffer.c:212
void bytebuffer_destroy(bytebuffer_t *s)
Free the bytebuffer_t and all memory managed within it.
Definition: bytebuffer.c:87
void bytebuffer_append_bulk(bytebuffer_t *s, void *start, size_t size)
Writes a uint8_t value to the buffer.
Definition: bytebuffer.c:171
void bytebuffer_append_int(bytebuffer_t *buf, const int val, int swap)
Definition: bytebuffer.c:226
uint8_t * buf_start
Definition: bytebuffer.h:52
size_t bytebuffer_getlength(bytebuffer_t *s)
Returns the length of the current buffer.
Definition: bytebuffer.c:337
int64_t bytebuffer_read_varint(bytebuffer_t *s)
Reads a signed varInt from the buffer.
Definition: bytebuffer.c:313