Giter Site home page Giter Site logo

amf.js's Introduction

AMF.js

As a simple AMF (Action Message Format) library for Node.js, AMF.js is capable of encoding and decoding most AMF0 and AMF3 types. Simply hook the AMFEncoder or AMFDecoder up to a stream and it will be able to read or write to/from the stream.

Installation

npm install [--save-dev] amfjs

Usage

  • Encoding
var amfjs = require("amfjs")
var encoder = new amfjs.AMFEncoder(someKindOfWritableStream)
encoder.writeObject(10, amfjs.AMF0) //Write as AMF0
encoder.writeObject(10, amfjs.AMF3) //Write as AMF3
  • Decoding
var amfjs = require("amfjs")
var decoder = new amfjs.AMFDecoder(someKindOfReadableStream)
var value = decoder.decode(amfjs.AMF0) //Decode an AMF0 object
var value = decoder.decode(amfjs.AMF3) //Decode an AMF3 object
  • Encoding custom objects
    Simply extend the Serializable class and call writeObject with an instance of your class. Any fields in the serializable not starting with __ will automatically be encoded:
class MySerializable extends Serializable
  constructor: ->
    super "name.of.the.serializable"
  • Custom Externalizables
    Simply extend the Externalizable class and register it in the decoder to allow for the custom encoding of objects. The write method will be called whenever an Externalizable needs to be encoded and the this value will be set to the encoder. The static read method will be called whenever an object with the Externizable's class is found. As with write, while invoking read the this value is set to the decoder.
class MyExternalizable extends Externalizable
  constructor: ->
    super "name.of.the.externalizable"
  write: ->
    //Do some writing stuff
    @write 0x10
  @read: ->
    //Do some reading stuff and return the read object
    @readByte()
    return new MyExternalizable()
    
//Register the externalizable
var amfjs = require("amfjs")
amfjs.AMFDecoder.register("name.of.the.externalizable", MyExternalizable, amfjs.AMF0) //Or AMF3  

amf.js's People

Contributors

molenzwiebel avatar

Watchers

James Cloos 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.