aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/hdr_histogram/src/hdr_encoding.h
blob: 141093ba3be1f7d40b47b6b643f9ae8f9b2aea3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Created by barkerm on 9/09/15.
//

#ifndef HDR_ENCODING_H
#define HDR_ENCODING_H

#include <stdint.h>

#define MAX_BYTES_LEB128 9

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Writes a int64_t value to the given buffer in LEB128 ZigZag encoded format
 *
 * @param buffer the buffer to write to
 * @param signed_value  the value to write to the buffer
 * @return the number of bytes written to the buffer
 */
int zig_zag_encode_i64(uint8_t* buffer, int64_t signed_value);

/**
 * Read an LEB128 ZigZag encoded long value from the given buffer
 *
 * @param buffer the buffer to read from
 * @param retVal out value to capture the read value
 * @return the number of bytes read from the buffer
 */
int zig_zag_decode_i64(const uint8_t* buffer, int64_t* signed_value);

/**
 * Gets the length in bytes of base64 data, given the input size.
 *
 * @param decoded_size the size of the unencoded values.
 * @return the encoded size
 */
size_t hdr_base64_encoded_len(size_t decoded_size);

/**
 * Encode into base64.
 *
 * @param input the data to encode
 * @param input_len the length of the data to encode
 * @param output the buffer to write the output to
 * @param output_len the number of bytes to write to the output
 */
int hdr_base64_encode(
    const uint8_t* input, size_t input_len, char* output, size_t output_len);

/**
 * Gets the length in bytes of decoded base64 data, given the size of the base64 encoded
 * data.
 *
 * @param encoded_size the size of the encoded value.
 * @return the decoded size
 */
size_t hdr_base64_decoded_len(size_t encoded_size);

/**
 * Decode from base64.
 *
 * @param input the base64 encoded data
 * @param input_len the size in bytes of the endcoded data
 * @param output the buffer to write the decoded data to
 * @param output_len the number of bytes to write to the output data
 */
int hdr_base64_decode(
    const char* input, size_t input_len, uint8_t* output, size_t output_len);

#ifdef __cplusplus
}
#endif

#endif //HDR_HISTOGRAM_HDR_ENCODING_H