All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Macros | Enumerations | Functions
as_bytes.h File Reference
#include <aerospike/as_std.h>
#include <aerospike/as_util.h>
#include <aerospike/as_val.h>
+ Include dependency graph for as_bytes.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  as_bytes
 

Macros

#define as_bytes_inita(__bytes, __capacity)
 

Enumerations

enum  as_bytes_type {
  AS_BYTES_UNDEF = 0, AS_BYTES_INTEGER = 1, AS_BYTES_DOUBLE = 2, AS_BYTES_STRING = 3,
  AS_BYTES_BLOB = 4, AS_BYTES_JAVA = 7, AS_BYTES_CSHARP = 8, AS_BYTES_PYTHON = 9,
  AS_BYTES_RUBY = 10, AS_BYTES_PHP = 11, AS_BYTES_ERLANG = 12, AS_BYTES_VECTOR = 16,
  AS_BYTES_BOOL = 17, AS_BYTES_HLL = 18, AS_BYTES_MAP = 19, AS_BYTES_LIST = 20,
  AS_BYTES_GEOJSON = 23, AS_BYTES_TYPE_MAX = 24
}
 

Functions

AS_EXTERN bool as_bytes_append (as_bytes *bytes, const uint8_t *value, uint32_t size)
 
static bool as_bytes_append_byte (as_bytes *bytes, uint8_t value)
 
static bool as_bytes_append_double (as_bytes *bytes, double value)
 
static bool as_bytes_append_int16 (as_bytes *bytes, int16_t value)
 
static bool as_bytes_append_int32 (as_bytes *bytes, int32_t value)
 
static bool as_bytes_append_int64 (as_bytes *bytes, int64_t value)
 
static uint32_t as_bytes_capacity (const as_bytes *bytes)
 
AS_EXTERN uint32_t as_bytes_copy (const as_bytes *bytes, uint32_t index, uint8_t *value, uint32_t size)
 
static void as_bytes_destroy (as_bytes *bytes)
 
AS_EXTERN bool as_bytes_ensure (as_bytes *bytes, uint32_t capacity, bool resize)
 
AS_EXTERN int as_bytes_from_string (uint8_t *bytes, uint32_t bytes_size, const char *str)
 
static as_bytesas_bytes_fromval (const as_val *v)
 
static uint8_t * as_bytes_get (const as_bytes *bytes)
 
static uint32_t as_bytes_get_byte (const as_bytes *bytes, uint32_t index, uint8_t *value)
 
static uint32_t as_bytes_get_double (const as_bytes *bytes, uint32_t index, double *value)
 
static uint32_t as_bytes_get_int16 (const as_bytes *bytes, uint32_t index, int16_t *value)
 
static uint32_t as_bytes_get_int32 (const as_bytes *bytes, uint32_t index, int32_t *value)
 
static uint32_t as_bytes_get_int64 (const as_bytes *bytes, uint32_t index, int64_t *value)
 
static as_bytes_type as_bytes_get_type (const as_bytes *bytes)
 
AS_EXTERN uint32_t as_bytes_get_var_int (const as_bytes *bytes, uint32_t index, uint32_t *value)
 
static uint8_t * as_bytes_getorelse (const as_bytes *bytes, uint8_t *fallback)
 
AS_EXTERN as_bytesas_bytes_init (as_bytes *bytes, uint32_t capacity)
 
AS_EXTERN as_bytesas_bytes_init_wrap (as_bytes *bytes, uint8_t *value, uint32_t size, bool free)
 
AS_EXTERN as_bytesas_bytes_new (uint32_t capacity)
 
AS_EXTERN as_bytesas_bytes_new_wrap (uint8_t *value, uint32_t size, bool free)
 
AS_EXTERN bool as_bytes_set (as_bytes *bytes, uint32_t index, const uint8_t *value, uint32_t size)
 
static bool as_bytes_set_byte (as_bytes *bytes, uint32_t index, uint8_t value)
 
static bool as_bytes_set_double (as_bytes *bytes, uint32_t index, double value)
 
