Writer

qtdatastream/writer~ Writer

Class to generate a buffer from a Javascript object

Constructor

new Writer(obj)

Parameters:
Name Type Description
obj Object

Javascript object

Source:
Example
var w = new Writer(obj);
var buffer = w.getBuffer(); //Buffer ready to be sent to a socket !

Methods

(static) conv(msg) → {Buffer}

Converts an UTF-8 string to an UTF-16 buffer

Parameters:
Name Type Description
msg Buffer

An UTF-8 string

Source:
Returns:

An UTF-16 Buffer

Type
Buffer

(protected) _parse(obj) → {Number}

Parses next element of the buffer

Parameters:
Name Type Description
obj *
Source:
Returns:

Type as defined in module:qtdatastream.Types

Type
Number

(protected) _parse_bool(obj)

Parameters:
Name Type Description
obj QBool
Source:

(protected) _parse_class(obj, key, newclass)

If obj[key] is not of class newclass, instanciate it. Then call _parse().

Parameters:
Name Type Description
obj *
key *
newclass *
Source:

(protected) _parse_qbytearray(obj)

Parameters:
Name Type Description
obj QByteArray
Source:

(protected) _parse_qchar(obj)

Parameters:
Name Type Description
obj QChar
Source:

(protected) _parse_qdatetime(obj)

Parameters:
Name Type Description
obj QDateTime
Source:

(protected) _parse_qdouble(obj)

Parameters:
Name Type Description
obj QDouble
Source:

(protected) _parse_qint(obj)

Parameters:
Name Type Description
obj QInt
Source:

(protected) _parse_qint64(obj)

Parameters:
Name Type Description
obj QInt64
Source:

(protected) _parse_qinvalid()

Source:

(protected) _parse_qlist(obj)

Parameters:
Name Type Description
obj QList
Source:

(protected) _parse_qmap(obj)

Parameters:
Name Type Description
obj QMap
Source:

(protected) _parse_qshort(obj)

Parameters:
Name Type Description
obj QShort
Source:

(protected) _parse_qstring(obj)

Parameters:
Name Type Description
obj QString
Source:

(protected) _parse_qstringlist(obj)

Parameters:
Name Type Description
obj QStringList
Source:

(protected) _parse_quint(obj)

Parameters:
Name Type Description
obj QUInt
Source:

(protected) _parse_quint64(obj)

Parameters:
Name Type Description
obj QUInt64
Source:

(protected) _parse_qusertype(obj)

Parameters:
Name Type Description
obj QUserType
Source:

(protected) _parse_qvariant(obj)

Parameters:
Name Type Description
obj QVariant
Source:

getBuffer() → {Buffer}

Get the buffer representation of the object. It is prefixed by the packet size as defined in Qt framework.

Source:
Returns:

A Qt styled buffer ready to be sent through a socket

Type
Buffer

getRawBuffer() → {Buffer}

Get the buffer without prefixing it by its size.

Source:
Returns:
Type
Buffer

parse(obj)

Should not be called directly, it is better to call new Writer(...) with the object as parameter

Parameters:
Name Type Description
obj *
Source:

write(b) → {Writer}

Add specified buffer to the internal buffer list

Parameters:
Name Type Description
b Buffer
Source:
Returns:
Type
Writer

writeBool(bool) → {Writer}

Add a boolean buffer to the internal buffer list

Parameters:
Name Type Description
bool Number | boolean
Source:
Returns:
Type
Writer

writeByteArray(arr) → {Writer}

Add a byteArray buffer to the internal buffer list

Parameters:
Name Type Description
arr Array | string
Source:
Returns:
Type
Writer

writeChar(str) → {Writer}

Add a char buffer to the internal buffer list

Parameters:
Name Type Description
str string
Source:
Returns:
Type
Writer

writeDateTime(i) → {Writer}

Add a QDateTime buffer to the internal buffer list.

Parameters:
Name Type Description
i Date
Source:
Returns:
Type
Writer

writeDouble(i) → {Writer}

Add a double buffer to the internal buffer list

Parameters:
Name Type Description
i Number
Source:
Returns:
Type
Writer

writeInt(i) → {Writer}

Add a int32 buffer to the internal buffer list

Parameters:
Name Type Description
i Number
Source:
Returns:
Type
Writer

writeInt64(i) → {Writer}

Add a int64 buffer to the internal buffer list

Parameters:
Name Type Description
i Number
Source:
Returns:
Type
Writer

writeQVariant(type, nullFlag) → {Writer}

Add a qvariant buffer to the internal buffer list

Parameters:
Name Type Description
type Number

Type as defined in module:qtdatastream.Types

nullFlag Number | boolean

must be true or 1 if the following QVariant is null

Source:
Returns:
Type
Writer

writeShort(i) → {Writer}

Add a uint16 buffer to the internal buffer list

Parameters:
Name Type Description
i Number
Source:
Returns:
Type
Writer

writeString(str) → {Writer}

Add a string buffer to the internal buffer list

Parameters:
Name Type Description
str string
Source:
Returns:
Type
Writer

writeUInt(i) → {Writer}

Add a uint32 buffer to the internal buffer list

Parameters:
Name Type Description
i Number
Source:
Returns:
Type
Writer

writeUInt64(i) → {Writer}

Add a uint64 buffer to the internal buffer list

Parameters:
Name Type Description
i Number
Source:
Returns:
Type
Writer