mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:57:44 +00:00
LibIPC+LibC: Add and use a helper to encode/decoder container sizes
While refactoring the IPC encoders and decoders for fallibility, the inconsistency in which we transfer container sizes was a frequent thing to trip over. We currently transfer sizes as any of i32, u32, and u64. This adds a helper to transfer sizes in one consistent way. Two special cases here are DeprecatedString and Vector, whose encoding is depended upon by netdb, so that is also updated here.
This commit is contained in:
parent
40165f5846
commit
7c6b5ed161
5 changed files with 48 additions and 35 deletions
|
@ -57,6 +57,8 @@ public:
|
|||
return m_buffer.fds.try_append(move(auto_fd));
|
||||
}
|
||||
|
||||
ErrorOr<void> encode_size(size_t size);
|
||||
|
||||
private:
|
||||
void encode_u32(u32);
|
||||
void encode_u64(u64);
|
||||
|
@ -134,7 +136,8 @@ ErrorOr<void> encode(Encoder&, Empty const&);
|
|||
template<Concepts::Vector T>
|
||||
ErrorOr<void> encode(Encoder& encoder, T const& vector)
|
||||
{
|
||||
TRY(encoder.encode(static_cast<u64>(vector.size())));
|
||||
// NOTE: Do not change this encoding without also updating LibC/netdb.cpp.
|
||||
TRY(encoder.encode_size(vector.size()));
|
||||
|
||||
for (auto const& value : vector)
|
||||
TRY(encoder.encode(value));
|
||||
|
@ -145,7 +148,7 @@ ErrorOr<void> encode(Encoder& encoder, T const& vector)
|
|||
template<Concepts::HashMap T>
|
||||
ErrorOr<void> encode(Encoder& encoder, T const& hashmap)
|
||||
{
|
||||
TRY(encoder.encode(static_cast<u32>(hashmap.size())));
|
||||
TRY(encoder.encode_size(hashmap.size()));
|
||||
|
||||
for (auto it : hashmap) {
|
||||
TRY(encoder.encode(it.key));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue