/*----------------------------------------------------------------------------*/
/* This file is generated by the templates/template.rb script and should not  */
/* be modified manually.                                                      */
/* To change the template see                                                 */
/* templates/include/rbs/serialize.h.erb                                      */
/*----------------------------------------------------------------------------*/

#ifndef RBS__SERIALIZE_H
#define RBS__SERIALIZE_H

#include "rbs/ast.h"
#include "rbs/string.h"
#include "rbs/util/rbs_allocator.h"
#include "rbs/util/rbs_constant_pool.h"

/**
 * Serialize a parsed AST node into a compact, portable binary buffer.
 *
 * The format is consumed by RBS::WASM::Deserializer on the Ruby side, which
 * rebuilds the same `RBS::AST` objects that the C extension would have built
 * directly. This is what lets RBS run on Ruby implementations that cannot load
 * the C extension (notably JRuby): the parser runs inside WebAssembly, produces
 * this buffer, and the host reconstructs the tree in pure Ruby.
 *
 * The buffer is allocated from `allocator`, so its lifetime is tied to that
 * allocator. `constant_pool` must be the pool the node was parsed with; it is
 * used to resolve interned symbol/identifier ids back into their bytes.
 *
 * See `docs/wasm_serialization.md` for the wire format.
 */
rbs_string_t rbs_serialize_node(rbs_allocator_t *allocator, rbs_constant_pool_t *constant_pool, rbs_node_t *node);

/**
 * Like rbs_serialize_node, but for a bare node list (e.g. the result of
 * rbs_parse_type_params). Decoded by RBS::WASM::Deserializer.deserialize_node_list.
 */
rbs_string_t rbs_serialize_node_list(rbs_allocator_t *allocator, rbs_constant_pool_t *constant_pool, rbs_node_list_t *list);

#endif
