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:
Hendiadyoin1 2024-03-24 20:32:59 +01:00 committed by Andrew Kaster
parent ffa9875fa6
commit e014296092
Notes: sideshowbarker 2024-07-17 03:25:24 +09:00

View file

@ -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 {