mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
wire: add bool routines.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
937a62100f
commit
f50af430e1
@ -14,7 +14,7 @@ class FieldType(object):
|
||||
self.tsize = FieldType._typesize(name)
|
||||
|
||||
def is_assignable(self):
|
||||
return self.name == 'u8' or self.name == 'u16' or self.name == 'u32' or self.name == 'u64'
|
||||
return self.name == 'u8' or self.name == 'u16' or self.name == 'u32' or self.name == 'u64' or self.name == 'bool'
|
||||
|
||||
# Returns typename and base size
|
||||
@staticmethod
|
||||
@ -39,6 +39,8 @@ class FieldType(object):
|
||||
return 2
|
||||
elif typename == 'u8':
|
||||
return 1
|
||||
elif typename == 'bool':
|
||||
return 1
|
||||
else:
|
||||
raise ValueError('Unknown typename {}'.format(typename))
|
||||
|
||||
|
@ -76,6 +76,17 @@ u64 fromwire_u64(const u8 **cursor, size_t *max)
|
||||
return be64_to_cpu(ret);
|
||||
}
|
||||
|
||||
bool fromwire_bool(const u8 **cursor, size_t *max)
|
||||
{
|
||||
u8 ret;
|
||||
|
||||
if (!fromwire(cursor, max, &ret, sizeof(ret)))
|
||||
return false;
|
||||
if (ret != 0 && ret != 1)
|
||||
fail_pull(cursor, max);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)
|
||||
{
|
||||
u8 der[PUBKEY_DER_LEN];
|
||||
|
@ -35,6 +35,12 @@ void towire_u64(u8 **pptr, u64 v)
|
||||
towire(pptr, &l, sizeof(l));
|
||||
}
|
||||
|
||||
void towire_bool(u8 **pptr, bool v)
|
||||
{
|
||||
u8 val = !!v;
|
||||
towire(pptr, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void towire_pubkey(u8 **pptr, const struct pubkey *pubkey)
|
||||
{
|
||||
u8 output[PUBKEY_DER_LEN];
|
||||
|
@ -32,6 +32,7 @@ void towire_u16(u8 **pptr, u16 v);
|
||||
void towire_u32(u8 **pptr, u32 v);
|
||||
void towire_u64(u8 **pptr, u64 v);
|
||||
void towire_pad(u8 **pptr, size_t num);
|
||||
void towire_bool(u8 **pptr, bool v);
|
||||
|
||||
void towire_u8_array(u8 **pptr, const u8 *arr, size_t num);
|
||||
void towire_signature_array(u8 **pptr, const struct signature *arr, size_t num);
|
||||
@ -42,6 +43,7 @@ u8 fromwire_u8(const u8 **cursor, size_t *max);
|
||||
u16 fromwire_u16(const u8 **cursor, size_t *max);
|
||||
u32 fromwire_u32(const u8 **cursor, size_t *max);
|
||||
u64 fromwire_u64(const u8 **cursor, size_t *max);
|
||||
bool fromwire_bool(const u8 **cursor, size_t *max);
|
||||
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey);
|
||||
void fromwire_signature(const u8 **cursor, size_t *max,
|
||||
struct signature *signature);
|
||||
|
Loading…
Reference in New Issue
Block a user