Tchatator413
TripEnArvor instant messaging protocol - JSON-based
Loading...
Searching...
No Matches
Macros | Functions
json-helpers.h File Reference

JSON-C library extra functions - Interface. More...

#include "slice.h"
#include <json-c.h>
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define min_json(obj)   json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN)
 Create a minified JSON string from a JSON object.
 
#define json_object_dbg_print(obj)   fprintf(stderr, "json_object_dbg_print: %s\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY))
 Debug-print a JSON object.
 
#define LOG_FMT_JSON_C(fmt, ...)   "json-c: " fmt ": %s" __VA_OPT__(, ) __VA_ARGS__, json_util_get_last_err()
 A format string and arguments for a json-c error.
 
#define LOG_FMT_JSON_TYPE(type, actual, fmt, ...)   "json: " fmt ": type: expected %s, got %s\n" __VA_OPT__(, ) __VA_ARGS__, json_type_to_name(type), json_type_to_name(actual)
 A format string and arguments for a JSON type error.
 

Functions

bool json_object_get_uint16_strict (json_object const *obj, uint16_t *out)
 Get the 16-bit unsigned integer value of a JSON object.
 
bool json_object_get_int_strict (json_object const *obj, int32_t *out)
 Get the 32-bit integer value of a JSON object.
 
bool json_object_get_int64_strict (json_object const *obj, int64_t *out)
 Get the 64-bit integer value of a JSON object.
 
bool json_object_get_string_strict (json_object *obj, slice_t *out)
 Get the string value of a JSON object.
 

Detailed Description

JSON-C library extra functions - Interface.

Author
Raphaƫl
Date
1/02/2025

Definition in file json-helpers.h.

Macro Definition Documentation

◆ json_object_dbg_print

#define json_object_dbg_print (   obj)    fprintf(stderr, "json_object_dbg_print: %s\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY))

Debug-print a JSON object.

Definition at line 18 of file json-helpers.h.

◆ LOG_FMT_JSON_C

#define LOG_FMT_JSON_C (   fmt,
  ... 
)    "json-c: " fmt ": %s" __VA_OPT__(, ) __VA_ARGS__, json_util_get_last_err()

A format string and arguments for a json-c error.

Definition at line 22 of file json-helpers.h.

◆ LOG_FMT_JSON_TYPE

#define LOG_FMT_JSON_TYPE (   type,
  actual,
  fmt,
  ... 
)    "json: " fmt ": type: expected %s, got %s\n" __VA_OPT__(, ) __VA_ARGS__, json_type_to_name(type), json_type_to_name(actual)

A format string and arguments for a JSON type error.

Definition at line 25 of file json-helpers.h.

◆ min_json

#define min_json (   obj)    json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN)

Create a minified JSON string from a JSON object.

Definition at line 15 of file json-helpers.h.

Function Documentation

◆ json_object_get_int64_strict()

bool json_object_get_int64_strict ( json_object const *  obj,
int64_t *  out 
)

Get the 64-bit integer value of a JSON object.

Parameters
objThe JSON object to get the value of.
outAssigned to the integer value of the object. Pass NULL to only check the type.
Returns
true when obj is of the integer type.
false otherwise. out is untouched.
Remarks
Values are clamped between INT64_MIN and INT64_MAX.

◆ json_object_get_int_strict()

bool json_object_get_int_strict ( json_object const *  obj,
int32_t *  out 
)

Get the 32-bit integer value of a JSON object.

Parameters
objThe JSON object to get the value of.
outAssigned to the integer value of the object. Pass NULL to only check the type.
Returns
true when obj is of the integer type.
false otherwise. out is untouched.
Remarks
Values are clamped between INT32_MIN and INT32_MAX.

◆ json_object_get_string_strict()

bool json_object_get_string_strict ( json_object *  obj,
slice_t out 
)

Get the string value of a JSON object.

Parameters
objThe JSON object to get the value of.
outAssigned to the string value of the object. Pass NULL to only check the type. The returned slice is null-terminated, but the null terminator is not included in the length.
Returns
true when obj is of the string type.
false otherwise. out is untouched.

◆ json_object_get_uint16_strict()

bool json_object_get_uint16_strict ( json_object const *  obj,
uint16_t *  out 
)

Get the 16-bit unsigned integer value of a JSON object.

Parameters
objThe JSON object to get the value of.
outAssigned to the integer value of the object. Pass NULL to only check the type.
Returns
true when obj is of the integer type.
false otherwise. out is untouched.
Remarks
Values are clamped between 0 and UINT16_MAX.