/usr/include/luasandbox/util/protobuf.h is in libluasandbox-dev 1.2.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** Generic protobuf utility functions @file */
#ifndef luasandbox_util_protobuf_h_
#define luasandbox_util_protobuf_h_
#include <stddef.h>
#include <stdbool.h>
#include "output_buffer.h"
#include "util.h"
#define LSB_MAX_VARINT_BYTES 10
typedef enum {
LSB_PB_WT_VARINT = 0,
LSB_PB_WT_FIXED64 = 1,
LSB_PB_WT_LENGTH = 2,
LSB_PB_WT_SGROUP = 3,
LSB_PB_WT_EGROUP = 4,
LSB_PB_WT_FIXED32 = 5
} lsb_pb_wire_types;
#ifdef __cplusplus
extern "C" {
#endif
/**
* Extract the tag and wiretype from a protobuf key
*
* @param p Key
* @param tag Tag Id
* @param wiretype Wiretype Id
*
* @return LSB_EXPORT const char*
*/
LSB_UTIL_EXPORT
const char* lsb_pb_read_key(const char *p, int *tag, int *wiretype);
/**
* Writes a field key (tag id/wire type) to the output buffer.
*
* @param ob Pointer to the output data buffer.
* @param tag Field identifier.
* @param wiretype Field wire type.
*
* @return lsb_err_value NULL on success error message on failure
*/
LSB_UTIL_EXPORT lsb_err_value
lsb_pb_write_key(lsb_output_buffer *ob, unsigned char tag,
unsigned char wiretype);
/**
* Reads the varint into the provided variable
*
* @param p Start of buffer
* @param e End of buffer
* @param vi Varint value
*
* @return const char* Position in the buffer after the varint
*/
LSB_UTIL_EXPORT
const char* lsb_pb_read_varint(const char *p, const char *e, long long *vi);
/**
* Outputs the varint to an existing buffer
*
* @param buf Pointer to buffer with at least LSB_MAX_VARINT_BYTES available,
* @param i Number to be encoded.
*
* @return int Number of bytes written
*/
LSB_UTIL_EXPORT int lsb_pb_output_varint(char *buf, unsigned long long i);
/**
* Writes a varint encoded number to the output buffer.
*
* @param ob Pointer to the output data buffer.
* @param i Number to be encoded.
*
* @return lsb_err_value NULL on success error message on failure
*/
LSB_UTIL_EXPORT lsb_err_value
lsb_pb_write_varint(lsb_output_buffer *ob, unsigned long long i);
/**
* Writes a bool to the output buffer.
*
* @param ob Pointer to the output data buffer.
* @param i Number to be encoded.
*
* @return lsb_err_value NULL on success error message on failure
*/
LSB_UTIL_EXPORT lsb_err_value lsb_pb_write_bool(lsb_output_buffer *ob, int i);
/**
* Writes a double to the output buffer.
*
* @param ob Pointer to the output data buffer.
* @param i Double to be encoded.
*
* @return lsb_err_value NULL on success error message on failure
*/
LSB_UTIL_EXPORT lsb_err_value
lsb_pb_write_double(lsb_output_buffer *ob, double i);
/**
* Writes a string to the output buffer.
*
* @param ob Pointer to the output data buffer.
* @param tag Field identifier.
* @param s String to output.
* @param len Length of s.
*
* @return lsb_err_value NULL on success error message on failure
*/
LSB_UTIL_EXPORT lsb_err_value
lsb_pb_write_string(lsb_output_buffer *ob, char tag, const char *s, size_t len);
/**
* Updates the field length in the output buffer once the size is known, this
* allows for single pass encoding.
*
* @param ob Pointer to the output data buffer.
* @param len_pos Position in the output buffer where the length should be
* written.
*
* @return lsb_err_value NULL on success error message on failure
*/
LSB_UTIL_EXPORT lsb_err_value
lsb_pb_update_field_length(lsb_output_buffer *ob, size_t len_pos);
#ifdef __cplusplus
}
#endif
#endif
|