static void check(const char *fmt, ...) { size_t len; char buf[200], *end, *p; va_list ap; len = 0; /* -Werror=maybe-uninitialized */ va_start(ap, fmt); testutil_check(__wt_struct_sizev(NULL, &len, fmt, ap)); va_end(ap); if (len < 1 || len >= sizeof(buf)) testutil_die(EINVAL, "Unexpected length from __wt_struct_sizev"); va_start(ap, fmt); testutil_check(__wt_struct_packv(NULL, buf, sizeof(buf), fmt, ap)); va_end(ap); printf("%s ", fmt); for (p = buf, end = p + len; p < end; p++) printf("%02x", (u_char)*p & 0xff); printf("\n"); }
/*内部使用的struct pack函数封装*/ int __wt_struct_pack(WT_SESSION_IMPL *session, void *buffer, size_t size, const char *fmt, ...) { WT_DECL_RET; va_list ap; va_start(ap, fmt); ret = __wt_struct_packv(session, buffer, size, fmt, ap); va_end(ap); return (ret); }
/* * wiredtiger_struct_pack -- * Pack a byte string (extension API). */ int wiredtiger_struct_pack(WT_SESSION *wt_session, void *buffer, size_t len, const char *format, ...) { WT_DECL_RET; WT_SESSION_IMPL *session; va_list ap; session = (WT_SESSION_IMPL *)wt_session; va_start(ap, format); ret = __wt_struct_packv(session, buffer, len, format, ap); va_end(ap); return (ret); }
/* * __wt_ext_struct_pack -- * Pack a byte string (extension API). */ int __wt_ext_struct_pack(WT_EXTENSION_API *wt_api, WT_SESSION *wt_session, void *buffer, size_t len, const char *fmt, ...) { WT_DECL_RET; WT_SESSION_IMPL *session; va_list ap; session = (wt_session != NULL) ? (WT_SESSION_IMPL *)wt_session : ((WT_CONNECTION_IMPL *)wt_api->conn)->default_session; va_start(ap, fmt); ret = __wt_struct_packv(session, buffer, len, fmt, ap); va_end(ap); return (ret); }
int __wt_log_put(WT_SESSION_IMPL *session, WT_LOGREC_DESC *recdesc, ...) { WT_DECL_RET; WT_ITEM *buf; va_list ap; size_t size; buf = &session->logrec_buf; va_start(ap, recdesc); ret = __log_record_size(session, &size, recdesc, ap); va_end(ap); WT_RET(ret); WT_RET(__wt_buf_initsize(session, buf, size)); va_start(ap, recdesc); ret = __wt_struct_packv(session, buf->mem, size, recdesc->fmt, ap); va_end(ap); return (ret); }
static void check(const char *fmt, ...) { char buf[200], *end, *p; va_list ap; size_t len; len = 0; /* -Werror=maybe-uninitialized */ va_start(ap, fmt); assert(__wt_struct_sizev(NULL, &len, fmt, ap) == 0); va_end(ap); assert(len > 0 && len < sizeof(buf)); va_start(ap, fmt); assert(__wt_struct_packv(NULL, buf, sizeof(buf), fmt, ap) == 0); va_end(ap); printf("%s ", fmt); for (p = buf, end = p + len; p < end; p++) printf("%02x", *p & 0xff); printf("\n"); }