ByteArray101 with Ben Stucki

This presentation by Ben Stucki, a software engineer with Atellis, is on ByteArray 101. This is directly after lunch so I am struggling not to slip back to the hotel and have a nap. However, as has been said before, "Sleep: a poor substitute for caffeine. ~Author Unknown" and the fine organizers of 360Flex have ensured a continual supply of caffeine.

Flex gives you the power to work with one byte at a time. This means content and formats that aren't fully supported can be read with a ByteArray. All data is represented as binary. Also, sockets use binary data so using the ByteArray is perfect for extending the fles framework in new and exciting ways. A byte is 8 bits and a bit represents an on / off state.

Ben is now going over bit arithmetic. 00000001 = 1, 00000010 = 2 etc. Bytes have a maximum value of 255. 4 Bytes can compose a uint(unsigned integer) or an int. 8 Bytes compose a number data type and a string is a variable number of Bytes.

A Byte array is an array of Bytes and typically the array is read from beginning to end. There are several convenience methods to read Bytes and each reads a different number of Bytes before evaluation. Common methods are readUnsignedInt(), readDouble(), depending on how many Bytes you wish to read at a time.

ID3 tags are used in MP3 files to track meta data in an mp3 file. Represented as a ByteArray, each type area represents certain information. To validate an ID3 tag, read and evaluate the first three Bytes. If proper, the result will be 'id3'. The following 2 Bytes represent major and minor version respectively. Thus, by reading the Bytes, you can determine a lot of information about a stream of Bytes.

Ben is now using Apollo and Apollo code samples for this presentation. Even though this is primarily a Flex conference and Apollo won't be released until the end of the year, I am very excited to see more Apollo!

Ben's example application will pull in Album covers and read the ID3 tag information from a file. Now he is showing how to open a file from the file system. The UI control is similar to the HTML file browse but there is come custom code needed to read the list of files in. He filters the results of a file.browse() command to include only .mp3 files. Then he fills an array with the results.

Soliloquy: Now that I have seen Apollo source code, I believe it is the same code in Flex, just with a different API. How very nice that I won't have to learn yet another language. Now back to the application demonstration.

Once a file is selected, he reads the file from the filesystem using a FileStream. Then he walks from byte 0 and reads the specific sections of the byte stream. He traces out the results from the reads and we can see on the screen the id3 header. Cool stuff. You won't be doing that with javascript so take that AJAX fanboys!

Ben stresses all file formats have an established header with an ID section and other header meta data. If you know the file format, you can read any file byte by byte. Understanding it, however, is your problem (Ben's joke not mine ;))

Back to reading Bytes, Ben is tracing out all of the ID3 tags in the mp3 file read from the file system. There are a lot more tags than I thought in an MP3 file. for example, if the beginning of the ID section of a tag is 'T', the rest of the tag should be processed as text. If the ID section of a tag is 'APIC', then the tag contains information about an image thumnail somewhere in the file. You can get the start and end position of the image by reading the additional information in the tag. After the image is copied into another ByteArray, Ben creates a new Loader() loads the Bytes from the image ByteArray and then image that was once embedded in the MP3, is now displayed to the user. Look! Album Cover Art!

From this session, I feel much more confident about applying and extending Flex and Apollo. Since both frameworks offer the ability to process binary data one byte at a time, I as a developer will be able to create compelling solutions for my clients without being dependent on supported formats. To date, this was the most low-level demonstration of the power of Flex and Apollo. This isn't your Mommas HTML.

Ben shifts to Sockets and Streams now. He says the methods used to work with Sockets and Streams are the same as he used when reading a file. The key difference is a streams and sockets do not have an 'end' like a file does. Also, sockets are bi-directional.

Ben points a digital video camera at the audience. A picture of us shows on the presentation screen. This particular produces a stream of images in an MJPG stream or a stream of JPG images. There is no formalized specification for MJPG so this illustrates how to use a looser format or specification. Ben has an image effect used on this stream of JPG images. At the bottom of the images is a reflection sort of effect which looks like the pictures are reflecting off water. Very Cool Stuff.

The funniest part of this session is during the Q&A section, an audience member asked Ben if he would trust his life to an application written with Flex. Confidently, Ben answers with the affirmative. The audience member asks if Ben would trust his life to an application written in Apollo, Ben says 'Yeah', and after a pause, 'Well, not right now, Apollo is in Beta.' Gotta love that.

7932 Views Print Print Comments (0) Flex

There are no comments for this entry.

Add Comment Subscribe to Comments