Object Message
Basic message object
The Message object is compatible with mq Each module can be used to build a custom message processing system, creating methods:
1
2var mq = require("mq");
var m = new mq.Message();
Inheritance
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, which represents a binary type
1const Message.BINARY = 2;
Member attributes
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, query the data of the message, this attribute will return different data according to the content-type, when it is text, it returns the text, which is json When returning json, Other times return to binary
1readonly Value Message.data;
body
SeekableStream, The stream object that contains the data part of the message
1SeekableStream Message.body;
length
Long, the length of the data part of the message
1readonly Long Message.length;
stream
Stream, Query the stream object when the message readFrom
1readonly Stream Message.stream;
lastError
String, query and set the last error of message processing
1String Message.lastError;
Member function
read
Read the data of the specified size from the stream, this method is the alias of the corresponding method of body
1Buffer 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, Return the data read from the stream, if there is no data to read, or the connection is interrupted, then return null
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, Return the data read from the stream, if there is no data to read, or the connection is interrupted, then return null
write
Write the given data, this method is the 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 be written
Return result:
- Value, This method will not return data
Parse the data in the message in JSON encoding
1Value Message.json();
Return result:
- Value, Return the parsed result
pack
by msgpack Encode to write the given data
1Value Message.pack(Value data);
Call parameters:
- data: Value, given the data to be written
Return result:
- Value, This method will not return data
by msgpack Encoding and parsing the data in the message
1Value Message.pack();
Return result:
- Value, Return the parsed result
end
Set the end of the current message processing,Chain The processor does not continue subsequent transactions
1Message.end();
isEnded
Query whether the current message is over
1Boolean Message.isEnded();
Return result:
- Boolean, Return true at the end
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, Specify the stream object to receive formatted messages
readFrom
Read the formatted message from the given cache stream object, and parse the filling object
1Message.readFrom(Stream stm) async;
Call parameters:
- stm: Stream, Specify the stream object for reading formatted messages
toString
Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics
1String Message.toString();
Return result:
- String, Returns the string representation of the object
toJSON
Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object
1Value Message.toJSON(String key = "");
Call parameters:
- key: String, unused
Return result:
- Value, Returns a value containing JSON serializable