[interfacekit] Re: Flattened BMessages

  • From: "Cedric Degea" <cdegea@xxxxxxxxxxxxxxxx>
  • To: interfacekit@xxxxxxxxxxxxx
  • Date: Wed, 22 May 2002 00:26:18 +0200

> 
>Has anyone looked into the flattened BMessage format yet?

A little bit;

> I wrote a BMessage 
>implementation, but flattening and unflattening is still not 
compatible. 
> 

Neither is mine; things looked good for simple cases (one-level,
ie. not Addmessage()ing a message within another) but I realized
later it does not "scale up".. here's what I have anyway in case
it helps; let's start with a simple
overview, the  BMessage::FlattenedSize() method:

{
        // declare accumulator, and init right away to header size
        ssize_t size =
                sizeof('1BOF')
                +4  ///??
                +sizeof(ssize_t)
                +sizeof(uint32)
                +1  ///??
                ;
        
        // add up each slot into the accumulator
        for( uint32 i = 0 ;  i < nameList.size() ;  i++ )
        {
                size += 1;  ///??
                size += sizeof( type_code );
                size += sizeof( uint8 );
                size += sizeof( uint8 ) +strlen(nameList[i].slotName);
                size += dataLengthAt( i );
        }
        
        // trailing null byte
        size += sizeof('\0');
        
        // finito!
        return size;
}



This does not reflect some more thinking I had to do afterwards
when realizing I was missing a big piece of the puzzle:
(here i've had to censor some of the fairly ugly comments in French
I had written that outline my ignorance) :


status_t BMessage::Flatten( BDataIO * stream, ssize_t * size_into = NULL 
) const
{
        ssize_t flattened_size = FlattenedSize();
        
        stream->Write( "1BOF", 4 );  ///maybe this is actually 'FOB1' in intel 
notation?? (Flattened Object format version 1..)
        stream->Write( "????", 4 );  /// ressembles a flattened_size & 
0x10000000 sometimes, sometimes not.. is that a hash or what?
        stream->Write( &flattened_size, sizeof(ssize_t) );
        stream->Write( &what, sizeof(uint32) );
        stream->Write( "?", 1 );  ///hard-coded to 0x01 maybe?
        
        for( uint32 i = 0 ;  i < nameList.size() ;  i++ )
        {
                // ..remember the size..
                ssize_t payload_len = dataLengthAt( i );
                
#warning nah, for integers (int8, int32..) ok, but it seems for a STRING 
it becomes 0x03....
#warning ** TODO refaire mon code, Be's ' BMessage slot header is 
actually
/*
        0x01
        0x0f or 0x03
        GNOL or RTSC or..
        num_entries if string, num bytes if integers (! ***)
        num bytes i nthe WHOLE section (! ****) i.e., AddString + AddString 
will produce a 0x18 here!
[snip - how the heck are STRINGS stored??]
*/
                // Be's BMessage seems to have a 0x0f before each field..??
                uint8 weird_header = 0x0f;
                stream->Write( &weird_header, sizeof(uint8) );
                
                // slotType, e.g. 'LONG'
                stream->Write( &nameList[i].slotType, sizeof(type_code) );
                
                // numItems * sizeof one atom.
                stream->Write( &payload_len, sizeof(uint8) );  //use an uint8 
rather 
than ssize_t?  Nope it works as is even on Intel...
                
                // slotName, e.g. "bytes"
                uint8 len = strlen( nameList[i].slotName );
                stream->Write( &len, sizeof (uint8) );
                stream->Write( nameList[i].slotName, len );
                
                // dataAddy
                stream->Write( nameList[i].dataAddy, payload_len );
        }
        
        // Be's BMessage appends a blank byte at the end...??
        stream->Write( "", sizeof('\0') );
        
        
        // Also process our second param
        //
        if( size_into )
                *size_into = flattened_size;
        
        // success
        return B_OK;
}


Cedric (thankful to be lurking here and every now and then
trying to justify being allowed to with meager tidbits :-)
--
http://cdegea.free.fr/ | BeDev E-16870
"What's oil got to do, got to do with it" -- F02 Chorus



Other related posts: