ubjsc  0.5
Enterprise-grade C library for manipulating UBJSON
ubjs_writer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Tomasz Sieprawski
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  **/
31 #ifndef HAVE_UBJS_WRITER
32 #define HAVE_UBJS_WRITER
33 
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38 
39 #include "ubjs_common.h"
40 #include "ubjs_library.h"
41 #include "ubjs_primitives.h"
42 
44 struct ubjs_writer;
45 
47 struct ubjs_writer_context;
48 
50 typedef struct ubjs_writer ubjs_writer;
51 
54 
61 typedef void (*ubjs_writer_context_would_write)(ubjs_writer_context *this, uint8_t *data,
62  unsigned int length);
63 
70 typedef void (*ubjs_writer_context_would_print)(ubjs_writer_context *this, char *data,
71  unsigned int length);
72 
78 typedef void (*ubjs_writer_context_free)(ubjs_writer_context *this);
79 
81 struct ubjs_writer_context
82 {
84  void *userdata;
91 };
92 
103 UBJS_EXPORT ubjs_result ubjs_writer_new(ubjs_library *lib, ubjs_writer **pthis,
104  ubjs_writer_context *context);
112 UBJS_EXPORT ubjs_result ubjs_writer_free(ubjs_writer **pthis);
113 
120 UBJS_EXPORT ubjs_result ubjs_writer_get_context(ubjs_writer *this, ubjs_writer_context **pcontext);
121 
129 UBJS_EXPORT ubjs_result ubjs_writer_write(ubjs_writer *this, ubjs_prmtv *object);
137 UBJS_EXPORT ubjs_result ubjs_writer_print(ubjs_writer *this, ubjs_prmtv *object);
138 
139 #ifdef __cplusplus
140 }
141 #endif
142 
143 #endif
Library handle, allocation callbacks, glues.
Definitions of common types, ubjson markers and some utilities.
struct ubjs_prmtv ubjs_prmtv
Definition: ubjs_primitives.h:166
void(* ubjs_writer_context_would_write)(ubjs_writer_context *this, uint8_t *data, unsigned int length)
Callback when writer produced bytes out of a primitive.
Definition: ubjs_writer.h:61
Library handle.
Definition: ubjs_library.h:827
struct ubjs_writer ubjs_writer
Writer itself.
Definition: ubjs_writer.h:50
ubjs_writer_context_would_write would_write
Definition: ubjs_writer.h:86
User-provided context - callbacks and userdata.
Definition: ubjs_writer.h:81
void * userdata
Definition: ubjs_writer.h:84
void(* ubjs_writer_context_would_print)(ubjs_writer_context *this, char *data, unsigned int length)
Callback when writer produced pretty-printed version of a primitive.
Definition: ubjs_writer.h:70
Wrappers over ubjson primitive types.
void(* ubjs_writer_context_free)(ubjs_writer_context *this)
Callback when writer is about to be free-d.
Definition: ubjs_writer.h:78
ubjs_result
Enum that defines the result of a method.
Definition: ubjs_common.h:73
UBJS_EXPORT ubjs_result ubjs_writer_free(ubjs_writer **pthis)
Frees the writer.
Definition: ubjs_writer_noncontainers.c:78
ubjs_writer_context_would_print would_print
Definition: ubjs_writer.h:88
UBJS_EXPORT ubjs_result ubjs_writer_write(ubjs_writer *this, ubjs_prmtv *object)
Writes a bytestream out of a primitive.
Definition: ubjs_writer_noncontainers.c:145
ubjs_writer_context_free free
Definition: ubjs_writer.h:90
UBJS_EXPORT ubjs_result ubjs_writer_print(ubjs_writer *this, ubjs_prmtv *object)
Pretty-prints out of a primitive.
Definition: ubjs_writer_noncontainers.c:170
UBJS_EXPORT ubjs_result ubjs_writer_new(ubjs_library *lib, ubjs_writer **pthis, ubjs_writer_context *context)
Creates new writer.
Definition: ubjs_writer_noncontainers.c:61
UBJS_EXPORT ubjs_result ubjs_writer_get_context(ubjs_writer *this, ubjs_writer_context **pcontext)
Gets user context from the writer.
Definition: ubjs_writer_noncontainers.c:96