static bool as_bytes_set_int16 (as_bytes *bytes, uint32_t index, int16_t value)
 
static bool as_bytes_set_int32 (as_bytes *bytes, uint32_t index, int32_t value)
 
static bool as_bytes_set_int64 (as_bytes *bytes, uint32_t index, int64_t value)
 
static void as_bytes_set_type (as_bytes *bytes, as_bytes_type type)
 
AS_EXTERN uint32_t as_bytes_set_var_int (const as_bytes *bytes, uint32_t index, uint32_t value)
 
static uint32_t as_bytes_size (const as_bytes *bytes)
 
AS_EXTERN bool as_bytes_to_string (const uint8_t *bytes, uint32_t bytes_size, char *str, uint32_t str_size)
 
AS_EXTERN bool as_bytes_to_string_with_prefix (const uint8_t *bytes, uint32_t bytes_size, char *str, uint32_t str_size)
 
static uint8_t * as_bytes_tobytes (const as_bytes *bytes, uint32_t *size)
 
static as_valas_bytes_toval (const as_bytes *b)
 
AS_EXTERN bool as_bytes_truncate (as_bytes *bytes, uint32_t n)
 
AS_EXTERN void as_bytes_val_destroy (as_val *v)
 
AS_EXTERN uint32_t as_bytes_val_hashcode (const as_val *v)
 
AS_EXTERN char * as_bytes_val_tostring (const as_val *v)
 

Macro Definition Documentation

#define as_bytes_inita (   __bytes,
  __capacity 
)
Value:
as_bytes_init(__bytes, 0);\
(__bytes)->type = AS_BYTES_BLOB;\
(__bytes)->free = false;\
(__bytes)->capacity = (__capacity);\
(__bytes)->size = 0;\
(__bytes)->value = (uint8_t*) alloca(sizeof(uint8_t) * (__capacity));
AS_EXTERN as_bytes * as_bytes_init(as_bytes *bytes, uint32_t capacity)
uint8_t type
Definition: as_proto.h:36

Initializes a stack allocated as_bytes. Allocates an internal buffer on the stack of specified capacity using alloca().

as_bytes bytes;
as_bytes_inita(&bytes, 10);
Parameters
__bytesThe bytes to initialize.
__capacityThe number of bytes to allocate on the heap.

Definition at line 303 of file as_bytes.h.

Enumeration Type Documentation

Types for as_bytes.type

Enumerator
AS_BYTES_UNDEF 

Type is Undefined

AS_BYTES_INTEGER 

Integer

AS_BYTES_DOUBLE 

Double

AS_BYTES_STRING 

String

AS_BYTES_BLOB 

Generic BLOB

AS_BYTES_JAVA 

Serialized Java Object

AS_BYTES_CSHARP 

Serialized C# Object

AS_BYTES_PYTHON 

Pickled Python Object

AS_BYTES_RUBY 

Marshalled Ruby Object

AS_BYTES_PHP 

Serialized PHP Object

AS_BYTES_ERLANG 

Serialized Erlang Data

AS_BYTES_VECTOR 

Vector

AS_BYTES_BOOL 

Boolean

AS_BYTES_HLL 

HyperLogLog

AS_BYTES_MAP 

Map

AS_BYTES_LIST 

List

AS_BYTES_GEOJSON 

GeoJSON Data

AS_BYTES_TYPE_MAX 

Upper bounds for the enum

Definition at line 35 of file as_bytes.h.

Function Documentation

AS_EXTERN bool as_bytes_append ( as_bytes bytes,
const uint8_t *  value,
uint32_t  size 
)

Append raw bytes of given size.

uint8_t value[3] = {'a','b','c'};
as_bytes_append(&bytes, value, 3);
Parameters
bytesThe bytes to append to.
valueThe buffer to read from.
sizeThe number of bytes to read from the value.
Returns
On success, true. Otherwise an error occurred.
static bool as_bytes_append_byte ( as_bytes bytes,
uint8_t  value 
)
inlinestatic

Append a uint8_t (byte).

as_bytes_append_byte(&bytes, 'a');
Returns
On success, true. Otherwise an error occurred.

Definition at line 817 of file as_bytes.h.

References as_bytes::as_bytes_append().

static bool as_bytes_append_double ( as_bytes bytes,
double  value 
)
inlinestatic

Append a double value.

as_bytes_append_double(&bytes, 123.456);
Returns
On success, true. Otherwise an error occurred.

Definition at line 881 of file as_bytes.h.

References as_bytes::as_bytes_append().

static bool as_bytes_append_int16 ( as_bytes bytes,
int16_t  value 
)
inlinestatic

Append an int16_t value.

as_bytes_append_int16(&bytes, 123);
Returns
On success, true. Otherwise an error occurred.

Definition at line 833 of file as_bytes.h.

References as_bytes::as_bytes_append().

static bool as_bytes_append_int32 ( as_bytes bytes,
int32_t  value 
)
inlinestatic

Append an int32_t value.

as_bytes_append_int32(&bytes, 123);
Returns
On success, true. Otherwise an error occurred.

Definition at line 849 of file as_bytes.h.

References as_bytes::as_bytes_append().

static bool as_bytes_append_int64 ( as_bytes bytes,
int64_t  value 
)
inlinestatic

Append an int64_t value.

as_bytes_append_int64(&bytes, 123);
Returns
On success, true. Otherwise an error occurred.

Definition at line 865 of file as_bytes.h.

References as_bytes::as_bytes_append().

static uint32_t as_bytes_capacity ( const as_bytes bytes)
inlinestatic

Get the number of bytes allocated.

Parameters
bytesThe bytes to get the capacity of.
Returns
The number of bytes allocated.

Definition at line 434 of file as_bytes.h.

References as_bytes::capacity.

AS_EXTERN uint32_t as_bytes_copy ( const as_bytes bytes,
uint32_t  index,
uint8_t *  value,
uint32_t  size 
)

Copy into value up to size bytes from the given as_bytes, returning the number of bytes copied.

uint8_t value[3] = {0};
uint32_t sz = as_bytes_copy(&bytes, 0, value, 3);
if ( sz == 0 ) {
// sz == 0, means that an error occurred
}
Parameters
bytesThe bytes to read from.
indexThe positing in bytes to read from.
valueThe byte buffer to copy into.
sizeThe number of bytes to copy into the buffer.
Returns
The number of bytes read and stored into value. 0 (zero) indicates an error has occurred.
static void as_bytes_destroy ( as_bytes bytes)
inlinestatic

Destroy the as_bytes and release associated resources.

Parameters
bytesThe bytes to destroy.

Definition at line 401 of file as_bytes.h.

References as_val_destroy.

AS_EXTERN bool as_bytes_ensure ( as_bytes bytes,
uint32_t  capacity,
bool  resize 
)

Ensure the bytes buffer can handle capacity bytes.

If resize is true and capacity exceeds the capacity of the bytes's buffer, then resize the capacity of the buffer to capacity bytes. If the buffer was heap allocated, then cf_realloc() will be used to resize. If the buffer was stack allocated, it will be converted to a heap allocated buffer using cf_malloc() and then its contents will be copied into the new heap allocated buffer.

If resize is false, and if the capacity is not sufficient, then return false.

as_bytes_ensure(&bytes, 100, true);
Parameters
bytesThe bytes to ensure the capacity of.
capacityThe total number of bytes to ensure bytes can handle.
resizeIf true and capacity is not sufficient, then resize the buffer.
Returns
On success, true. Otherwise an error occurred.
AS_EXTERN int as_bytes_from_string ( uint8_t *  bytes,
uint32_t  bytes_size,
const char *  str 
)

Convert hexidecimal string to byte array.

Parameters
bytesTarget byte array.
bytes_sizeSize of byte array.
strSource hex string in format [0x][0-9]|[a-f]|[A-F]. 0x prefix is optional.
Returns
count of bytes converted or -1 on invalid hex chars or byte array truncation.
static as_bytes * as_bytes_fromval ( const as_val v)
inlinestatic

