mirror of
https://github.com/dgibson/dtc.git
synced 2026-04-11 16:37:42 -04:00
pylibfdt: add Property.as_*int*_array()
Add new methods to handle decoding of int32, uint32, int64 and uint64 arrays. Also add tests for the new methods. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Message-Id: <20211225132558.167123-3-luca@z3ntu.xyz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
83102717d7
commit
a04f690250
3 changed files with 30 additions and 0 deletions
|
|
@ -716,6 +716,21 @@ class Property(bytearray):
|
|||
def as_int64(self):
|
||||
return self.as_cell('q')
|
||||
|
||||
def as_list(self, fmt):
|
||||
return list(map(lambda x: x[0], struct.iter_unpack('>' + fmt, self)))
|
||||
|
||||
def as_uint32_list(self):
|
||||
return self.as_list('L')
|
||||
|
||||
def as_int32_list(self):
|
||||
return self.as_list('l')
|
||||
|
||||
def as_uint64_list(self):
|
||||
return self.as_list('Q')
|
||||
|
||||
def as_int64_list(self):
|
||||
return self.as_list('q')
|
||||
|
||||
def as_str(self):
|
||||
"""Unicode is supported by decoding from UTF-8"""
|
||||
if self[-1] != 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue