- From: Maciej Hirsz <notifications@github.com>
- Date: Fri, 19 Aug 2016 06:03:51 -0700
- To: whatwg/encoding <encoding@noreply.github.com>
- Message-ID: <whatwg/encoding/issues/69@github.com>
For binary protocols, such as msgpack, performance of writing/reading strings can be crucial, however those strings rarely (virtually never) exist on a binary buffer on their own. When decoding a string from a binary buffer of Uint8Array (obtained over, say, websockets) it's possible to cheaply create a subarray and pass it over to `TextDecoder#decode`, as such the decoding story is pretty straight forward. The writing story is much more complicated. In order to write a string into an existing buffer, one must take the result `Uint8Array` from `TextEncoder#encode` and `TypedArray#set` it at a desired offset into another buffer, which introduces unnecessary copying and, as result, is slower than plain JavaScript encoding implementations. A much better solution would be analog to the Node.js [`Buffer#write` implementation](https://nodejs.org/api/buffer.html#buffer_buf_write_string_offset_length_encoding) where the encoder can write a string to a buffer at a desired offset. Example signature could be something like: ``` TextEncoder#write(DOMString source, Uint8Array target [, Number offset [, Number length]]) ``` -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/encoding/issues/69
Received on Friday, 19 August 2016 13:04:19 UTC