PostGIS  2.4.9dev-r@@SVN_REVISION@@
bytebuffer.h
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright 2015 Nicklas Avén <nicklas.aven@jordogskog.no>
22  *
23  **********************************************************************/
24 
25 
26 #ifndef _BYTEBUFFER_H
27 #define _BYTEBUFFER_H 1
28 
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <stdint.h>
32 #include "varint.h"
33 
34 #include "lwgeom_log.h"
35 #define BYTEBUFFER_STARTSIZE 512
36 #define BYTEBUFFER_STATICSIZE 1024
37 
38 typedef struct
39 {
40  size_t capacity;
45 }
47 
48 void bytebuffer_init_with_size(bytebuffer_t *b, size_t size);
55 void bytebuffer_append_varint(bytebuffer_t *s, const int64_t val);
56 void bytebuffer_append_uvarint(bytebuffer_t *s, const uint64_t val);
59 size_t bytebuffer_getlength(const bytebuffer_t *s);
60 bytebuffer_t* bytebuffer_merge(bytebuffer_t **buff_array, int nbuffers);
62 uint8_t* bytebuffer_get_buffer_copy(const bytebuffer_t *s, size_t *buffer_length);
63 const uint8_t* bytebuffer_get_buffer(const bytebuffer_t *s, size_t *buffer_length);
64 
65 void bytebuffer_append_bytebuffer(bytebuffer_t *write_to,bytebuffer_t *write_from);
66 void bytebuffer_append_bulk(bytebuffer_t *s, void * start, size_t size);
67 void bytebuffer_append_int(bytebuffer_t *buf, const int val, int swap);
68 void bytebuffer_append_double(bytebuffer_t *buf, const double val, int swap);
69 #endif /* _BYTEBUFFER_H */
uint8_t * writecursor
Definition: bytebuffer.h:42
void bytebuffer_append_bytebuffer(bytebuffer_t *write_to, bytebuffer_t *write_from)
Writes a uint8_t value to the buffer.
Definition: bytebuffer.c:224
bytebuffer_t * bytebuffer_create(void)
Allocate a new bytebuffer_t.
Definition: bytebuffer.c:34
#define BYTEBUFFER_STATICSIZE
Definition: bytebuffer.h:36
uint8_t * readcursor
Definition: bytebuffer.h:43
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:71
void bytebuffer_append_byte(bytebuffer_t *s, const uint8_t val)
Writes a uint8_t value to the buffer.
Definition: bytebuffer.c:197
bytebuffer_t * bytebuffer_create_with_size(size_t size)
Allocate a new bytebuffer_t.
Definition: bytebuffer.c:44
uint64_t bytebuffer_read_uvarint(bytebuffer_t *s)
Reads a unsigned varInt from the buffer.
Definition: bytebuffer.c:365
size_t bytebuffer_getlength(const bytebuffer_t *s)
Returns the length of the current buffer.
Definition: bytebuffer.c:377
void bytebuffer_append_double(bytebuffer_t *buf, const double val, int swap)
Writes a float64 to the buffer.
Definition: bytebuffer.c:311
bytebuffer_t * bytebuffer_merge(bytebuffer_t **buff_array, int nbuffers)
Returns a new bytebuffer were both ingoing bytebuffers is merged.
Definition: bytebuffer.c:388
void bytebuffer_reset_reading(bytebuffer_t *s)
Set the read cursor to the beginning.
Definition: bytebuffer.c:119
size_t capacity
Definition: bytebuffer.h:40
void bytebuffer_clear(bytebuffer_t *s)
Reset the bytebuffer_t.
Definition: bytebuffer.c:130
void bytebuffer_append_varint(bytebuffer_t *s, const int64_t val)
Writes a signed varInt to the buffer.
Definition: bytebuffer.c:239
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:252
void bytebuffer_destroy(bytebuffer_t *s)
Free the bytebuffer_t and all memory managed within it.
Definition: bytebuffer.c:91
void bytebuffer_append_bulk(bytebuffer_t *s, void *start, size_t size)
Writes a uint8_t value to the buffer.
Definition: bytebuffer.c:211
const uint8_t * bytebuffer_get_buffer(const bytebuffer_t *s, size_t *buffer_length)
Returns a read-only reference to the internal buffer.
Definition: bytebuffer.c:185
uint8_t * bytebuffer_get_buffer_copy(const bytebuffer_t *s, size_t *buffer_length)
Returns a copy of the internal buffer.
Definition: bytebuffer.c:173
void bytebuffer_append_int(bytebuffer_t *buf, const int val, int swap)
Definition: bytebuffer.c:266
uint8_t * buf_start
Definition: bytebuffer.h:41
unsigned char uint8_t
Definition: uthash.h:79
int64_t bytebuffer_read_varint(bytebuffer_t *s)
Reads a signed varInt from the buffer.
Definition: bytebuffer.c:353
void bytebuffer_destroy_buffer(bytebuffer_t *s)
Free the bytebuffer_t and all memory managed within it.
Definition: bytebuffer.c:104