LibDeviceTree: Make DeviceTreeProperty::as_stream return a ValueStream
This new Stream class adds an interface to work in cell-sized chunks, which is useful for parsing the data in a DeviceTreeProperty.
This commit is contained in:
parent
ffa9875fa6
commit
e014296092
Notes:
sideshowbarker
2024-07-17 03:25:24 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/e014296092 Pull-request: https://github.com/SerenityOS/serenity/pull/24141 Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 15 additions and 1 deletions
|
@ -19,6 +19,20 @@
|
|||
namespace DeviceTree {
|
||||
|
||||
struct DeviceTreeProperty {
|
||||
class ValueStream : public FixedMemoryStream {
|
||||
public:
|
||||
using AK::FixedMemoryStream::FixedMemoryStream;
|
||||
|
||||
ErrorOr<FlatPtr> read_cells(u32 cell_size)
|
||||
{
|
||||
// FIXME: There are rare cases of 3 cell size big values, even in addresses, especially in addresses
|
||||
VERIFY(cell_size <= 2);
|
||||
if (cell_size == 1)
|
||||
return read_value<BigEndian<u32>>();
|
||||
return read_value<BigEndian<u64>>();
|
||||
}
|
||||
};
|
||||
|
||||
ReadonlyBytes raw_data;
|
||||
|
||||
size_t size() const { return raw_data.size(); }
|
||||
|
@ -73,7 +87,7 @@ struct DeviceTreeProperty {
|
|||
return {};
|
||||
}
|
||||
|
||||
FixedMemoryStream as_stream() const { return FixedMemoryStream { raw_data }; }
|
||||
ValueStream as_stream() const { return ValueStream { raw_data }; }
|
||||
};
|
||||
|
||||
class DeviceTreeNodeView {
|
||||
|
|
Loading…
Add table
Reference in a new issue