Working with messages.
- Source:
- See:
Example
var structs = require("bitmessage").structs;
var messages = require("bitmessage").messages;
// Simple encoding and decoding:
var vermsg = messages.version.encode({
remoteHost: "1.1.1.1",
remotePort: 8444,
});
console.log(messages.version.decode(vermsg).remoteHost); // 1.1.1.1
// Low-level encoding and decoding:
var addrPayload = messages.addr.encodePayload([
{host: "2.2.2.2", port: 28444},
]);
var addrmsg = structs.message.encode("addr", addrPayload);
var decoded = structs.message.decode(addrmsg);
console.log(decoded.command); // addr
var addr = messages.addr.decodePayload(decoded.payload);
console.log(addr.addrs[0].host); // 2.2.2.2
// Encode with empty payload:
var verackmsg = structs.message.encode("verack");
console.log(structs.message.decode(verackmsg).command); // verack
Namespaces
Methods
(static) getCommand(buf) → (nullable) {string}
Try to get command of the given encoded message. Note that this function doesn't do any validation because it is already provided by message.decode routine.
Parameters:
Name | Type | Description |
---|---|---|
buf |
Buffer | Buffer that starts with encoded message |
- Source:
Returns:
Message's command if any.
- Type
- string