Libamf
Action Message Format library for node.js.
Install / Use
/learn @Pyrodash/LibamfREADME
libamf
An Action Message Format library for node.js.
Usage
Parser/Serializer
const libamf = require('libamf');
const data = libamf.serialize(5, libamf.ENCODING.AMF3);
const int = libamf.deserialize(data, libamf.ENCODING.AMF3);
Server
const {Server, Service} = require('libamf');
class PizzaService extends Service {
constructor() {
super('pizza');
this.register('order', 'handleOrder');
this.register('cancelOrder', this.cancelOrder.bind(this));
this.register('asyncMethod', 'asyncMethod');
}
handleOrder(pizza, message) {
message.respond({ status: 1, message: pizza.type + ' pizza ordered!'});
}
cancelOrder(pizza, message) {
const id = pizza.id;
return { status: 1, message: 'Order ' + id + ' has been cancelled successfully.'};
}
asyncMethod(message) {
return new Promise((resolve, reject) => {
resolve('this will be sent as a response');
});
}
}
const server = new Server();
// You can also just do this
server.on('data', packet => {
console.log(packet);
});
server.registerService(pizzaService);
server.listen(8080, () => {
console.log('Listening on port 8080');
});
You can stop services from enforcing the -service suffix to the name by doing:
libamf.Service.ForceSuffix = false;
You can also allow any service method to be used without registration by doing:
libamf.Service.RequireRegistration = false;
If you wish to return other values in your service methods, you can disable responding with return values using:
libamf.Service.ReturnResponses = false;
To write whole numbers as integers, use this:
libamf.AMF3.AssumeIntegers = true;
To disable the default homepage, use:
libamf.Server.DisableDefaultHome = true;
Client
const {Client} = require('libamf');
const client = new Client();
client.connect('http://localhost:8080/');
client.call('pizza-service.order', { type: 'cheese' }).then(res => {
console.log(res);
});
SOL
const fs = require('fs');
const libamf = require('libamf');
fs.readFile('path/to/file.sol', (err, data) => {
console.log(libamf.SOL.read(data));
const newObj = new libamf.SOL.LSO({
allow: false,
always: false,
allowsecure: false,
alwayssecure: false,
klimit: 100,
hstsEnabled: false,
hstsMaxAge: '0',
hstsIncSubDomain: false,
hstsStartTime: '0'
});
newObj.filename = 'domain/settings';
newObj.version = 0;
console.log(newObj.write());
});
Supported types
AMF0
|Type|Read|Write|Note| |--|--|--|--| |Null|✔|✔| |Undefined|✔|✔| |String|✔|✔| |Long String|✔|✔| |Number|✔|✔| |Boolean|✔|✔| |Reference|✔|✔| |Strict Array|✔|✔| |ECMA Array|✔|✔| |Typed Object|✔|✔| |Date|✔|✔| |AVMPLUS|✔|✔| |XML|✔|✔|
AMF3
|Type|Read|Write|Note| |--|--|--|--| |Undefined|✔|✔| |Null|✔|✔| |String|✔|✔| |Double|✔|✔| |Integer|✔|✔| |Boolean|✔|✔| |Date|✔|✔| |Array|✔|✔| |Dictionary|✔|✔| |Vector|✔|✔| |Byte Array|✔|✔| |Custom object|✔|✔| |XML|✔|✔|
TODO
- Better documentation
- Better tests
- Better TODO
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
