tools/generate-wire.py: simplify printwire routines, fix ... handling.

We make them return bool, and always use names `cursor` and `plen` in
callers, for simplicity.

Also, `...` means "loop until finished" not "loop this many bytes".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-03-23 10:01:14 +10:30
parent 12c7b156c5
commit 88de64a580
5 changed files with 53 additions and 48 deletions

View File

@@ -180,7 +180,7 @@ find_print_record_type(u64 type,
return NULL;
}
void printwire_tlvs(const char *fieldname, const u8 **cursor, size_t *plen,
bool printwire_tlvs(const char *fieldname, const u8 **cursor, size_t *plen,
const struct tlv_print_record_type types[],
size_t num_types)
{
@@ -212,10 +212,11 @@ void printwire_tlvs(const char *fieldname, const u8 **cursor, size_t *plen,
printf("**TYPE #%"PRIu64" UNKNOWN for TLV %s**\n", type, fieldname);
*plen -= length;
}
return;
return true;
fail:
printf("**TRUNCATED TLV %s**\n", fieldname);
return false;
}
#define PRINTWIRE_TYPE_TO_STRING(T, N) \

View File

@@ -9,7 +9,7 @@
struct tlv_print_record_type {
u64 type;
void (*print)(const char *tlv_name, const u8 **cursor, size_t *plen);
bool (*print)(const char *tlv_name, const u8 **cursor, size_t *plen);
};
typedef u64 bigsize;
@@ -21,7 +21,7 @@ void printwire_u16(const char *fieldname, const u16 *v);
void printwire_u32(const char *fieldname, const u32 *v);
void printwire_u64(const char *fieldname, const u64 *v);
void printwire_u8_array(const char *fieldname, const u8 **cursor, size_t *plen, size_t len);
void printwire_tlvs(const char *tlv_name, const u8 **cursor, size_t *plen,
bool printwire_tlvs(const char *tlv_name, const u8 **cursor, size_t *plen,
const struct tlv_print_record_type types[], size_t num_types);
void printwire_bitcoin_blkid(const char *fieldname, const struct bitcoin_blkid *bitcoin_blkid);