GithubHelp home page GithubHelp logo

node-amp-message's Introduction

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('amp-message');

var msg = new Message;

console.log(msg.toBuffer());
// => <Buffer 10>

msg.push('foo');
msg.push('bar');
msg.push('baz');
console.log(msg.toBuffer());
// => <Buffer 13 00 05 73 3a 66 6f 6f 00 05 73 3a 62 61 72 00 05 73 3a 62 61 7a>

msg.push({ foo: 'bar' });
console.log(msg.toBuffer());
// => <Buffer 14 00 05 73 3a 66 6f 6f 00 05 73 3a 62 61 72 00 05 73 3a 62 61 7a 00 0f 6a 3a 7b 22 66 6f 6f 22 3a 22 62 61 72 22 7d>

msg.push(new Buffer('image data'));
console.log(msg.toBuffer());
// => <Buffer 15 00 05 73 3a 66 6f 6f 00 05 73 3a 62 61 72 00 05 73 3a 62 61 7a 00 0f 6a 3a 7b 22 66 6f 6f 22 3a 22 62 61 72 22 7d 00 0a 69 6d 61 67 65 20 64 61 74 ... >

Decoding a message:

var Message = require('..');

var msg = new Message;

msg.push('foo')
msg.push({ hello: 'world' })
msg.push(new Buffer('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

node-amp-message's People

Contributors

tj avatar a0viedo avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.