qtty-cpp 0.4.5
Header-only C++ wrapper for qtty
Loading...
Searching...
No Matches
serialization.hpp File Reference

JSON serialization helpers for qtty quantities. More...

#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include "qtty_ffi.h"
#include "ffi_core.hpp"
Include dependency graph for serialization.hpp:

Go to the source code of this file.

Namespaces

namespace  qtty
namespace  qtty::serialization
namespace  qtty::derived_serialization

Functions

int32_t qtty_quantity_to_json_value (qtty_quantity_t src, char **out_json)
int32_t qtty_quantity_from_json_value (UnitId unit, const char *json, qtty_quantity_t *out)
int32_t qtty_quantity_to_json (qtty_quantity_t src, char **out_json)
int32_t qtty_quantity_from_json (const char *json, qtty_quantity_t *out)
int32_t qtty_derived_to_json (qtty_derived_quantity_t src, char **out)
int32_t qtty_derived_from_json (const char *json, qtty_derived_quantity_t *out)
void qtty_string_free (char *s)
std::string qtty::serialization::from_owned_c (char *ptr)
 Convert an owned C string from FFI into std::string and free it.
template<typename UnitTag>
std::string qtty::serialization::to_json_value (const Quantity< UnitTag > &q)
 Serialize only the numeric value as JSON for a typed quantity.
template<typename T>
Quantity< typename ExtractTag< T >::type > qtty::serialization::from_json_value (std::string_view json)
 Deserialize a JSON numeric value into a typed quantity.
template<typename UnitTag>
std::string qtty::serialization::to_json (const Quantity< UnitTag > &q)
 Serialize a typed quantity as JSON object with value and unit id.
UnitId qtty::serialization::unit_id_from_u32 (uint32_t raw)
template<typename T>
Quantity< typename ExtractTag< T >::type > qtty::serialization::from_json (std::string_view json)
 Deserialize a JSON quantity object into a requested target type.
template<typename Tag>
std::string qtty::derived_serialization::to_json (const Quantity< Tag > &q)
 Serialize a compound quantity as JSON.
template<typename T>
Quantity< typename ExtractTag< T >::type > qtty::derived_serialization::from_json (std::string_view json)
 Deserialize a JSON string into a compound quantity.

Detailed Description

JSON serialization helpers for qtty quantities.

Definition in file serialization.hpp.

Function Documentation

◆ qtty_derived_from_json()

int32_t qtty_derived_from_json ( const char * json,
qtty_derived_quantity_t * out )

◆ qtty_derived_to_json()

int32_t qtty_derived_to_json ( qtty_derived_quantity_t src,
char ** out )

◆ qtty_quantity_from_json()

int32_t qtty_quantity_from_json ( const char * json,
qtty_quantity_t * out )

◆ qtty_quantity_from_json_value()

int32_t qtty_quantity_from_json_value ( UnitId unit,
const char * json,
qtty_quantity_t * out )

◆ qtty_quantity_to_json()

int32_t qtty_quantity_to_json ( qtty_quantity_t src,
char ** out_json )

◆ qtty_quantity_to_json_value()

int32_t qtty_quantity_to_json_value ( qtty_quantity_t src,
char ** out_json )

◆ qtty_string_free()

void qtty_string_free ( char * s)