Binary data: Structs and ArrayBuffers
dherman at mozilla.com
Mon Dec 3 17:34:06 PST 2012
On Dec 3, 2012, at 11:53 AM, Jussi Kalliokoski <jussi.kalliokoski at gmail.com> wrote:
> I was just reading through the binary data proposal  and I have a few comments / questions:
> First of all, how will this integrate with the Typed Arrays?
Typed Arrays will become a special case of binary data objects. In other words, the binary data API generalizes typed arrays completely.
> Will a struct have an intrinsic ArrayBuffer?
Yes, but with some exceptions. We will be extending the API to allow fields of type "object" (basically, pointers to JS objects) or the type "any" (basically, any JS value whatsoever), but those types will not be allowed to expose their ArrayBuffer.
> What about an ArrayType instance? If they do, how will it react to typeless properties? Are typeless properties allowed in the first place (IIRC there was a talk I watched where David Herman or someone else said that this might be)? Will you be able to extract structs out of an ArrayBuffer?
Same story: if you have the type "object" or the type "any" you can't get at the underlying ArrayBuffer.
> What about strings? Looking through the binary data related proposals, there seems to be no good way of extracting strings from binary data. Should we have, for example StringType(DOMString encoding, uint length, boolean isPadded=false) for Structs? Or, should DataView have a method for extracting a string from it? What about storing one?
As Ken says, the WhatWG string encoding/decoding spec is the way to do that. The important thing to recognize is that a string formats are just that -- encoding/decoding formats -- rather than "types." There isn't and won't be a string type, or a UTF8 type, or anything like that in the API.
> Pointers. Now it's useful if a struct can contain an array of arbitrary size, but we don't have pointers. We can't let the struct be of arbitrary size either. What are the thoughts on this?
> Arrays inside structs. Are there plans for this? They're not absolutely necessary, but often quite handy anyway, for example:
> unique: uint32
That's definitely supported.
> Also, what's the plan with Typed Arrays anyway? Are we going to adopt them as a part of JS or leave it as an extension?
I think binary data will be very nice in ES6, and I'm excited about where it's headed. We've started implementation in SpiderMonkey and hopefully before too long people will be able to start experimenting with it in nightly builds of Firefox.
Thanks for your questions!
More information about the es-discuss