序列化 / 二进制格式

//using Node.js
//npm install avsc

class Size {
    constructor(width, height) {
        this.width = width;
        this.height = height;
    }
}

class Rect {
    constructor(size) {
        this.size = size;
    }
}

let rect = new Rect(new Size(510));

//Encoding Binary Data
const avsc = require('avsc');
const type = avsc.Type.forValue(rect);
const data_b = type.toBuffer(rect);

//Decoding Binary Data
const rect2 = type.fromBuffer(data_b);
//Record

nbsp;{ size: Recordnbsp;{ width: 5, height: 10 } }
console.log("rect2 is", rect2);