Skip to content

Commit

Permalink
feat(msgpack): ability to specify NOSCHEMA for cbinds (AztecProtocol/…
Browse files Browse the repository at this point in the history
  • Loading branch information
ludamad authored Jul 12, 2023
1 parent 7812e6b commit 9b3d5b2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions circuits/cpp/barretenberg/cpp/src/barretenberg/serialize/cbind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,23 @@ inline void msgpack_cbind_schema_impl(auto func, uint8_t** output_out, size_t* o
*output_len_out = schema.size();
}

// The CBIND_NOSCHEMA macro generates a function named 'cname' that decodes the input arguments from msgpack format,
// calls the target function, and then encodes the return value back into msgpack format. It should be used over CBIND
// in cases where we do not want schema generation, such as meta-functions that themselves give information to control
// how the schema is interpreted.
#define CBIND_NOSCHEMA(cname, func) \
WASM_EXPORT void cname(const uint8_t* input_in, size_t input_len_in, uint8_t** output_out, size_t* output_len_out) \
{ \
msgpack_cbind_impl(func, input_in, input_len_in, output_out, output_len_out); \
}

// The CBIND macro is a convenient utility that abstracts away several steps in binding C functions with msgpack
// serialization. It creates two separate functions:
// 1. cname function: This decodes the input arguments from msgpack format, calls the target function,
// and then encodes the return value back into msgpack format.
// 2. cname##__schema function: This creates a JSON schema of the function's input arguments and return type.
#define CBIND(cname, func) \
WASM_EXPORT void cname(const uint8_t* input_in, size_t input_len_in, uint8_t** output_out, size_t* output_len_out) \
{ \
msgpack_cbind_impl(func, input_in, input_len_in, output_out, output_len_out); \
} \
CBIND_NOSCHEMA(cname, func) \
WASM_EXPORT void cname##__schema(uint8_t** output_out, size_t* output_len_out) \
{ \
msgpack_cbind_schema_impl(func, output_out, output_len_out); \
Expand Down

0 comments on commit 9b3d5b2

Please sign in to comment.