3 Copyright 2011 David Robillard <http://drobilla.net>
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
15 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
18 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 THE POSSIBILITY OF SUCH DAMAGE.
34 # define PACKED __attribute__((__packed__))
46 typedef struct _RDFF* RDFF;
49 Status codes for function returns.
52 RDFF_STATUS_OK = 0, /**< Success. */
53 RDFF_STATUS_UNKNOWN_ERROR = 1, /**< Unknown error. */
54 RDFF_STATUS_EOF = 2, /**< End of file. */
55 RDFF_STATUS_CORRUPT = 3 /**< Corrupt data. */
59 Generic RIFF chunk header.
62 char type[4]; /**< Chunk type ID. */
63 uint32_t size; /**< Size of chunk body (not including header). */
64 char data[]; /**< Chunk body. */
68 Body of a RDFF "urid" chunk.
71 uint32_t id; /**< Numeric ID of URI in this RDFF. */
72 char uri[]; /**< URI string. */
73 } PACKED RDFFURIChunk;
76 Body of a RDFF "trip" chunk.
79 uint32_t subject; /**< Subject URI ID. */
80 uint32_t predicate; /**< Predicate URI ID. */
81 uint32_t object_type; /**< Object type URI ID. */
82 uint32_t object_size; /**< Size of object data. */
83 char object[]; /**< Object data. */
84 } PACKED RDFFTripleChunk;
87 Open/Create a new RDFF file.
90 rdff_open(const char* path, bool write);
93 Write a URI ID to @a file.
96 rdff_write_uri(RDFF file,
102 Write a key/value record to @a file.
105 rdff_write_triple(RDFF file,
108 uint32_t object_type,
109 uint32_t object_size,
113 Read a chunk from @a file.
115 @param buf MUST point to an RDFFChunk dynamically allocated with malloc.
116 The @a size field (i.e. (*buf)->size) MUST be set to the amount of available
117 memory in the chunk (not including the header). If this is insufficient,
118 *buf will be resized using realloc.
121 rdff_read_chunk(RDFF file,
126 After this call, @a file is invalid.
129 rdff_close(RDFF file);
135 #endif /* RDFF_RDFF_H */