Object Message
base message object
Message objects are compatible withmqEach module can be used to build a custom message processing system, the creation method:
1
2var mq = require("mq");
var m = new mq.Message();
inheritance relationship
Constructor
Message
message object constructor
1new Message();
constant
TEXT
Specify message type 1, which represents a text type
1const Message.TEXT = 1;
BINARY
Specify message type 2, representing a binary type
1const Message.BINARY = 2;
member attribute
value
String, the basic content of the message
1String Message.value;
params
NArray, the basic parameters of the message
1readonly NArray Message.params;
type
Integer, message type
1Integer Message.type;
data
Value, the data of the query message, this attribute will return different data according to the content-type, when it is text, it will return the text, which isjsonreturn whenjson, otherwise return binary
1readonly Value Message.data;
body
SeekableStream, a stream object containing the message data part
1SeekableStream Message.body;
length
Long, the length of the data part of the message
1readonly Long Message.length;
stream
Stream, the stream object when querying the message readFrom
1readonly Stream Message.stream;
lastError
String, query and set message processing last error
1String Message.lastError;
member function
read
Read data of specified size from the stream, this method is an alias of the corresponding method of body
1Buffer Message.read(Integer bytes = -1) async;
Call parameters:
- bytes: Integer, specify the amount of data to read, the default is to read data blocks of random size, the size of the read data 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 remaining data from the stream, this method is an alias of the corresponding method of body
1Buffer 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
Write the given data, this method is an alias of the corresponding method of body
1Message.write(Buffer data) async;
Call parameters:
- data:Buffer, given the data to be written
json
Write the given data in JSON encoding
1Value 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
1Value Message.json();
return result:
- Value, returns the parsed result
pack
bymsgpackEncode writes the given data
1Value Message.pack(Value data);
Call parameters:
- data: Value, given the data to write
return result:
- Value, this method will not return data
bymsgpackEncode the data in the parsed message
1Value Message.pack();
return result:
- Value, returns the parsed result
end
Set the current message processing to end,ChainProcessor does not continue subsequent transactions
1Message.end();
isEnded
Query whether the current message is over
1Boolean Message.isEnded();
return result:
- Boolean, return true when finished
clear
Clear the content of the message
1Message.clear();
sendTo
send a formatted message to the given stream object
1Message.sendTo(Stream stm) async;
Call parameters:
- stm:Stream, specifies the stream object that receives the formatted message
readFrom
Reads a formatted message from the given cached stream object, and parses the populated object
1Message.readFrom(Stream stm) async;
Call parameters:
- stm:Stream, specifies the stream object for reading formatted messages
toString
Return the string representation of the object, generally return "[Native Object]", the object can be reimplemented according to its own characteristics
1String Message.toString();
return result:
- String, returns a string representation of the object
toJSON
Returns the JSON format representation of the object, generally returns a collection of readable properties defined by the object
1Value Message.toJSON(String key = "");
Call parameters:
- key: String, not used
return result:
- Value, which returns a JSON-serializable value