ubjsc  0.4-dev
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_primitives.h"
41 
43 struct ubjs_writer;
44 
46 struct ubjs_writer_context;
47 
49 typedef struct ubjs_writer ubjs_writer;
50 
53 
60 typedef void (*ubjs_writer_context_would_write)(ubjs_writer_context *this, uint8_t *data,
61  unsigned int length);
62 
69 typedef void (*ubjs_writer_context_would_print)(ubjs_writer_context *this, char *data,
70  unsigned int length);
71 
77 typedef void (*ubjs_writer_context_free)(ubjs_writer_context *this);
78 
80 struct ubjs_writer_context
81 {
83  void *userdata;
90 };
91 
102 UBJS_EXPORT ubjs_result ubjs_writer_new(ubjs_library *lib, ubjs_writer **pthis,
103  ubjs_writer_context *context);
111 UBJS_EXPORT ubjs_result ubjs_writer_free(ubjs_writer **pthis);
112 
119 UBJS_EXPORT ubjs_result ubjs_writer_get_context(ubjs_writer *this, ubjs_writer_context **pcontext);
120 
128 UBJS_EXPORT ubjs_result ubjs_writer_write(ubjs_writer *this, ubjs_prmtv *object);
136 UBJS_EXPORT ubjs_result ubjs_writer_print(ubjs_writer *this, ubjs_prmtv *object);
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif
Definitions of common types, ubjson markers and some utilities.
struct ubjs_prmtv ubjs_prmtv
Definition: ubjs_primitives.h:165
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:60
struct ubjs_writer ubjs_writer
Writer itself.
Definition: ubjs_writer.h:49
ubjs_writer_context_would_write would_write
Definition: ubjs_writer.h:85
User-provided context - callbacks and userdata.
Definition: ubjs_writer.h:80
void * userdata
Definition: ubjs_writer.h:83
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:69
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:77
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:81
ubjs_writer_context_would_print would_print
Definition: ubjs_writer.h:87
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:148
ubjs_writer_context_free free
Definition: ubjs_writer.h:89
UBJS_EXPORT ubjs_result ubjs_writer_print(ubjs_writer *this, ubjs_prmtv *object)
Pretty-prints out of a primitive.
Definition: ubjs_writer_noncontainers.c:173
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:64
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:99
struct ubjs_library ubjs_library
Library handle.
Definition: ubjs_common.h:203