1/*
2 * particle.h
3 *
4 * Copyright (C) 2015 Aerospike, Inc.
5 *
6 * Portions may be licensed to Aerospike, Inc. under one or more contributor
7 * license agreements.
8 *
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU Affero General Public License as published by the Free
11 * Software Foundation, either version 3 of the License, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/
21 */
22
23#pragma once
24
25#include <stdint.h>
26#include "aerospike/as_val.h"
27#include "base/datamodel.h"
28
29//------------------------------------------------
30// Particle interface specification - functions.
31//
32
33// Destructor, etc.
34typedef void (*as_particle_destructor_fn) (as_particle *p);
35typedef uint32_t (*as_particle_size_fn) (const as_particle *p);
36
37// Handle "wire" format.
38typedef int32_t (*as_particle_concat_size_from_wire_fn) (as_particle_type wire_type, const uint8_t *wire_value, uint32_t value_size, as_particle **pp);
39typedef int (*as_particle_append_from_wire_fn) (as_particle_type wire_type, const uint8_t *wire_value, uint32_t value_size, as_particle **pp);
40typedef int (*as_particle_prepend_from_wire_fn) (as_particle_type wire_type, const uint8_t *wire_value, uint32_t value_size, as_particle **pp);
41typedef int (*as_particle_incr_from_wire_fn) (as_particle_type wire_type, const uint8_t *wire_value, uint32_t value_size, as_particle **pp);
42typedef int32_t (*as_particle_size_from_wire_fn) (const uint8_t *wire_value, uint32_t value_size);
43typedef int (*as_particle_from_wire_fn) (as_particle_type wire_type, const uint8_t *wire_value, uint32_t value_size, as_particle **pp);
44typedef int (*as_particle_compare_from_wire_fn) (const as_particle *p, as_particle_type wire_type, const uint8_t *wire_value, uint32_t value_size);
45typedef uint32_t (*as_particle_wire_size_fn) (const as_particle *p);
46typedef uint32_t (*as_particle_to_wire_fn) (const as_particle *p, uint8_t *wire);
47
48// Handle as_val translation.
49typedef uint32_t (*as_particle_size_from_asval_fn) (const as_val *val);
50typedef void (*as_particle_from_asval_fn) (const as_val *val, as_particle **pp);
51typedef as_val *(*as_particle_to_asval_fn) (const as_particle *p);
52typedef uint32_t (*as_particle_asval_wire_size_fn) (const as_val *val);
53typedef uint32_t (*as_particle_asval_to_wire_fn) (const as_val *val, uint8_t *wire);
54
55// Handle msgpack translation.
56typedef uint32_t (*as_particle_size_from_msgpack_fn) (const uint8_t *packed, uint32_t packed_size);
57typedef void (*as_particle_from_msgpack_fn) (const uint8_t *packed, uint32_t packed_size, as_particle **pp);
58
59// Handle on-device "flat" format.
60typedef const uint8_t * (*as_particle_skip_flat_fn) (const uint8_t *flat, const uint8_t *end);
61typedef const uint8_t * (*as_particle_cast_from_flat_fn) (const uint8_t *flat, const uint8_t *end, as_particle **pp);
62typedef const uint8_t * (*as_particle_from_flat_fn) (const uint8_t *flat, const uint8_t *end, as_particle **pp);
63typedef uint32_t (*as_particle_flat_size_fn) (const as_particle *p);
64typedef uint32_t (*as_particle_to_flat_fn) (const as_particle *p, uint8_t *flat);
65
66//------------------------------------------------
67// Particle interface specification - vtable.
68//
69
70typedef struct as_particle_vtable_s {
71 as_particle_destructor_fn destructor_fn;
72 as_particle_size_fn size_fn;
73
74 as_particle_concat_size_from_wire_fn concat_size_from_wire_fn;
75 as_particle_append_from_wire_fn append_from_wire_fn;
76 as_particle_prepend_from_wire_fn prepend_from_wire_fn;
77 as_particle_incr_from_wire_fn incr_from_wire_fn;
78 as_particle_size_from_wire_fn size_from_wire_fn;
79 as_particle_from_wire_fn from_wire_fn;
80 as_particle_compare_from_wire_fn compare_from_wire_fn; // TODO - unused - keep this?
81 as_particle_wire_size_fn wire_size_fn;
82 as_particle_to_wire_fn to_wire_fn;
83
84 as_particle_size_from_asval_fn size_from_asval_fn;
85 as_particle_from_asval_fn from_asval_fn;
86 as_particle_to_asval_fn to_asval_fn;
87 as_particle_asval_wire_size_fn asval_wire_size_fn;
88 as_particle_asval_to_wire_fn asval_to_wire_fn;
89
90 as_particle_size_from_msgpack_fn size_from_msgpack_fn;
91 as_particle_from_msgpack_fn from_msgpack_fn;
92
93 as_particle_skip_flat_fn skip_flat_fn;
94 as_particle_cast_from_flat_fn cast_from_flat_fn;
95 as_particle_from_flat_fn from_flat_fn;
96 as_particle_flat_size_fn flat_size_fn;
97 as_particle_to_flat_fn to_flat_fn;
98} as_particle_vtable;
99