You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a serializable class whose 2 first fields are a Uuid in need of a binary serializer, so I set up @file:UseContextualSerialization(Uuid::class) for them and tried to use the BinarySerializer provided by this library.
After looking at https://protobuf-decoder.netlify.app/ to see what the payload looked like, this is what I got:
(image for 08 d9 84 9d 86 d1 f6 8b aa eb 01 08 bd cf ff be 82 c8 a8 ef b5 01 10 84 90 89 b5 c7 d7 be 91 96 01 10 89 c6 c4 ca ca f4 f3 b6 a9 01)
I was not quite happy with the results, ~22 bytes per uuid is a lot of overhead, so I decided to test another serializer using a byte array and the results improved quite a lot:
(image for 0a 10 bb e3 92 bd 34 e5 47 9d 83 b1 9e bb b2 f5 ee 88 12 10 0a 51 15 dc 61 36 43 0e a5 ee 9b 7d 60 4e e3 4f)
With the new serializer, the overhead is 2 bytes per uuid instead of 6. It's also much easier to reason about and inspect in debug tools when needed to (the visual representation in the screenshot above is almost the dash representation of the uuid).
I propose the class below is added to this library:
I have a serializable class whose 2 first fields are a
Uuid
in need of a binary serializer, so I set up@file:UseContextualSerialization(Uuid::class)
for them and tried to use theBinarySerializer
provided by this library.After looking at https://protobuf-decoder.netlify.app/ to see what the payload looked like, this is what I got:
![image](https://private-user-images.githubusercontent.com/251695/395764253-78aa3d58-bfd4-471e-a49c-81f0a2dee438.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNzczMTIsIm5iZiI6MTczOTI3NzAxMiwicGF0aCI6Ii8yNTE2OTUvMzk1NzY0MjUzLTc4YWEzZDU4LWJmZDQtNDcxZS1hNDljLTgxZjBhMmRlZTQzOC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjExJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMVQxMjMwMTJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1lNThiZDgzYjVkYmQ3MGNhMmYyYjkxMTA4YTg1YjU2YjMxMzIzYjlkNmRjNzg5YjFkY2U1NzlhNzBjYTgwYTAyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.-NaztOTX_fKaeeXti7xJCkMtGjKRKtb0ZEDSk4PPMpA)
(image for
08 d9 84 9d 86 d1 f6 8b aa eb 01 08 bd cf ff be 82 c8 a8 ef b5 01 10 84 90 89 b5 c7 d7 be 91 96 01 10 89 c6 c4 ca ca f4 f3 b6 a9 01
)I was not quite happy with the results, ~22 bytes per uuid is a lot of overhead, so I decided to test another serializer using a byte array and the results improved quite a lot:
![image](https://private-user-images.githubusercontent.com/251695/395764176-a3918255-4bf9-4356-bd03-9ee62f076576.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNzczMTIsIm5iZiI6MTczOTI3NzAxMiwicGF0aCI6Ii8yNTE2OTUvMzk1NzY0MTc2LWEzOTE4MjU1LTRiZjktNDM1Ni1iZDAzLTllZTYyZjA3NjU3Ni5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjExJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMVQxMjMwMTJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wMTI0NmE4NjQ3MjA2NzU1NmI2Zjk3MDI3OTA2NjlmZTE3NDM0YzBhY2JkOTVmZTE3MDBjM2MwNjM5OGJkYTdlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.28ra4FfN3-1iZO_tCVc1NapC_aX3bzZsFW8SEaCUy3w)
(image for
0a 10 bb e3 92 bd 34 e5 47 9d 83 b1 9e bb b2 f5 ee 88 12 10 0a 51 15 dc 61 36 43 0e a5 ee 9b 7d 60 4e e3 4f
)With the new serializer, the overhead is 2 bytes per uuid instead of 6. It's also much easier to reason about and inspect in debug tools when needed to (the visual representation in the screenshot above is almost the dash representation of the uuid).
I propose the class below is added to this library:
I can raise a PR if you think it's worth.
We may also deprecate
BinarySerializer
as well, unless its performance is much better in Cbor in which case a new name might help.The text was updated successfully, but these errors were encountered: