Rizin
unix-like reverse engineering framework and cli tools
rz_serialize.h File Reference
#include <rz_util/rz_json.h>
#include <rz_list.h>

Go to the source code of this file.

Macros

#define RZ_SERIALIZE_ERR(res, ...)
 Push an error to the local RzSerializeResultInfo \res RzSerializeInfoResult *. More...
 
#define RZ_KEY_PARSER_UNKNOWN   -1
 
#define RZ_KEY_PARSER_SWITCH(parser, key)
 switch-like macro over RzKeyParser values More...
 
#define RZ_KEY_PARSER_JSON(parser, json, child, body)
 Iterate over all keys in a json object and call RZ_KEY_PARSER_SWITCH on each. More...
 
#define RZ_SERIALIZE_SUB(db, subdb, res, ns, rip)
 Get an sdb sub-namespace or fail. More...
 
#define RZ_SERIALIZE_SUB_DO(db, subdb, res, ns, call, rip)
 Get an sdb sub-namespace and evaluate call or fail. More...
 

Typedefs

typedef RzList RzSerializeResultInfo
 Detailed info about a (de)serialization result. More...
 
typedef HtPP RzKeyParser
 Hashtable-based key parser to prevent strcmp chains. More...
 

Functions

static RzSerializeResultInforz_serialize_result_info_new (void)
 
static void rz_serialize_result_info_free (RzSerializeResultInfo *info)
 
static RzKeyParserrz_key_parser_new (void)
 
static void rz_key_parser_free (RzKeyParser *parser)
 
static void rz_key_parser_add (RzKeyParser *parser, const char *key, int val)
 

Macro Definition Documentation

◆ RZ_KEY_PARSER_JSON

#define RZ_KEY_PARSER_JSON (   parser,
  json,
  child,
  body 
)
Value:
if (json->type == RZ_JSON_OBJECT) { \
for (RzJson *child = json->children.first; child; child = child->next) { \
RZ_KEY_PARSER_SWITCH(parser, child->key) { body } \
} \
}
@ RZ_JSON_OBJECT
Definition: rz_json.h:30
struct rz_json_t::@304::@307 children

Iterate over all keys in a json object and call RZ_KEY_PARSER_SWITCH on each.

Parameters
parserRzKeyParser *
jsonRzJson *
childvar name for the RzJson *child
bodycode block with cases

Definition at line 82 of file rz_serialize.h.

◆ RZ_KEY_PARSER_SWITCH

#define RZ_KEY_PARSER_SWITCH (   parser,
  key 
)
Value:
bool key_parser_found = false; \
int key_parser_v = (int)(size_t)ht_pp_find(parser, key, &key_parser_found); \
if (!key_parser_found) { \
key_parser_v = RZ_KEY_PARSER_UNKNOWN; \
} \
switch (key_parser_v)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
#define RZ_KEY_PARSER_UNKNOWN
Definition: rz_serialize.h:60
static int
Definition: sfsocketcall.h:114

switch-like macro over RzKeyParser values

Parameters
parserRzKeyParser *
keyconst char *

Definition at line 67 of file rz_serialize.h.

◆ RZ_KEY_PARSER_UNKNOWN

#define RZ_KEY_PARSER_UNKNOWN   -1

Definition at line 60 of file rz_serialize.h.

◆ RZ_SERIALIZE_ERR

#define RZ_SERIALIZE_ERR (   res,
  ... 
)
Value:
do { \
if (res) { \
rz_list_push(res, rz_str_newf(__VA_ARGS__)); \
} \
} while (0)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1

Push an error to the local RzSerializeResultInfo \res RzSerializeInfoResult *.

Parameters
...printf-style arguments to be pushed as the error to res

Definition at line 33 of file rz_serialize.h.

◆ RZ_SERIALIZE_SUB

#define RZ_SERIALIZE_SUB (   db,
  subdb,
  res,
  ns,
  rip 
)
Value:
do { \
subdb = sdb_ns(db, ns, false); \
if (!subdb) { \
RZ_SERIALIZE_ERR(res, "missing " ns " namespace"); \
rip \
} \
} while (0)
RZ_API Sdb * sdb_ns(Sdb *s, const char *name, int create)
Definition: ns.c:186

Get an sdb sub-namespace or fail.

Parameters
dbSdb * the Sdb from which to take the sub-namespace
subdbSdb * where to put the sub-namespace
resRzSerializeResult * where to push an error on failure
nsconst char *
ripcode to execute if the function failed

Example:

Sdb *subdb;
RZ_SERIALIZE_SUB(db, subdb, res, "files", return false;)
// do something with subdb

Definition at line 104 of file rz_serialize.h.

◆ RZ_SERIALIZE_SUB_DO

#define RZ_SERIALIZE_SUB_DO (   db,
  subdb,
  res,
  ns,
  call,
  rip 
)
Value:
RZ_SERIALIZE_SUB(db, subdb, res, ns, rip); \
if (!(call)) { \
rip \
}
int call(int a, int b)
Definition: bcj_test.c:25
void rip(char *fname, off_t offset, unsigned int length)
Definition: cabrip.c:18
#define RZ_SERIALIZE_SUB(db, subdb, res, ns, rip)
Get an sdb sub-namespace or fail.
Definition: rz_serialize.h:104

Get an sdb sub-namespace and evaluate call or fail.

Parameters
dbSdb * the Sdb from which to take the sub-namespace
subdbSdb * where to put the sub-namespace
resRzSerializeResult * where to push an error on failure
nsconst char *
callfunction call
ripcode to execute if the function failed

Example:

Sdb *subdb;
RZ_SERIALIZE_SUB_DO(db, subdb, res, "files",
    rz_serialize_io_files_load(subdb, io, res), return false;)

Definition at line 129 of file rz_serialize.h.

Typedef Documentation

◆ RzKeyParser

typedef HtPP RzKeyParser

Hashtable-based key parser to prevent strcmp chains.

This enables string values to be used in a switch/case-like fashion.

Definition at line 46 of file rz_serialize.h.

◆ RzSerializeResultInfo

Detailed info about a (de)serialization result.

This is currently just a list of strings which may be warnings or detailed error messages.

Definition at line 16 of file rz_serialize.h.

Function Documentation

◆ rz_key_parser_add()

◆ rz_key_parser_free()

◆ rz_key_parser_new()

◆ rz_serialize_result_info_free()

static void rz_serialize_result_info_free ( RzSerializeResultInfo info)
inlinestatic

Definition at line 22 of file rz_serialize.h.

22  {
24 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137

References info(), and rz_list_free().

Referenced by rz_core_project_load_for_cli().

◆ rz_serialize_result_info_new()

static RzSerializeResultInfo* rz_serialize_result_info_new ( void  )
inlinestatic

Definition at line 18 of file rz_serialize.h.

18  {
19  return rz_list_newf(free);
20 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248

References free(), and rz_list_newf().

Referenced by rz_core_project_load_for_cli().