Loading...
Searching...
No Matches
as_serializer.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2018 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19#include <aerospike/as_buffer.h>
20#include <aerospike/as_std.h>
21#include <aerospike/as_types.h>
22#include <aerospike/as_util.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/******************************************************************************
29 * TYPES
30 *****************************************************************************/
31
32struct as_serializer_hooks_s;
33
34/**
35 * Serializer Object
36 */
37typedef struct as_serializer_s {
38 /**
39 * @private
40 * If true, then as_serializer_destroy() will free this.
41 */
42 bool free;
43
44 /**
45 * Hooks for the serializer
46 */
47 const struct as_serializer_hooks_s *hooks;
49
50/**
51 * Serializer Function Hooks
52 */
53typedef struct as_serializer_hooks_s {
54 void (*destroy)(as_serializer *);
55 int (*serialize)(as_serializer *, const as_val *, as_buffer *);
56 int32_t (*serialize_presized)(as_serializer *, const as_val *, uint8_t *);
57 int (*deserialize)(as_serializer *, as_buffer *, as_val **);
58 uint32_t (*serialize_getsize)(as_serializer *, const as_val *);
60
61/******************************************************************************
62 * FUNCTIONS
63 *****************************************************************************/
64
66
68
70
72
73/******************************************************************************
74 * INLINE FUNCTIONS
75 *****************************************************************************/
76
77static inline int as_serializer_serialize(as_serializer *serializer, as_val *val, as_buffer *buffer)
78{
79 return as_util_hook(serialize, 1, serializer, val, buffer);
80}
81
82/**
83 * Pack directly into pre-sized buffer.
84 * @return -1 if failed
85 * @return length of unpacked buffer
86 */
87static inline int32_t as_serializer_serialize_presized(as_serializer *serializer, const as_val *val, uint8_t *buf)
88{
89 return as_util_hook(serialize_presized, 1, serializer, val, buf);
90}
91
92static inline int as_serializer_deserialize(as_serializer *serializer, as_buffer *buffer, as_val **val)
93{
94 return as_util_hook(deserialize, 1, serializer, buffer, val);
95}
96
97static inline uint32_t as_serializer_serialize_getsize(as_serializer *serializer, as_val *val)
98{
99 return as_util_hook(serialize_getsize, 1, serializer, val);
100}
101
102#ifdef __cplusplus
103} // end extern "C"
104#endif
AS_EXTERN as_serializer * as_serializer_cons(as_serializer *serializer, bool free, const as_serializer_hooks *hooks)
AS_EXTERN as_serializer * as_serializer_init(as_serializer *serializer, const as_serializer_hooks *hooks)
static int32_t as_serializer_serialize_presized(as_serializer *serializer, const as_val *val, uint8_t *buf)
static int as_serializer_serialize(as_serializer *serializer, as_val *val, as_buffer *buffer)
AS_EXTERN as_serializer * as_serializer_new(const as_serializer_hooks *)
static int as_serializer_deserialize(as_serializer *serializer, as_buffer *buffer, as_val **val)
AS_EXTERN void as_serializer_destroy(as_serializer *)
static uint32_t as_serializer_serialize_getsize(as_serializer *serializer, as_val *val)
#define AS_EXTERN
Definition as_std.h:25
#define as_util_hook(hook, default, object,...)
Definition as_util.h:34
const struct as_serializer_hooks_s * hooks