Convert from an as_val.

Definition at line 977 of file as_bytes.h.

References AS_BYTES, and as_util_fromval.

static uint8_t * as_bytes_get ( const as_bytes bytes)
inlinestatic

Get the raw value of this instance.

uint8_t * raw = as_bytes_get(&bytes);
Parameters
bytesThe bytes to get the raw value from.
Returns
The pointer to the raw value.

Definition at line 503 of file as_bytes.h.

References as_bytes::as_bytes_getorelse().

static uint32_t as_bytes_get_byte ( const as_bytes bytes,
uint32_t  index,
uint8_t *  value 
)
inlinestatic

Read a single byte from the given bytes.

uint8_t value = 0;
uint32_t sz = as_bytes_get_byte(&bytes, 0, &value);
if ( sz == 0 ) {
// sz == 0, means that an error occurred
}
Returns
The number of bytes read and stored into value. 0 (zero) indicates an error has occurred.

Definition at line 555 of file as_bytes.h.

References as_bytes::as_bytes_copy().

static uint32_t as_bytes_get_double ( const as_bytes bytes,
uint32_t  index,
double *  value 
)
inlinestatic

Read a double from the given bytes.

double value = 0;
uint32_t sz = as_bytes_get_double(&bytes, 0, &value);
if ( sz == 0 ) {
// sz == 0, means that an error occurred
}
Returns
The number of bytes read and stored into value. 0 (zero) indicates an error has occurred.

Definition at line 639 of file as_bytes.h.

References as_bytes::as_bytes_copy().

static uint32_t as_bytes_get_int16 ( const as_bytes bytes,
uint32_t  index,
int16_t *  value 
)
inlinestatic

Read an int16_t from the given bytes.

int16_t value = 0;
uint32_t sz = as_bytes_get_int16(&bytes, 0, &value);
if ( sz == 0 ) {
// sz == 0, means that an error occurred
}
Returns
The number of bytes read and stored into value. 0 (zero) indicates an error has occurred.

Definition at line 576 of file as_bytes.h.

References as_bytes::as_bytes_copy().

static uint32_t as_bytes_get_int32 ( const as_bytes bytes,
uint32_t  index,
int32_t *  value 
)
inlinestatic

Read an int32_t from the given bytes.

int32_t value = 0;
uint32_t sz = as_bytes_get_int32(&bytes, 0, &value);
if ( sz == 0 ) {
// sz == 0, means that an error occurred
}
Returns
The number of bytes read and stored into value. 0 (zero) indicates an error has occurred.

Definition at line 597 of file as_bytes.h.

References as_bytes::as_bytes_copy().

static uint32_t as_bytes_get_int64 ( const as_bytes bytes,
uint32_t  index,
int64_t *  value 
)
inlinestatic

Read an int64_t from the given bytes.

int64_t value = 0;
uint32_t sz = as_bytes_get_int64(&bytes, 0, &value);
if ( sz == 0 ) {
// sz == 0, means that an error occurred
}
Returns
The number of bytes read and stored into value. 0 (zero) indicates an error has occurred.

Definition at line 618 of file as_bytes.h.

References as_bytes::as_bytes_copy().

static as_bytes_type as_bytes_get_type ( const as_bytes bytes)
inlinestatic

Get the type of bytes.

Parameters
bytesThe bytes to get the type of.
Returns
The type of bytes.

Definition at line 449 of file as_bytes.h.

References AS_BYTES_UNDEF, and as_bytes::type.

AS_EXTERN uint32_t as_bytes_get_var_int ( const as_bytes bytes,
uint32_t  index,
uint32_t *  value 
)

Decode an integer in variable 7-bit format. The high bit indicates if more bytes are used.

uint32_t value = 0;
uint32_t sz = as_bytes_get_var_int(&bytes, 0, &value);
if ( sz == 0 ) {
// sz == 0, means that an error occurred
}
Returns
The number of bytes copied in to value.
static uint8_t * as_bytes_getorelse ( const as_bytes bytes,
uint8_t *  fallback 
)
inlinestatic

