diff options
author | Luca Weiss <luca@z3ntu.xyz> | 2021-12-25 14:25:56 +0100 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2021-12-28 15:30:33 +1100 |
commit | a04f69025003890be265e007238dc91041e5529b (patch) | |
tree | a430fdffa0454b20b05f3a6cf550c4ea963e94c1 /pylibfdt/libfdt.i | |
parent | 83102717d7c4171aeb2d26941fa1ee2997bf4a7d (diff) | |
download | dtc-a04f69025003890be265e007238dc91041e5529b.zip dtc-a04f69025003890be265e007238dc91041e5529b.tar.gz dtc-a04f69025003890be265e007238dc91041e5529b.tar.bz2 |
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>
Diffstat (limited to 'pylibfdt/libfdt.i')
-rw-r--r-- | pylibfdt/libfdt.i | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i index c81b504..ac70762 100644 --- a/pylibfdt/libfdt.i +++ b/pylibfdt/libfdt.i @@ -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: |