mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-12 19:54:34 +00:00
Add bool to simple serialize
This commit is contained in:
parent
1684a3ffd3
commit
1c25917622
@ -81,6 +81,20 @@ buffer_size = int_size / 8
|
||||
return value.to_bytes(buffer_size, 'big')
|
||||
```
|
||||
|
||||
#### bool
|
||||
|
||||
Convert directly to a single 0x00 or 0x01 byte.
|
||||
|
||||
| Check to perform | Code |
|
||||
|:------------------|:---------------------------|
|
||||
| Value is boolean | ``value in (True, False)`` |
|
||||
|
||||
```python
|
||||
assert(value in (True, False))
|
||||
return b'\x01' if value is True else b'\x00'
|
||||
```
|
||||
|
||||
|
||||
#### Address
|
||||
|
||||
The address should already come as a hash/byte format. Ensure that length is
|
||||
@ -237,6 +251,15 @@ new_index = current_index + int_size
|
||||
return int.from_bytes(rawbytes[current_index:current_index+int_size], 'big'), new_index
|
||||
```
|
||||
|
||||
#### Bool
|
||||
|
||||
Return True if 0x01, False if 0x00.
|
||||
|
||||
```python
|
||||
assert rawbytes in (b'\x00', b'\x01')
|
||||
return True if rawbytes == b'\x01' else False
|
||||
```
|
||||
|
||||
#### Address
|
||||
|
||||
Return the 20 bytes.
|
||||
|
Loading…
x
Reference in New Issue
Block a user