1 /**********************************************************************
2  * bytebuffer.h
3  *
4  * Copyright 2013 Paul Ramsey <pramsey@cleverelephant.ca>
5  *
6  * Redistribution and use in source and binary forms, with or
7  * without modification, are permitted provided that the following
8  * conditions are met:
9  *
10  * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  *
18  * The name of the author may not be used to endorse or promote
19  * products derived from this software without specific prior
20  * written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
23  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33  * THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  **********************************************************************/
36 
37 #ifndef _BYTEBUFFER_H
38 #define _BYTEBUFFER_H 1
39 
40 #include <stdlib.h>
41 #include <stdarg.h>
42 #include <string.h>
43 #include <stdio.h>
44 #include <stdint.h>
45 
46 #define BYTEBUFFER_STARTSIZE 1028
47 
48 typedef struct
49 {
50     size_t capacity;
51     uint8_t *bytes_end;
52     uint8_t *bytes_start;
53 }
54 bytebuffer_t;
55 
56 extern bytebuffer_t *bytebuffer_create(void);
57 extern void bytebuffer_destroy(bytebuffer_t *bb);
58 extern void bytebuffer_append(bytebuffer_t *bb, const uint8_t *buffer, size_t buffer_size);
59 extern size_t bytebuffer_getsize(bytebuffer_t *s);
60 extern const uint8_t *bytebuffer_getbytes(bytebuffer_t *bb);
61 extern uint8_t *bytebuffer_getbytescopy(bytebuffer_t *bb);
62 extern size_t bytebuffer_getsize(bytebuffer_t *bb);
63 
64 #include "ght_internal.h"
65 
66 #endif /* _BYTEBUFFER_H */