Object built-in object

objectMessage

base message object

Message objects are compatible withmqVarious modules, which can be used to build custom message processing systems, create methods:

1 2
var mq = require("mq"); var m = new mq.Message();

inheritance relationship

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<this>Message|new Message()|TEXT;BINARY|value;params;type;data;body;length;stream;lastError|read();readAll();write();json();pack();end();isEnded();clear();sendTo();readFrom()] [<class>HttpMessage] [<class>HttpRequest] [<class>HttpResponse] [<class>WebSocketMessage] [object] <:- [Message] [Message] <:- [HttpMessage] [HttpMessage] <:- [HttpRequest] [HttpMessage] <:- [HttpResponse] [Message] <:- [WebSocketMessage] Message new Message() TEXT BINARY value params type data body length stream lastError read() readAll() write() json() pack() end() isEnded() clear() sendTo() readFrom() object toString() toJSON() HttpMessage HttpRequest HttpResponse WebSocketMessage

Constructor

Message

message object constructor

1
new Message();

constant

TEXT

Specify message type 1, representing a text type

1
const Message.TEXT = 1;

BINARY

Specifies message type 2, representing a binary type

1
const Message.BINARY = 2;

Member properties

value

String, the basic content of the message

1
String Message.value;

params

NArray, the basic parameters of the message

1
readonly NArray Message.params;

type

Integer, message type

1
Integer Message.type;

data

Value, query the data of the message, this property will return different data according to the content-type, when it is text, it will return the text, which isjsonreturn whenjson, otherwise returns binary

1
readonly Value Message.data;

body

SeekableStream, a stream object containing the data part of the message

1
SeekableStream Message.body;

length

Long, the length of the message data part

1
readonly Long Message.length;

stream

Stream, the stream object when querying the message readFrom

1
readonly Stream Message.stream;

lastError

String, the last error for query and set message processing

1
String Message.lastError;

member function

read

Read data of the specified size from the stream, this method is an alias of the corresponding method of body

1
Buffer Message.read(Integer bytes = -1) async;

Call parameters:

  • bytes: Integer, specify the amount of data to be read, the default is to read a random size data block, the size of the data read depends on the device

Return result:

  • Buffer, returns the data read from the stream, or null if there is no data to read or the connection is interrupted

readAll

Read all the remaining data from the stream, this method is the alias of the corresponding method of body

1
Buffer Message.readAll() async;

Return result:

  • Buffer, returns the data read from the stream, or null if there is no data to read or the connection is interrupted

write

Writes the given data, this method is an alias of the corresponding method of body

1
Message.write(Buffer data) async;

Call parameters:

  • data:Buffer, given the data to write

json

Writes the given data in JSON encoding

1
Value Message.json(Value data);

Call parameters:

  • data: Value, given the data to write

Return result:

  • Value, this method will not return data

Parse the data in the message in JSON encoding

1
Value Message.json();

Return result:

  • Value, returns the parsed result

pack

bymsgpackEncode to write the given data

1
Value Message.pack(Value data);

Call parameters:

  • data: Value, given the data to write

Return result:

  • Value, this method will not return data

bymsgpackEncoding and parsing the data in the message

1
Value Message.pack();

Return result:

  • Value, returns the parsed result

end

Set the current message processing end,ChainThe processor does not continue with subsequent transactions

1
Message.end();

isEnded

Query whether the current message is over

1
Boolean Message.isEnded();

Return result:

  • Boolean, return true when finished

clear

Clear the content of the message

1
Message.clear();

sendTo

Send a formatted message to the given stream object

1
Message.sendTo(Stream stm) async;

Call parameters:

  • stm:Stream, specifying the stream object to receive formatted messages

readFrom

Reads formatted messages from the given cache stream object, and parses the fill object

1
Message.readFrom(Stream stm) async;

Call parameters:

  • stm:Stream, specifies the stream object from which to read formatted messages

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be reimplemented according to its own characteristics

1
String Message.toString();

Return result:

  • String, returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns the set of readable properties defined by the object

1
Value Message.toJSON(String key = "");

Call parameters:

  • key: String, unused

Return result:

  • Value, returns a value containing JSON serializable