2019-07-24 01:54:21 +02:00
|
|
|
/* This file was generated by generate-wire.py */
|
2020-08-25 04:19:58 +02:00
|
|
|
/* Do not modify this file! Modify the .csv file it was generated from. */
|
2019-07-15 02:10:01 +02:00
|
|
|
|
2021-09-16 06:50:02 +02:00
|
|
|
#include <${header_filename}>
|
2019-07-21 05:04:59 +02:00
|
|
|
#include <ccan/array_size/array_size.h>
|
2019-07-15 02:10:01 +02:00
|
|
|
#include <ccan/mem/mem.h>
|
|
|
|
#include <ccan/tal/str/str.h>
|
|
|
|
#include <common/utils.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
2022-03-23 00:31:14 +01:00
|
|
|
% for i in includes:
|
|
|
|
${i}
|
|
|
|
% endfor
|
2019-07-15 02:10:01 +02:00
|
|
|
|
2021-09-09 04:40:01 +02:00
|
|
|
% if enum_sets:
|
2022-03-23 00:31:14 +01:00
|
|
|
bool print${options.enum_name}_message(const u8 *msg)
|
2019-07-15 02:10:01 +02:00
|
|
|
{
|
|
|
|
switch ((enum ${options.enum_name})fromwire_peektype(msg)) {
|
|
|
|
% for msg in enum_sets[0]['set']:
|
|
|
|
case ${msg.enum_name()}:
|
|
|
|
printf("${msg.enum_name()}:\n");
|
2022-03-23 00:31:14 +01:00
|
|
|
return printwire_${msg.name}("${msg.name}", msg);
|
2019-07-15 02:10:01 +02:00
|
|
|
% endfor
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("UNKNOWN: %s\\n", tal_hex(msg, msg));
|
2022-03-23 00:31:14 +01:00
|
|
|
return false;
|
2019-07-15 02:10:01 +02:00
|
|
|
}
|
2021-09-09 04:40:01 +02:00
|
|
|
% endif
|
2019-07-15 02:10:01 +02:00
|
|
|
|
|
|
|
## 'component' for 'truncate check
|
2022-03-23 00:31:14 +01:00
|
|
|
<%def name="truncate_check()">
|
|
|
|
if (!*cursor) {
|
2019-07-15 02:10:01 +02:00
|
|
|
printf("**TRUNCATED**\n");
|
2022-03-23 00:31:14 +01:00
|
|
|
return false;
|
2019-07-15 02:10:01 +02:00
|
|
|
}
|
|
|
|
</%def> \
|
|
|
|
## definition for printing field sets
|
2022-03-23 00:31:14 +01:00
|
|
|
<%def name="print_fieldset(fields)">
|
2019-07-15 02:10:01 +02:00
|
|
|
% for f in fields:
|
2019-07-23 23:36:55 +02:00
|
|
|
% if f.is_extension():
|
2022-03-23 00:31:14 +01:00
|
|
|
if (*plen == 0)
|
|
|
|
return true;
|
2019-07-23 23:36:55 +02:00
|
|
|
printf("(${','.join(f.extension_names)}):");
|
|
|
|
% endif
|
2019-07-15 02:10:01 +02:00
|
|
|
% if f.len_field_of:
|
2022-03-23 00:31:14 +01:00
|
|
|
${f.type_obj.type_name()} ${f.name} = fromwire_${f.type_obj.name}(cursor, plen);${truncate_check()} <% continue %> \
|
2019-07-15 02:10:01 +02:00
|
|
|
% endif
|
|
|
|
printf("${f.name}=");
|
2019-07-21 05:04:59 +02:00
|
|
|
% if f.type_obj.is_tlv():
|
2022-03-23 00:31:14 +01:00
|
|
|
printwire_tlvs(tal_fmt(NULL, "%s.${f.name}", fieldname), cursor, plen, print_tlvs_${f.type_obj.tlv.name}, ARRAY_SIZE(print_tlvs_${f.type_obj.tlv.name}));
|
2019-07-21 05:04:59 +02:00
|
|
|
% elif f.is_array() or f.is_varlen():
|
2019-07-15 02:10:01 +02:00
|
|
|
% if f.type_obj.has_array_helper():
|
2022-03-23 00:31:14 +01:00
|
|
|
printwire_${f.type_obj.name}_array(tal_fmt(NULL, "%s.${f.name}", fieldname), cursor, plen, ${f.size('*plen')});
|
2019-07-15 02:10:01 +02:00
|
|
|
% else:
|
|
|
|
printf("[");
|
2019-07-28 02:52:43 +02:00
|
|
|
% if f.is_implicit_len():
|
2022-03-23 00:31:14 +01:00
|
|
|
while (*plen) {
|
2019-07-28 02:52:43 +02:00
|
|
|
% else:
|
2019-07-15 02:10:01 +02:00
|
|
|
for (size_t i = 0; i < ${f.size()}; i++) {
|
2019-07-28 02:52:43 +02:00
|
|
|
% endif
|
2022-03-23 00:31:14 +01:00
|
|
|
if (!printwire_${f.type_obj.name}(tal_fmt(NULL, "%s.${f.name}", fieldname), cursor, plen))
|
|
|
|
return false;
|
2019-07-15 02:10:01 +02:00
|
|
|
}
|
|
|
|
printf("]");
|
|
|
|
% endif
|
|
|
|
% else:
|
2022-03-23 00:31:14 +01:00
|
|
|
if (!printwire_${f.type_obj.name}(tal_fmt(NULL, "%s.${f.name}", fieldname), cursor, plen))
|
|
|
|
return false;
|
2019-07-15 02:10:01 +02:00
|
|
|
% endif
|
|
|
|
% endfor
|
|
|
|
</%def> \
|
|
|
|
## Definitions for 'subtypes'
|
|
|
|
% for subtype in subtypes:
|
2019-07-21 05:04:59 +02:00
|
|
|
|
2019-07-27 12:19:25 +02:00
|
|
|
<%
|
|
|
|
static = '' if options.expose_subtypes else 'static '
|
|
|
|
%>\
|
2022-03-23 00:31:14 +01:00
|
|
|
${static}bool printwire_${subtype.name}(const char *fieldname, const u8 **cursor, size_t *plen)
|
2019-07-15 02:10:01 +02:00
|
|
|
{
|
2022-03-23 00:31:14 +01:00
|
|
|
${print_fieldset(subtype.fields.values())}
|
|
|
|
return true;
|
2019-07-15 02:10:01 +02:00
|
|
|
}
|
|
|
|
% endfor
|
2019-07-21 05:04:59 +02:00
|
|
|
% for tlv in tlvs.values():
|
2019-07-15 02:10:01 +02:00
|
|
|
|
2019-07-21 05:04:59 +02:00
|
|
|
% for msg in tlv.messages.values():
|
2022-03-23 00:31:14 +01:00
|
|
|
static bool printwire_${msg.struct_name()}(const char *fieldname, const u8 **cursor, size_t *plen)
|
2019-07-21 05:04:59 +02:00
|
|
|
{
|
|
|
|
printf("(msg_name=%s)\n", "${msg.name}");
|
2022-03-23 00:31:14 +01:00
|
|
|
${print_fieldset(msg.fields.values())}
|
|
|
|
return true;
|
2019-07-21 05:04:59 +02:00
|
|
|
}
|
|
|
|
% endfor
|
|
|
|
|
|
|
|
static const struct tlv_print_record_type print_tlvs_${tlv.name}[] = {
|
|
|
|
% for msg in tlv.messages.values():
|
|
|
|
{ ${msg.number}, printwire_${msg.struct_name()} },
|
|
|
|
% endfor
|
|
|
|
};
|
|
|
|
% endfor
|
2019-07-15 02:10:01 +02:00
|
|
|
% for msg in messages:
|
2022-03-23 00:31:14 +01:00
|
|
|
bool printwire_${msg.name}(const char *fieldname, const u8 *msg)
|
2019-07-15 02:10:01 +02:00
|
|
|
{
|
2022-03-23 00:31:14 +01:00
|
|
|
size_t msglen = tal_count(msg);
|
|
|
|
const u8 **cursor = &msg;
|
|
|
|
size_t *plen = &msglen;
|
2019-07-15 02:10:01 +02:00
|
|
|
|
2022-03-23 00:31:14 +01:00
|
|
|
if (fromwire_u16(cursor, plen) != ${msg.enum_name()}) {
|
2019-07-15 02:10:01 +02:00
|
|
|
printf("WRONG TYPE?!\n");
|
2022-03-23 00:31:14 +01:00
|
|
|
return false;
|
2019-07-15 02:10:01 +02:00
|
|
|
}
|
2022-03-23 00:31:14 +01:00
|
|
|
${print_fieldset(msg.fields.values())}
|
2019-07-15 02:10:01 +02:00
|
|
|
|
|
|
|
## Length check
|
2022-03-23 00:31:14 +01:00
|
|
|
if (*plen != 0)
|
|
|
|
printf("EXTRA: %s\n", tal_hexstr(NULL, *cursor, *plen));
|
|
|
|
return *cursor != NULL;
|
2019-07-15 02:10:01 +02:00
|
|
|
}
|
|
|
|
% endfor
|
2019-07-21 05:04:59 +02:00
|
|
|
|
|
|
|
% if bool(tlvs):
|
2022-03-23 00:31:14 +01:00
|
|
|
bool print${options.enum_name}_tlv_message(const char *tlv_name, const u8 *msg) {
|
|
|
|
size_t len = tal_count(msg);
|
2022-03-23 00:31:14 +01:00
|
|
|
% for tlv in tlvs.values():
|
|
|
|
if (strcmp(tlv_name, "${tlv.name}") == 0) {
|
2022-03-23 00:31:14 +01:00
|
|
|
return printwire_tlvs(tlv_name, &msg, &len, print_tlvs_${tlv.name}, ARRAY_SIZE(print_tlvs_${tlv.name}));
|
2019-07-21 05:04:59 +02:00
|
|
|
}
|
|
|
|
% endfor
|
2022-03-23 00:31:14 +01:00
|
|
|
return false;
|
2019-07-21 05:04:59 +02:00
|
|
|
}
|
2021-09-09 04:40:01 +02:00
|
|
|
% endif
|