Avro 类型 
纯 Java 脚本执行 阿芙罗 规格。 。 。 .
特征
- 快速而紧凑的连载! 通常比JSON快 更小的编码.
- 所有阿芙罗的善良和更多: 类型推论, (中文(简体) ), 计划 演变,, , , , , , , , .
- 支助 序列化任意 JavaScript 对象。 。 。 .
- 无选择 64位整数相容性。 。 。 .
安装
$ npm install @avro/types
@avro/types 与所有版本兼容 节点.js 自此以来 0.11。 。 。 .
实例
在节点.js模块内,或使用浏览器进行:
const {Type} = require('@avro/types');
-
编码并解码一个已知计划值 :
const type = Type.forSchema({ type: 'record', fields: [ {name: 'kind', type: {type: 'enum', symbols: ['CAT', 'DOG']}}, {name: 'name', type: 'string'} ] }); const buf = type.toBuffer({kind: 'CAT', name: 'Albert'}); // Encoded buffer. const val = type.fromBuffer(buf); // = {kind: 'CAT', name: 'Albert'} -
推断一个值的计数和编码类似值:
const type = Type.forValue({ city: 'Cambridge', zipCodes: ['02138', '02139'], visits: 2 }); // We can use `type` to encode any values with the same structure: const bufs = [ type.toBuffer({city: 'Seattle', zipCodes: ['98101'], visits: 3}), type.toBuffer({city: 'NYC', zipCodes: [], visits: 0}) ];