Get the raw value of this instance. If the instance is NULL, then return the fallback value.

uint8_t * raw = as_bytes_getorelse(&bytes, NULL);
Parameters
bytesThe bytes to get the raw value from.
fallbackThe value to return if bytes is NULL.
Returns
The pointer to the raw value if bytes is not NULL. Otherwise return the fallback.

Definition at line 485 of file as_bytes.h.

References as_bytes::value.

AS_EXTERN as_bytes * as_bytes_init ( as_bytes bytes,
uint32_t  capacity 
)

Initializes a stack allocated as_bytes. Allocates an internal buffer on the heap of specified capacity using cf_malloc().

as_bytes bytes;
as_bytes_init_empty(&bytes, 10);
Parameters
bytesThe bytes to initialize.
capacityThe number of bytes to allocate on the heap.
Returns
On success, the initializes bytes. Otherwise NULL.
AS_EXTERN as_bytes * as_bytes_init_wrap ( as_bytes bytes,
uint8_t *  value,
uint32_t  size,
bool  free 
)

Initializes a stack allocated as_bytes, wrapping the given buffer.

uint8_t raw[10] = {0};
as_bytes bytes;
as_bytes_init_wrap(&bytes, raw, 10, false);
Parameters
bytesThe bytes to initialize.
valueThe initial value.
sizeThe number of bytes of the initial value.
freeIf true, then as_bytes_destroy() will free the value.
Returns
On success, the initializes bytes. Otherwise NULL.
AS_EXTERN as_bytes * as_bytes_new ( uint32_t  capacity)

Create and initialize a new heap allocated as_bytes. Allocates an internal buffer on the heap of specified capacity using cf_malloc().

as_bytes * bytes = as_bytes_new(10);
Parameters
capacityThe number of bytes to allocate.
Returns
On success, the initializes bytes. Otherwise NULL.
AS_EXTERN as_bytes * as_bytes_new_wrap ( uint8_t *  value,
uint32_t  size,
bool  free 
)

Creates a new heap allocated as_bytes, wrapping the given buffer.

uint8_t raw[10] = {0};
as_bytes * bytes = as_bytes_new_wrap(raw, 10, false);
Parameters
valueThe initial value.
sizeThe number of bytes of the initial value.
freeIf true, then as_bytes_destroy() will free the value.
Returns
On success, the initializes bytes. Otherwise NULL.
AS_EXTERN bool as_bytes_set ( as_bytes bytes,
uint32_t  index,
const uint8_t *  value,
uint32_t  size 
)

Copy raw bytes of given size into the given as_bytes starting at specified index.

as_bytes_set(&bytes, 0, (uint8_t[]){'a','b','c'}, 3);
Parameters
bytesThe bytes to write to.
indexThe position to write to.
valueThe buffer to read from.
sizeThe number of bytes to read from the value.
Returns
On success, true. Otherwise an error occurred.
static bool as_bytes_set_byte ( as_bytes bytes,
uint32_t  index,
uint8_t  value 
)
inlinestatic

Set a byte at given index.

as_bytes_set_byte(&bytes, 0, 'a');
Returns
On success, true. Otherwise an error occurred.

Definition at line 696 of file as_bytes.h.

References as_bytes::as_bytes_set().

static bool as_bytes_set_double ( as_bytes bytes,
uint32_t  index,
double  value 
)
inlinestatic

Set double at given index.

as_bytes_set_double(&bytes, 0, 4.4);
Returns
On success, true. Otherwise an error occurred.

Definition at line 760 of file as_bytes.h.

References as_bytes::as_bytes_set().

static bool as_bytes_set_int16 ( as_bytes bytes,
uint32_t  index,
int16_t  value 
)
inlinestatic

Set 16 bit integer at given index.

as_bytes_set_int16(&bytes, 0, 1);
Returns
On success, true. Otherwise an error occurred.

