1146773Ssam/*-
2146773Ssam * Copyright (c) 2003, 2004 David Young.  All rights reserved.
3146773Ssam *
4146773Ssam * Redistribution and use in source and binary forms, with or without
5146773Ssam * modification, are permitted provided that the following conditions
6146773Ssam * are met:
7146773Ssam * 1. Redistributions of source code must retain the above copyright
8146773Ssam *    notice, this list of conditions and the following disclaimer.
9146773Ssam * 2. Redistributions in binary form must reproduce the above copyright
10146773Ssam *    notice, this list of conditions and the following disclaimer in the
11146773Ssam *    documentation and/or other materials provided with the distribution.
12146773Ssam * 3. The name of David Young may not be used to endorse or promote
13146773Ssam *    products derived from this software without specific prior
14146773Ssam *    written permission.
15146773Ssam *
16146773Ssam * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
17146773Ssam * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18146773Ssam * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19146773Ssam * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DAVID
20146773Ssam * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21146773Ssam * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22146773Ssam * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23146773Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24146773Ssam * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25146773Ssam * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26146773Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27146773Ssam * OF SUCH DAMAGE.
28146773Ssam */
29146773Ssam
30146773Ssam#ifndef _CPACK_H
31146773Ssam#define _CPACK_H
32146773Ssam
33146773Ssamstruct cpack_state {
34146773Ssam	u_int8_t					*c_buf;
35146773Ssam	u_int8_t					*c_next;
36146773Ssam	size_t						 c_len;
37146773Ssam};
38146773Ssam
39146773Ssamint cpack_init(struct cpack_state *, u_int8_t *, size_t);
40146773Ssam
41146773Ssamint cpack_uint8(struct cpack_state *, u_int8_t *);
42146773Ssamint cpack_uint16(struct cpack_state *, u_int16_t *);
43146773Ssamint cpack_uint32(struct cpack_state *, u_int32_t *);
44146773Ssamint cpack_uint64(struct cpack_state *, u_int64_t *);
45146773Ssam
46235530Sdelphiju_int8_t *cpack_next_boundary(u_int8_t *buf, u_int8_t *p, size_t alignment);
47235530Sdelphiju_int8_t *cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize);
48235530Sdelphij
49146773Ssam#define cpack_int8(__s, __p)	cpack_uint8((__s),  (u_int8_t*)(__p))
50146773Ssam#define cpack_int16(__s, __p)	cpack_uint16((__s), (u_int16_t*)(__p))
51146773Ssam#define cpack_int32(__s, __p)	cpack_uint32((__s), (u_int32_t*)(__p))
52146773Ssam#define cpack_int64(__s, __p)	cpack_uint64((__s), (u_int64_t*)(__p))
53146773Ssam
54146773Ssam#endif /* _CPACK_H */
55