Results 1 to 15 of 15

Thread: VB6 - BasicBuffer, Binary Stream Class

Threaded View

  1. #1

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Lightbulb VB6 - BasicBuffer, Binary Stream Class

    Description

    A simple stream-style buffer class.

    This is a kind of binary stream, similar to an ADO Steam object in Type = adBinary mode or an OLE IStream object. It accepts and returns Byte arrays, Integers, and Longs but not text String values.

    It can be useful whenever you want a data structure that supports something similar to concatenating Byte arrays when you need to accumulate data arriving in bits and pieces and extract chunks for use. Things like Winsock control and MSComm control binary communication come to mind.

    The properties and methods are similar to those of an ADO Stream.

    This class has a lot of things in it to handle common needs. Remove anything you don't need in your programs.

    I have done a lot of testing, but bug reports and fixes would be welcome.


    Properties

    ChunkSize As Long [R/W]
    EOS As Boolean [RO]
    HaveAtLeast(Length As Long) As Boolean [RO]
    IsOpen As Boolean [RO]
    Position As Long [R/W]
    Size As Long [RO]



    Methods

    CloseBuf()
    CurrentBytes() As Byte()
    DeleteBytes(Optional ByVal Length As Long = -1)
    ExtractBytes(Optional ByVal Length As Long = -1) As Byte()
    ExtractInteger() As Integer
    ExtractLong() As Long
    OpenBuf()
    ReadBytes(Optional ByVal Length As Long = -1) As Byte()
    ReadInteger() As Integer
    ReadLong() As Long
    ScanForBytes(ByRef Target() As Byte) As Long
    SetEOS()
    ShrinkBuf()
    WriteBytes(ByRef Bytes() As Byte)
    WriteInteger(ByVal Value As Integer)
    WriteLong(ByVal Value As Long)



    Attachment

    The attached archive contains BasicBuffer.cls as well as a testing Project.

    It uses character data for easy reading/debugging here (converting to/from Unicode as needed) though BasicBuffers are normally for binary data.

    This looks weird but tries to provide a test for correctness of as many operations as possible.


    Requirements

    No special requirements. You just need VB6. It may also work in Office VBA and VB5 (not tested).

    See comments in the code for more help in understanding its use.
    Attached Files Attached Files
    Last edited by dilettante; Nov 3rd, 2013 at 05:33 PM. Reason: replaced attachment

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width