Definition at line 712 of file as_bytes.h.

References as_bytes::as_bytes_set().

static bool as_bytes_set_int32 ( as_bytes bytes,
uint32_t  index,
int32_t  value 
)
inlinestatic

Set 32 bit integer at given index.

as_bytes_set_int32(&bytes, 0, 2);
Returns
On success, true. Otherwise an error occurred.

Definition at line 728 of file as_bytes.h.

References as_bytes::as_bytes_set().

static bool as_bytes_set_int64 ( as_bytes bytes,
uint32_t  index,
int64_t  value 
)
inlinestatic

Set 64 bit integer at given index.

as_bytes_set_int64(&bytes, 0, 3);
Returns
On success, true. Otherwise an error occurred.

Definition at line 744 of file as_bytes.h.

References as_bytes::as_bytes_set().

static void as_bytes_set_type ( as_bytes bytes,
as_bytes_type  type 
)
inlinestatic

Set the type of bytes.

Parameters
bytesThe bytes to set the type of.
typeThe type for the bytes.

Definition at line 463 of file as_bytes.h.

References type, and as_bytes::type.

AS_EXTERN uint32_t as_bytes_set_var_int ( const as_bytes bytes,
uint32_t  index,
uint32_t  value 
)

Encode an integer in 7-bit format. The high bit indicates if more bytes are used.

as_bytes_set_var_int(&bytes, 0, 36);

The bytes must be sufficiently sized for the data being written. To ensure the bytes is allocated sufficiently, you will need to call as_bytes_ensure().

Returns
The number of bytes copied into byte array.
static uint32_t as_bytes_size ( const as_bytes bytes)
inlinestatic

Get the number of bytes used.

Parameters
bytesThe bytes to get the size of.
Returns
The number of bytes used.

Definition at line 419 of file as_bytes.h.

References as_bytes::size.

AS_EXTERN bool as_bytes_to_string ( const uint8_t *  bytes,
uint32_t  bytes_size,
char *  str,
uint32_t  str_size 
)

Convert byte array to hexidecimal string.

Parameters
bytesSource byte array.
bytes_sizeSize of byte array.
strTarget hex string.
str_sizeSize of hex string.
Returns
true on success, false on string truncation.
AS_EXTERN bool as_bytes_to_string_with_prefix ( const uint8_t *  bytes,
uint32_t  bytes_size,
char *  str,
uint32_t  str_size 
)

Convert byte array to hexidecimal string with 0x prefix.

Parameters
bytesSource byte array.
bytes_sizeSize of byte array.
strTarget hex string.
str_sizeSize of hex string.
Returns
true on success, false on string truncation.
static uint8_t * as_bytes_tobytes ( const as_bytes bytes,
uint32_t *  size 
)
inlinestatic

Get the bytes value.

Deprecated:
Use as_bytes_get() instead.

Definition at line 947 of file as_bytes.h.

References as_bytes::size, and as_bytes::value.

static as_val * as_bytes_toval ( const as_bytes b)
inlinestatic

Convert to an as_val.

Definition at line 967 of file as_bytes.h.

AS_EXTERN bool as_bytes_truncate ( as_bytes bytes,
uint32_t  n 
)

Truncate the bytes' buffer. The size specifies the number of bytes to remove from the end of the buffer.

This means, if the buffer has size of 100, and we truncate 10, then the remaining size is 90.

Truncation does not modify the capacity of the buffer.

as_bytes_truncate(&bytes, 10);
Parameters
bytesThe bytes to truncate.
nThe number of bytes to remove from the end.
Returns
On success, true. Otherwise an error occurred.
AS_EXTERN void as_bytes_val_destroy ( as_val v)
private

Internal helper function for destroying an as_val.

AS_EXTERN uint32_t as_bytes_val_hashcode ( const as_val v)
private

Internal helper function for getting the hashcode of an as_val.

AS_EXTERN char* as_bytes_val_tostring ( const as_val v)
private

Internal helper function for getting the string representation of an as_val.