Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

bytearray-node

3.3.0 • Public • Published

ByteArray-node

npm version

A Node.js implementation of the Actionscript 3 ByteArray supporting AMF0/AMF3.

Installation

  • Tools for Native Modules installed in Node.js setup
  • npm install bytearray-node

API (please see this)

Usage example

const ByteArray = require('bytearray-node')
 
const ba = new ByteArray()
 
ba.writeByte(1)
ba.writeShort(5)
 
ba.position = 0
 
console.log(ba.readByte()) // 1
console.log(ba.readShort()) // 5

AMF3 IExternalizable example

const ByteArray = require('bytearray-node')
const IExternalizable = require('bytearray-node/enums/IExternalizable')
 
class Person extends IExternalizable {
  constructor(name, age) {
    super()
 
    this.name = name
    this.age = age
  }
 
  writeExternal(ba) {
    ba.writeUTF(this.name)
    ba.writeByte(this.age)
  }
 
  readExternal(ba) {
    this.name = ba.readUTF()
    this.age = ba.readByte()
  }
}
 
ByteArray.registerClassAlias('src.person', Person)
 
const ba = new ByteArray()
 
ba.writeObject(new Person('Daan', 18))
 
ba.position = 0
 
console.log(ba.readObject()) // Person { name: 'Daan', age: 18 }

Install

npm i bytearray-node

DownloadsWeekly Downloads

27

Version

3.3.0

License

MIT

Unpacked Size

70.2 kB

Total Files

16

Last publish

Collaborators

  • avatar