[whatwg] API for encoding/decoding ArrayBuffers into text

Brandon Jones tojiro at gmail.com
Wed Mar 14 08:15:12 PDT 2012

On Wed, Mar 14, 2012 at 1:14 AM, Cedric Vivier <cedricv at neonux.com> wrote:

> What are the 'late' use cases for this?
> The question might sound naive, but to me the encoding/decoding would
> have been really great to have during the time when we didn't have
> support for ArrayBuffers in general input/output APIs like we have now
> (XHR, WebSockets, File API, ...) - which sounds like the mainstream
> use cases to me.

I brought up a use case with Mozilla during their Games Work Week. When
designing formats for games there's a desire to make the content small and
parse fast to keep load times down. When talking about something like a 3D
mesh format, it's very convenient to deliver the mesh to the browser
with responseType = "arraybuffer", as this allows us to push views of the
resulting array directly into WebGL buffers.

There's a lot of content within a model that doesn't cleanly map to a
binary array, however. A good example is if you want to include shader code
as part of the model. It's also very popular currently to use JSON to
describe model metadata. In these cases currently developers have two
choices: embed the string data in the binary buffer, which requires
cumbersome byte-by-byte extraction, or store it in a secondary file that is
requested as string data to begin with. This is the route I've seen taken
most often: Three.js uses it currently, for example. In either case,
however, you are being slowed down by either the string parsing overhead or
the second request.

With the proposed API it would be practical and fast to store string data
and binary mesh data in the same ArrayBuffer, which would be a boon to game
developers seeking to make HTML5 into a first-class gaming platform.


More information about the whatwg mailing list