1 /**********************************************************************
2  *
3  * rttopo - topology library
4  * http://git.osgeo.org/gitea/rttopo/librttopo
5  *
6  * rttopo 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  * rttopo 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 rttopo.  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 
27 #ifndef _BYTEBUFFER_H
28 #define _BYTEBUFFER_H 1
29 
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <stdint.h>
33 #include "varint.h"
34 
35 #include "rtgeom_log.h"
36 #define BYTEBUFFER_STARTSIZE 128
37 
38 typedef struct
39 {
40   size_t capacity;
41   uint8_t *buf_start;
42   uint8_t *writecursor;
43   uint8_t *readcursor;
44 }
45 bytebuffer_t;
46 
47 void bytebuffer_init_with_size(const RTCTX *ctx, bytebuffer_t *b, size_t size);
48 bytebuffer_t *bytebuffer_create_with_size(const RTCTX *ctx, size_t size);
49 bytebuffer_t *bytebuffer_create(const RTCTX *ctx);
50 void bytebuffer_destroy(const RTCTX *ctx, bytebuffer_t *s);
51 void bytebuffer_clear(const RTCTX *ctx, bytebuffer_t *s);
52 void bytebuffer_append_byte(const RTCTX *ctx, bytebuffer_t *s, const uint8_t val);
53 void bytebuffer_append_varint(const RTCTX *ctx, bytebuffer_t *s, const int64_t val);
54 void bytebuffer_append_uvarint(const RTCTX *ctx, bytebuffer_t *s, const uint64_t val);
55 uint64_t bytebuffer_read_uvarint(const RTCTX *ctx, bytebuffer_t *s);
56 int64_t bytebuffer_read_varint(const RTCTX *ctx, bytebuffer_t *s);
57 size_t bytebuffer_getlength(const RTCTX *ctx, bytebuffer_t *s);
58 bytebuffer_t* bytebuffer_merge(const RTCTX *ctx, bytebuffer_t **buff_array, int nbuffers);
59 void bytebuffer_reset_reading(const RTCTX *ctx, bytebuffer_t *s);
60 
61 void bytebuffer_append_bytebuffer(const RTCTX *ctx, bytebuffer_t *write_to,bytebuffer_t *write_from);
62 void bytebuffer_append_bulk(const RTCTX *ctx, bytebuffer_t *s, void * start, size_t size);
63 void bytebuffer_append_int(const RTCTX *ctx, bytebuffer_t *buf, const int val, int swap);
64 void bytebuffer_append_double(const RTCTX *ctx, bytebuffer_t *buf, const double val, int swap);
65 #endif /* _BYTEBUFFER_H */
66