wire: add explicit-length fromwire_peektype variant.
Useful for continuous streams. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -41,10 +41,9 @@ const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n)
|
||||
return memcheck(p, n);
|
||||
}
|
||||
|
||||
int fromwire_peektype(const u8 *cursor)
|
||||
int fromwire_peektypen(const u8 *cursor, size_t max)
|
||||
{
|
||||
be16 be_type;
|
||||
size_t max = tal_count(cursor);
|
||||
|
||||
fromwire(&cursor, &max, &be_type, sizeof(be_type));
|
||||
if (!cursor)
|
||||
@@ -52,6 +51,11 @@ int fromwire_peektype(const u8 *cursor)
|
||||
return be16_to_cpu(be_type);
|
||||
}
|
||||
|
||||
int fromwire_peektype(const u8 *cursor)
|
||||
{
|
||||
return fromwire_peektypen(cursor, tal_count(cursor));
|
||||
}
|
||||
|
||||
u8 fromwire_u8(const u8 **cursor, size_t *max)
|
||||
{
|
||||
u8 ret;
|
||||
|
||||
@@ -15,6 +15,8 @@ typedef char utf8;
|
||||
|
||||
/* Read the type; returns -1 if not long enough. cursor is a tal ptr. */
|
||||
int fromwire_peektype(const u8 *cursor);
|
||||
/* Same, but doesn't need to be a tal ptr */
|
||||
int fromwire_peektypen(const u8 *cursor, size_t len);
|
||||
void *fromwire_fail(const u8 **cursor, size_t *max);
|
||||
|
||||
void towire(u8 **pptr, const void *data, size_t len);
|
||||
|
||||
Reference in New Issue
Block a user