ubjsc  0.6
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_builder;
48 
50 typedef struct ubjs_writer ubjs_writer;
51 
54 
62 typedef void (*ubjs_writer_would_write_f)(void *userdata, uint8_t *data,
63  unsigned int length);
64 
72 typedef void (*ubjs_writer_would_print_f)(void *userdata, char *data,
73  unsigned int length);
74 
82 typedef void (*ubjs_writer_debug_f)(void *userdata, unsigned int len, char *message);
83 
90 typedef void (*ubjs_writer_free_f)(void *userdata);
91 
112  void *userdata);
120  ubjs_writer_would_write_f would_write_f);
128  ubjs_writer_would_print_f would_print_f);
136  ubjs_writer_debug_f debug_f);
144  ubjs_writer_free_f free_f);
145 
156  ubjs_writer **pthis);
157 
166 UBJS_EXPORT ubjs_result ubjs_writer_free(ubjs_writer **pthis);
167 
175 UBJS_EXPORT ubjs_result ubjs_writer_get_userdata(ubjs_writer *this, void **puserdata);
176 
185 UBJS_EXPORT ubjs_result ubjs_writer_write(ubjs_writer *this, ubjs_prmtv *object);
194 UBJS_EXPORT ubjs_result ubjs_writer_print(ubjs_writer *this, ubjs_prmtv *object);
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #endif
Library handle, allocation callbacks, glues.
UBJS_EXPORT ubjs_result ubjs_writer_builder_free(ubjs_writer_builder **pthis)
Frees the writer builder.
Definition: ubjs_writer.c:82
Definitions of common types, ubjson markers and some utilities.
struct ubjs_prmtv ubjs_prmtv
Definition: ubjs_primitives.h:166
UBJS_EXPORT ubjs_result ubjs_writer_builder_new(ubjs_library *lib, ubjs_writer_builder **pthis)
Creates new writer builder.
Definition: ubjs_writer.c:61
struct ubjs_writer_builder ubjs_writer_builder
Writer builder.
Definition: ubjs_writer.h:53
UBJS_EXPORT ubjs_result ubjs_writer_builder_set_would_print_f(ubjs_writer_builder *this, ubjs_writer_would_print_f would_print_f)
Sets the would-print callback for builder.
Definition: ubjs_writer.c:120
struct ubjs_writer ubjs_writer
Writer itself.
Definition: ubjs_writer.h:50
UBJS_EXPORT ubjs_result ubjs_writer_builder_set_would_write_f(ubjs_writer_builder *this, ubjs_writer_would_write_f would_write_f)
Sets the would-write callback for builder.
Definition: ubjs_writer.c:108
UBJS_EXPORT ubjs_result ubjs_writer_builder_set_debug_f(ubjs_writer_builder *this, ubjs_writer_debug_f debug_f)
Sets the debug callback for builder.
Definition: ubjs_writer.c:132
Wrappers over ubjson primitive types.
ubjs_result
Enum that defines the result of a method.
Definition: ubjs_common.h:73
UBJS_EXPORT ubjs_result ubjs_writer_get_userdata(ubjs_writer *this, void **puserdata)
Gets userdata from the writer.
Definition: ubjs_writer.c:213
void(* ubjs_writer_debug_f)(void *userdata, unsigned int len, char *message)
Callback to be executed just when writer issued a debug message.
Definition: ubjs_writer.h:82
UBJS_EXPORT ubjs_result ubjs_writer_free(ubjs_writer **pthis)
Frees the writer.
Definition: ubjs_writer.c:186
void(* ubjs_writer_would_print_f)(void *userdata, char *data, unsigned int length)
Callback when writer produced pretty-printed version of a primitive.
Definition: ubjs_writer.h:72
UBJS_EXPORT ubjs_result ubjs_writer_write(ubjs_writer *this, ubjs_prmtv *object)
Writes a bytestream out of a primitive.
Definition: ubjs_writer.c:280
UBJS_EXPORT ubjs_result ubjs_writer_print(ubjs_writer *this, ubjs_prmtv *object)
Pretty-prints out of a primitive.
Definition: ubjs_writer.c:305
void(* ubjs_writer_free_f)(void *userdata)
Callback when writer is about to be free-d.
Definition: ubjs_writer.h:90
UBJS_EXPORT ubjs_result ubjs_writer_builder_set_userdata(ubjs_writer_builder *this, void *userdata)
Sets the userdata for builder.
Definition: ubjs_writer.c:97
UBJS_EXPORT ubjs_result ubjs_writer_builder_set_free_f(ubjs_writer_builder *this, ubjs_writer_free_f free_f)
Sets the userdata free callback for builder.
Definition: ubjs_writer.c:144
void(* ubjs_writer_would_write_f)(void *userdata, uint8_t *data, unsigned int length)
Callback when writer produced bytes out of a primitive.
Definition: ubjs_writer.h:62
struct ubjs_library ubjs_library
Library handle.
Definition: ubjs_library.h:67
UBJS_EXPORT ubjs_result ubjs_writer_builder_build(ubjs_writer_builder *builder, ubjs_writer **pthis)
Builds new writer.
Definition: ubjs_writer.c:156