Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation from source code
Components
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Arithmetical Functions
Arithmetic Operators
Array Declaration
Assignment Operators
Assignments
Binary Data Representation
Bits Manipulation Functions
Character Test Functions
Comparison methods
Complex numbers
Constant Declaration
Constant Expression
Conversion Functions
Datatype Functions
Datatypes
Date & Time Functions
Enumeration declaration
Error Management
Event Loop
Event Management
Events declaration
Expressions
External Function Management
File & Directory Functions
File & Directory Paths
File mode syntax
Floating Point Numbers
Formatting functions
Gambas Object Model
Global Special Event Handlers
Integer numbers
Intrinsic Functions
Language Constants
Localization and Translation Functions
Local Variable Declaration
Logarithms & Exponentials Functions
Logical Operators
Loop Control Structures
Method Declaration
Miscellaneous Control Structures
Miscellaneous Functions
Native Arrays
Native Container Classes
Object & Class Management
Operator Evaluation Order
Predefined Constants
Process Management
Property Declaration
Random Numbers Functions
Special Methods
Stream & Input/Output functions
String Functions
String Operators
Structure declaration
Test Control Structures & Functions
Trigonometric Functions
User-defined formats
Using reserved keywords as identifiers
Variable Declaration
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

Binary Data Representation

The READ and WRITE instructions allow to read and write binary representation of Gambas datatypes values.

Datatype Size Representation
Boolean 1 byte 0 for FALSE, 255 for TRUE.
Byte 1 byte The data value in binary.
Short 2 bytes The data value in binary.
Integer 4 bytes The data value in binary.
Long 8 bytes The data value in binary.
Pointer 4 bytes in 32 bits
8 bytes in 64 bits
The pointer value in binary.
Single 4 bytes The data value in binary.
Float 8 bytes The data value in binary.
Date 8 bytes The date and time as two four-bytes integers.
String variable The string length is written first, as a variable-length integer number:
  • One byte is written if the string length is lower or equal than 127 characters.

  • Two bytes are written if the string length is between 128 and 16383 characters.

  • Four bytes are written if the string length is between 16384 and 1073741824 characters.

  • Longer strings cannot be written at the moment.

Then the string contents is written.

Since 3.15

If the Stream.NullTerminatedString property is set, then strings are null terminated instead. No string length is read or written.
NULL 1 byte Null values and null strings are written as a single 0 byte.
Variant Variable When writing a variant value, a byte indicating the value datatype is written before. The value itself is written according to this table.
Array 2 bytes + array length + array contents
  • One byte whose value is 65.

  • One byte whose value represents the array contents datatype.

  • The array length, written like a string length.

  • The value of each array element.

Collection 1 byte + collection length + collection contents
  • One byte whose value is 67 if the collection keys are case sensitive, 99 if they are not case sensitive.

  • The collection length, written like a string length.

  • For each collection item:
    • The key, written as a string

    • Its associated value.

Structure Contents size
  • The structure contents are written in declaration order recursively.

  • Embedded arrays items are written in order. Contrary to normal arrays, no size or type header is written.

Serializable objects

Since 3.15
1 byte + class name (optional) + object contents
  • One byte whose value is 79 or 111.

  • If the initial byte is 111, the class name is written that way:
    • One byte for the class name length, between 1 and 255.

    • The class name.

  • The object contents as written by the _write method of the class.

The endianness of the binary data is the endianness of the stream.

See also