Class: Fox::FXStream

Inherits:
Object
  • Object
show all
Defined in:
rdoc-sources/FXStream.rb,
lib/fox16/iterators.rb

Overview

A stream is a way to serialize data and objects into a byte stream. Each item of data that is saved or loaded from the stream may be byte-swapped, thus allowing little-endian machines to read data produced on big endian ones and vice-versa. Data is serialized exactly as-is. There are no tags or other markers inserted into the stream; thus, the stream may be used to save or load arbitrary binary data. Objects derived from FXObjects may be serialized also; whenever a reference to an object is serialized, a table is consulted to determine if the same object has been encountered previously; if not, the object is added to the table and then its contents are serialized. If the object has been encountered before, only a reference to the object is serialized. When loading back a serialized object, new instances are constructed using the default constructor, and subsequently the object's contents are loaded. A special container object may be passed in which is placed in the table as if it had been encountered before; this will cause only references to this object to be saved. The container object is typically the top-level document object which manages all objects contained by it. Additional objects may be added using addObject(); these will not be actually saved or loaded.

Stream status codes

FXStreamOK

OK

FXStreamEnd

Try read past end of stream

FXStreamFull

Filled up stream buffer or disk full

FXStreamNoWrite

Unable to open for write

FXStreamNoRead

Unable to open for read

FXStreamFormat

Stream format error

FXStreamUnknown

Trying to read unknown class

FXStreamAlloc

Alloc failed

FXStreamFailure

General failure

Stream data flow direction

FXStreamDead

Unopened stream

FXStreamSave

Saving stuff to stream

FXStreamLoad

Loading stuff from stream

Stream seeking

FXFromStart

Seek from start position

FXFromCurrent

Seek from current position

FXFromEnd

Seek from end position

Direct Known Subclasses

FXFileStream, FXMemoryStream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cont = nil) ⇒ FXStream

Construct stream with given container object. The container object is an object that will itself not be saved to or loaded from the stream, but which may be referenced by other objects. These references will be properly saved and restored.

Parameters:

cont

the container object, or nil if there is none Fox::FXObject.


74
75
# File 'rdoc-sources/FXStream.rb', line 74

def initialize(cont=nil) # :yields: theStream
end

Instance Attribute Details

#containerObject (readonly)

Parent object Fox::FXObject


56
57
58
# File 'rdoc-sources/FXStream.rb', line 56

def container
  @container
end

#directionObject (readonly)

Stream direction, one of FXStreamSave, FXStreamLoad or FXStreamDead.


53
54
55
# File 'rdoc-sources/FXStream.rb', line 53

def direction
  @direction
end

#positionObject

Stream position (an offset from the beginning of the stream) [Integer]


62
63
64
# File 'rdoc-sources/FXStream.rb', line 62

def position
  @position
end

#spaceObject

Available buffer space


59
60
61
# File 'rdoc-sources/FXStream.rb', line 59

def space
  @space
end

#statusObject (readonly)

Stream status [Integer]


50
51
52
# File 'rdoc-sources/FXStream.rb', line 50

def status
  @status
end

Instance Method Details

#bigEndian=(big) ⇒ Object

Set stream to big endian mode if true. Byte swapping will be enabled if the machine native byte order is not equal to the desired byte order.


134
# File 'rdoc-sources/FXStream.rb', line 134

def bigEndian=(big); end

#bigEndian?Boolean

Return true if big endian mode.

Returns:

  • (Boolean)

139
# File 'rdoc-sources/FXStream.rb', line 139

def bigEndian?; end

#bytesSwapped=(swapBytes) ⇒ Object

Set the byte-swapped flag to true or false.


124
# File 'rdoc-sources/FXStream.rb', line 124

def bytesSwapped=(swapBytes); end

#bytesSwapped?Boolean

Returns true if bytes are swapped for this stream

Returns:

  • (Boolean)

127
# File 'rdoc-sources/FXStream.rb', line 127

def bytesSwapped?; end

#closeObject

Close stream; returns true if OK.


95
# File 'rdoc-sources/FXStream.rb', line 95

def close(); end

#eof?Boolean

Return true if at end of file or error.

Returns:

  • (Boolean)

115
# File 'rdoc-sources/FXStream.rb', line 115

def eof?; end

#error=(err) ⇒ Object

Set status code, where err is one of the stream status codes listed above.


121
# File 'rdoc-sources/FXStream.rb', line 121

def error=(err); end

#flushObject

Flush buffer


100
# File 'rdoc-sources/FXStream.rb', line 100

def flush(); end

#getSpaceObject

Get available buffer space


105
# File 'rdoc-sources/FXStream.rb', line 105

def getSpace(); end

#open(save_or_load, size = 8192, data = nil) ⇒ Object

Open stream for reading or for writing. An initial buffer size may be given, which must be at least 16 bytes. If data is not nil, it is expected to point to an external data buffer of length size; otherwise the stream will use an internally managed buffer. Returns true on success, false otherwise.

Parameters:

save_or_load

access mode, either FXStreamSave or FXStreamLoad [Integer]

size

initial buffer size [Integer]

data

external data buffer (if any) [String]


90
# File 'rdoc-sources/FXStream.rb', line 90

def open(save_or_load, size=8192, data=nil); end

#setSpace(sp) ⇒ Object

Set available buffer space


110
# File 'rdoc-sources/FXStream.rb', line 110

def setSpace(sp); end