luasandbox  1.4.0
Generic Lua sandbox for dynamic data analysis
Macros | Enumerations | Functions
protobuf.h File Reference

Generic protobuf utility functions. More...

#include <stddef.h>
#include <stdbool.h>
#include "output_buffer.h"
#include "util.h"
Include dependency graph for protobuf.h:

Go to the source code of this file.

Macros

#define LSB_MAX_VARINT_BYTES   10
 

Enumerations

enum  lsb_pb_wire_types {
  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
}
 

Functions

LSB_UTIL_EXPORT const char * lsb_pb_read_key (const char *p, int *tag, int *wiretype)
 Extract the tag and wiretype from a protobuf key. More...
 
LSB_UTIL_EXPORT lsb_err_value lsb_pb_write_key (lsb_output_buffer *ob, unsigned char tag, unsigned char wiretype)
 Writes a field key (tag id/wire type) to the output buffer. More...
 
LSB_UTIL_EXPORT const char * lsb_pb_read_varint (const char *p, const char *e, long long *vi)
 Reads the varint into the provided variable. More...
 
LSB_UTIL_EXPORT int lsb_pb_output_varint (char *buf, unsigned long long i)
 Outputs the varint to an existing buffer. More...
 
LSB_UTIL_EXPORT lsb_err_value lsb_pb_write_varint (lsb_output_buffer *ob, unsigned long long i)
 Writes a varint encoded number to the output buffer. More...
 
LSB_UTIL_EXPORT lsb_err_value lsb_pb_write_bool (lsb_output_buffer *ob, int i)
 Writes a bool to the output buffer. More...
 
LSB_UTIL_EXPORT lsb_err_value lsb_pb_write_double (lsb_output_buffer *ob, double i)
 Writes a double to the output buffer. More...
 
LSB_UTIL_EXPORT lsb_err_value lsb_pb_write_string (lsb_output_buffer *ob, char tag, const char *s, size_t len)
 Writes a string to the output buffer. More...
 
LSB_UTIL_EXPORT lsb_err_value lsb_pb_update_field_length (lsb_output_buffer *ob, size_t len_pos)
 Updates the field length in the output buffer once the size is known, this allows for single pass encoding. More...
 

Detailed Description

Generic protobuf utility functions.

Definition in file protobuf.h.

Macro Definition Documentation

#define LSB_MAX_VARINT_BYTES   10

Definition at line 18 of file protobuf.h.

Enumeration Type Documentation

Enumerator
LSB_PB_WT_VARINT 
LSB_PB_WT_FIXED64 
LSB_PB_WT_LENGTH 
LSB_PB_WT_SGROUP 
LSB_PB_WT_EGROUP 
LSB_PB_WT_FIXED32 

Definition at line 20 of file protobuf.h.

Function Documentation

LSB_UTIL_EXPORT int lsb_pb_output_varint ( char *  buf,
unsigned long long  i 
)

Outputs the varint to an existing buffer.

Parameters
bufPointer to buffer with at least LSB_MAX_VARINT_BYTES available,
iNumber to be encoded.
Returns
int Number of bytes written
LSB_UTIL_EXPORT const char* lsb_pb_read_key ( const char *  p,
int *  tag,
int *  wiretype 
)

Extract the tag and wiretype from a protobuf key.

Parameters
pKey
tagTag Id
wiretypeWiretype Id
Returns
LSB_EXPORT const char*
LSB_UTIL_EXPORT const char* lsb_pb_read_varint ( const char *  p,
const char *  e,
long long *  vi 
)

Reads the varint into the provided variable.

Parameters
pStart of buffer
eEnd of buffer
viVarint value
Returns
const char* Position in the buffer after the varint
LSB_UTIL_EXPORT lsb_err_value lsb_pb_update_field_length ( lsb_output_buffer ob,
size_t  len_pos 
)

Updates the field length in the output buffer once the size is known, this allows for single pass encoding.

Parameters
obPointer to the output data buffer.
len_posPosition in the output buffer where the length should be written.
Returns
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 bool to the output buffer.

Parameters
obPointer to the output data buffer.
iNumber to be encoded.
Returns
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 double to the output buffer.

Parameters
obPointer to the output data buffer.
iDouble to be encoded.
Returns
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 
)

Writes a field key (tag id/wire type) to the output buffer.

Parameters
obPointer to the output data buffer.
tagField identifier.
wiretypeField wire type.
Returns
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 
)

Writes a string to the output buffer.

Parameters
obPointer to the output data buffer.
tagField identifier.
sString to output.
lenLength of s.
Returns
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 varint encoded number to the output buffer.

Parameters
obPointer to the output data buffer.
iNumber to be encoded.
Returns
lsb_err_value NULL on success error message on failure