Open BtheDestroyer opened 1 year ago
Did you see the decode_u8|16|32|64()
methods in PackedByteArray (and their encode_u8|16|32|64()
counterparts)? These also exist for signed integers, halfs, floats and doubles. Encoding/decoding arbitrary Variants this way is also possible.
Yes, and while those are undoubtedly useful and provide the functionality most people will want, I'm suggesting an even more fine-grained set of functionality to operate both on a more arbitrary number of bits (maybe I have a 4-bit int or a 12-bit int or an array of 1-bit bools) and with a bit-resolution offset (store starting at byte 3, bit 6).
As stated, this can be done manually (encoding booleans as bit flags within a uint is an easy example), but doing so takes a considerable amount of code and care.
Describe the project you are working on
Low level networking library with binary de/serialization
Describe the problem or limitation you are having in your project
Encoding individual bits or otherwise packing data into sub-byte sizes is cumbersome, repetitive, and somehow tends to be simultaneously both overly verbose and unclear:
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I propose adding the following method signatures:
Admittedly, these are the first names and signatures that came to mind, so they could do with iteration and feedback.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Example usage:
If this enhancement will not be used often, can it be worked around with a few lines of script?
Utility functions to achieve the desired effect could be implemented in GDScript as an add-on, but it would require a considerable amount of code to be flexible.
Is there a reason why this should be core and not an add-on in the asset library?
It feels like GDScript imparts a significant performance overhead for performing this low-level of memory manipulation. It could also be used in various scenarios and could have direct impact of the available functionality of any situation in which binary data serialization is relevant (eg: network packets, save files, resource/configuration files).