[SabreAMF] SabreAMF and ByteArray

Jim Mischel jim at mischel.com
Tue Nov 14 10:57:21 EST 2006


SabreAMF does not currently support AMF type 0x0C, which is a Flash 
ByteArray.  Looking at a dump of the AMF created when I pass a 
ByteArray, it appears that the ByteArray format is very similar to the 
String format.  That is, 0x0C followed by an integer-data length, 
followed by the bytes in the array.  As with Strings, the low bit of the 
length determines whether it's a literal ByteArray or a reference to a 
previous ByteArray.

It would be simple enough to code up something that reads this data 
type, but there's a problem:  there is no PHP data type that corresponds 
to a ByteArray.  It appears that I can use a PHP string to hold the 
bytes, but that becomes problematic on serialization.  If the serializer 
sees a string, how does it know whether output it as a String (type 
0x06) or a ByteArray (type 0x0C)?  Being something of a PHP novice, I 
could be missing something.  But there doesn't appear to be a distinct 
PHP data type that I can use for the ByteArray.

The solution I stumbled on was to mangle the name of the ByteArray when 
I read it.  For example, if I get a ByteArray field called 'data', I 
mangle the name by adding (prepending or appending) something to the 
field name.  'data', for example, would become 'data_BA' (for 
ByteArray).  This, of course, requires that I either mangle every field 
name by adding its type, or tell clients that they can't use variables 
that end in '_BA' (or whatever the mangling characters are).

The other problem with this approach is ... mangled names.  And mangled 
names are a serious pain to work with, as we discovered years ago when 
working with the Hungarian notation so common in old-style Windows 
programming.  lpszFileName, and all that rot.

Any thoughts on this one?  Suggestions how to handle ByteArray?

Jim






More information about the sabreamf mailing list