public void Write( Stream output )
{
long pos = output.Position;
BinaryWriter bw = new BinaryWriter( output );
bw.Write( _actionCode );
//
// When the MSB of the action is set, a length field MUST follow
if ( 0 != ( _actionCode & 0x80 ) )
{
//
// fancy action, let it do the rendering into a MemoryStream
//
using ( MemoryStream ms = new MemoryStream() )
{
BinaryWriter mbw = new BinaryWriter( ms );
ulong innerLength = Render( mbw );
if ( innerLength > 0xFFFF )
{
AVM1ExceptionByteCodeFormat e = new AVM1ExceptionByteCodeFormat( "Rendered action is larger than 0xFFFF bytes" );
Log.Error(this, e );
throw e;
}
UInt16 writeLength = ( UInt16 )innerLength;
bw.Write( writeLength );
//
// Yes, this check makes sense. See ActionCall.
//
if ( innerLength > 0 )
{
ms.WriteTo( output );
}
if ( innerLength != _length )
{
AVM1ExceptionByteCodeFormat e = new AVM1ExceptionByteCodeFormat( "Rendered action size differs from _length (" + innerLength.ToString( "d" ) + " vs. " + _length.ToString( "d" ) );
Log.Error(this, e );
throw e;
}
}
}
//Log.Debug(this, this.ToString() + " (" + ( output.Position - pos ).ToString("d") + " bytes)" );
}