amp-message
High level AMP Message
implementation for manipulating, encoding and decoding AMP messages.
Installation
$ npm install amp-message
Example
Encoding a message:
var Message = require('xcraft-amp-message');
var msg = new Message;
console.log(msg.toBuffer());
msg.push('foo');
msg.push('bar');
msg.push('baz');
console.log(msg.toBuffer());
msg.push({ foo: 'bar' });
console.log(msg.toBuffer());
msg.push(Buffer.from('image data'));
console.log(msg.toBuffer());
Decoding a message:
var Message = require('..');
var msg = new Message;
msg.push('foo')
msg.push({ hello: 'world' })
msg.push(Buffer.from('hello'))
var other = new Message(msg.toBuffer());
console.log(other.shift());
console.log(other.shift());
console.log(other.shift());
API
Message
Initialize an empty message.
Message(buffer)
Decode the buffer
AMP message to populate the Message
.
Message(args)
Initialize a messeage populated with args
.
License
MIT