vg
tools for working with variation graphs
Classes | Macros | Functions
json2pb.cpp File Reference
#include <errno.h>
#include <jansson.h>
#include <google/protobuf/message.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/struct.pb.h>
#include "vg/io/json2pb.h"
#include <stdexcept>
#include <cstdio>
#include "bin2ascii.h"

Classes

struct  json_autoptr
 
class  j2pb_error
 

Macros

#define json_boolean(val)   ((val) ? json_true() : json_false())
 
#define _CONVERT(type, ctype, fmt, sfunc, afunc)
 
#define _CONVERT_AS_STRING(type, ctype, sfunc, afunc)
 
#define _SET_OR_ADD(sfunc, afunc, value)
 
#define _CONVERT_WITH_STRING(type, ctype, fmt, fromstringfunc, sfunc, afunc)
 

Functions

void json2pb (Message &msg, const char *buf, size_t size)
 
void json2pb (Message &msg, FILE *fp)
 
void json2pb (Message &msg, const std::string &data)
 
std::string pb2json (const Message &msg)
 

Macro Definition Documentation

◆ _CONVERT

#define _CONVERT (   type,
  ctype,
  fmt,
  sfunc,
  afunc 
)
Value:
case FieldDescriptor::type: { \
const ctype value = (repeated)? \
ref->afunc(msg, field, index): \
ref->sfunc(msg, field); \
jf = fmt(value); \
break; \
}

◆ _CONVERT_AS_STRING

#define _CONVERT_AS_STRING (   type,
  ctype,
  sfunc,
  afunc 
)
Value:
case FieldDescriptor::type: { \
const ctype value = (repeated)? \
ref->afunc(msg, field, index): \
ref->sfunc(msg, field); \
std::string quoted = std::to_string(value); \
jf = json_string(quoted.c_str()); \
break; \
}

◆ _CONVERT_WITH_STRING

#define _CONVERT_WITH_STRING (   type,
  ctype,
  fmt,
  fromstringfunc,
  sfunc,
  afunc 
)
Value:
case FieldDescriptor::type: { \
ctype value; \
int r = json_unpack_ex(jf, &error, JSON_STRICT, fmt, &value); \
if (r) { \
if (!json_is_string(jf)) throw j2pb_error(field, std::string("Failed to unpack or view as string: ") + error.text); \
const char * string_value = json_string_value(jf); \
value = fromstringfunc(string_value); \
} \
_SET_OR_ADD(sfunc, afunc, value); \
break; \
}

◆ _SET_OR_ADD

#define _SET_OR_ADD (   sfunc,
  afunc,
  value 
)
Value:
do { \
if (repeated) \
ref->afunc(&msg, field, value); \
else \
ref->sfunc(&msg, field, value); \
} while (0)

◆ json_boolean

#define json_boolean (   val)    ((val) ? json_true() : json_false())

Function Documentation

◆ json2pb() [1/3]

void json2pb ( Message &  msg,
const char *  buf,
size_t  size 
)

◆ json2pb() [2/3]

void json2pb ( Message &  msg,
const std::string &  data 
)

◆ json2pb() [3/3]

void json2pb ( Message &  msg,
FILE *  fp 
)

◆ pb2json()

std::string pb2json ( const Message &  msg)
std::to_string
std::string to_string(const vg::WFAAlignment::Edit &edit)
Convert a WFAAlignment Edit operation to a string.
Definition: gbwt_extender.cpp:1191
j2pb_error
Definition: json2pb.cpp:48