New Feature #345345

| | Comments (1)

BinaryStreams with different storage backings!

In previous versions of REALbasic, a BinaryStream represented one thing only -- a file on disk. Now you can back a BinaryStream with a MemoryBlock, or a string. This is really handy when you want to construct a MemoryBlock, but don't want to mess around with keeping track of positions.

[rbcode]
// Make a 0-length memory block
dim mb as new MemoryBlock( 0 )
// And back a BinaryStream with it
dim bs as new BinaryStream( mb )

// Write some data to the stream
bs.WriteLong( 12 )
bs.WriteShort( 456 )

// Close our stream down
bs.Close

MsgBox Str( mb.Size ) // Will show 6
MsgBox Str( mb.Short( 2 ) ) // Will show 456
[/rbcode]
This sort of thing is really handy when you want to construct packets that you send out over a socket or serial device.

1 Comments

Huh. I'd forgotten all about that feature.

Leave a comment

Disclaimer

I'm currently an employee of REAL Software. My blog is mine. The opinions represented in this blog are mine as well and may not represent my employer's opinions. All original material is copyrighted and property of the author.

REALbasic® is a registered trademark of REAL Software, Inc. REAL SQL Server™ and Lingua™ are pending trademarks of REAL Software, Inc. All rights reserved.