1 | /* |
2 | * msgpack_sz.h |
3 | * |
4 | * Copyright (C) 2019 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 | //========================================================== |
26 | // Includes. |
27 | // |
28 | |
29 | #include <stdbool.h> |
30 | #include <stdint.h> |
31 | |
32 | |
33 | //========================================================== |
34 | // Typedefs & constants. |
35 | // |
36 | |
37 | typedef struct { |
38 | const uint8_t *buf; |
39 | uint32_t buf_sz; |
40 | uint32_t offset; |
41 | bool has_nonstorage; |
42 | } msgpack_in; |
43 | |
44 | typedef struct msgpack_ext_s { |
45 | const uint8_t *data; // pointer to ext contents |
46 | uint32_t size; // size of ext contents |
47 | uint32_t type_offset; // offset where the type field is located |
48 | uint8_t type; // type of ext contents |
49 | } msgpack_ext; |
50 | |
51 | typedef enum msgpack_cmp_e { |
52 | MSGPACK_CMP_ERROR = -2, |
53 | MSGPACK_CMP_END = -1, |
54 | MSGPACK_CMP_LESS = 0, |
55 | MSGPACK_CMP_EQUAL = 1, |
56 | MSGPACK_CMP_GREATER = 2, |
57 | } msgpack_cmp_t; |
58 | |
59 | |
60 | //========================================================== |
61 | // Public API. |
62 | // |
63 | |
64 | uint32_t msgpack_sz_rep(msgpack_in *mp, uint32_t rep_count); |
65 | static inline uint32_t |
66 | msgpack_sz(msgpack_in *mp) |
67 | { |
68 | return msgpack_sz_rep(mp, 1); |
69 | } |
70 | |
71 | msgpack_cmp_t msgpack_cmp(msgpack_in *mp0, msgpack_in *mp1); |
72 | msgpack_cmp_t msgpack_cmp_peek(const msgpack_in *mp0, const msgpack_in *mp1); |
73 | |