protobuf-javascript icon indicating copy to clipboard operation
protobuf-javascript copied to clipboard

Using JS typed arrays in JoinFloat

Open tomasreimers opened this issue 7 years ago • 1 comments

Hi,

Has anyone thought of using JS typed arrays in the splitFloat and joinFloat methods for the JavaScript library (https://github.com/google/protobuf/blob/master/js/binary/utils.js#L388)?

One could imagine adding something like:

jspb.utils.joinFloat64 = function(bitsLow, bitsHigh) {
    if (window.Uint32Array) {
        bytes = Uint8Array.of(bitsLow, bitsHigh)
        data = new Float64Array(bytes.buffer)
        return data[0];
    }
    // ...
}

And vica-versa for the splitFloat method. This might increase readability (and depending on if it taps into the JS engine's native implementation, maybe even speed).

Happy to write the PR, just curious if it would be useful / appreciated!

Let me know,

tomasreimers avatar Jun 19 '17 19:06 tomasreimers