avro 1.8.2 (js)

5月15日发布的avro 1.8.2 已经包含了js版代码。

清华大学镜像地址:

https://mirrors.tuna.tsinghua.edu.cn/apache/avro/avro-1.8.2/js/

根据README.md,运行了一下简单的例子。

具体步骤:

1.将下载的压缩包解压

2.在package目录下,创建一个简单的文件 index.js,内容如下:

var avro = require("./lib/index");


var type = avro.parse({
    name: 'Pet',
    type: 'record',
    fields: [
      {name: 'kind', type: {name: 'Kind', type: 'enum', symbols: ['CAT', 'DOG']}},
      {name: 'name', type: 'string'}
    ]
  });
  var pet = {kind: 'CAT', name: 'Albert'};
  var buf = type.toBuffer(pet); // Serialized object.
  var obj = type.fromBuffer(buf); // {kind: 'CAT', name: 'Albert'}
  console.log(obj)
  console.log(pet)
  console.log(obj==pet)

3.打开命令行,切换到package目录,执行  node index.js

如果没有nodejs环境,需要去nodejs官网下载安装,安装好后运行node index.js可能会提示 underscore找不到,

在命令行执行 node install underscore即可。

原文地址:https://www.cnblogs.com/majianguo/p/6876297.html