Binary data: Structs and ArrayBuffers

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Dec 3 12:14:18 PST 2012


On Mon, Dec 3, 2012 at 11:53 AM, Jussi Kalliokoski <
jussi.kalliokoski at gmail.com> wrote:

> I was just reading through the binary data proposal [1] and I have a few
> comments / questions:
>
> First of all, how will this integrate with the Typed Arrays?


Typed Arrays are already using similar logic where Float32Array is, as
example, a new ArrayType(float32, length)



> Will a struct have an intrinsic ArrayBuffer? What about an ArrayType
> instance?


I believe Float32Array should be instanceof ArrayType



> 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?
>

I hope so ... MyStructArray = new ArrayType(new
StructType({myStruct:fields}), length) so that new MyStructArray([st])[0]
will be your struct?



>
> 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?
>

what is an arbitrary size struct? what do you mean?



>
> Arrays inside structs. Are there plans for this?


I think supported already

const Pixel = new StructType({ point: Point2D, color: Color });

same could be {color: Uint8Array} ... isn't it ? is as RGBA



>
> 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?
>

predefined handy natives?



>
> Binary stuff is hard in a language like JavaScript,


not really, JS has type checks since ever, just consider TypeError
constructor ;-)




> but I think that ultimately we'll get something workable, and would love
> to see more discussion around this!
>
>
for what is worth it, I wrote a way to test now this stuff in 2011 ...
http://webreflection.blogspot.com/2011/09/introduction-to-js-ctypes.html

That is (was?) a workable shim for typed stuff in JS, grab any FF and test
it

br
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121203/8dca5c48/attachment.html>


More information about the es-discuss mailing list