I have a simple sample code taken from the documentation:
test.js
var avsc = require('avsc');
var type = avsc.parse('./schemas/pet.avsc')
var pet = {kind: 'CAT', name: 'my cat'}
var buf = type.toBuffer(pet); // Serialized object.
var obj = type.fromBuffer(buf); // {kind: 'CAT', name: 'Albert'}
console.log(buf)
console.dir(obj)
And a simple avsc file in schemas/peg.avsc
{
"name": "Pet",
"type": "record",
"fields": [
{"name": "kind", "type": {"name": "Kind", "type": "enum", "symbols": ["CAT", "DOG"]}},
{"name": "name", "type": "string"}
]
}
on ubuntu, running node test.js I get:
cromestant@tweb-lab-web-01:~/test$ node test.js
< Buffer 00 0c 6d 79 20 63 61 74>
{ kind: 'CAT', name: 'my cat' }
however con El Capitรกn:
Charles-Romestant-MacBook-Air:activity cromestant$ node test.js
/Users/cromestant/Codigos/node/activity/test.js:4
var buf = type.toBuffer(pet); // Serialized object.
^
TypeError: type.toBuffer is not a function
at Object. (/Users/cromestant/Codigos/node/activity/test.js:4:16)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:138:18)
at node.js:974:3
important version & stuff
Charles-Romestant-MacBook-Air:activity cromestant$ node --version
v5.1.1
Charles-Romestant-MacBook-Air:tigo-activity cromestant$ cat node_modules/avsc/package.json
{
"_args": [
[
"avsc@^1.0.2",
"/Users/cromestant/Codigos/node/tigo-activity"
]
],
"_from": "avsc@>=1.0.2 <2.0.0",
"_id": "[email protected]",
"_inCache": true,
"_installable": true,
"_location": "/avsc",
"_nodeVersion": "4.1.0",
"_npmUser": {
"email": "[email protected]",
"name": "mtth"
},
"_npmVersion": "2.14.3",
"_phantomChildren": {},
"_requested": {
"name": "avsc",
"raw": "avsc@^1.0.2",
"rawSpec": "^1.0.2",
"scope": null,
"spec": ">=1.0.2 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/avsc/-/avsc-1.0.2.tgz",
"_shasum": "aa9369896e0d1ea5e63fd74b3857df21fc61f86a",
"_shrinkwrap": null,
"_spec": "avsc@^1.0.2",
"_where": "/Users/cromestant/Codigos/node/tigo-activity",
"author": {
"name": "Matthieu Monsch"
},
"bugs": {
"url": "https://github.com/mtth/avsc/issues"
},
"dependencies": {},
"description": "A serialization API to make you smile",
"devDependencies": {
"coveralls": "^2.11.4",
"istanbul": "^0.3.19",
"mocha": "^2.3.2"
},
"directories": {},
"dist": {
"shasum": "aa9369896e0d1ea5e63fd74b3857df21fc61f86a",
"tarball": "http://registry.npmjs.org/avsc/-/avsc-1.0.2.tgz"
},
"engines": {
"node": ">=0.11"
},
"files": [
"lib"
],
"gitHead": "75c09c68b5dc5a0510a5ebede5ce80f00e3e6aec",
"homepage": "https://github.com/mtth/avsc",
"keywords": [
"avro",
"avsc",
"decoding",
"encoding",
"json",
"schema"
],
"license": "MIT",
"main": "./lib",
"maintainers": [
{
"name": "mtth",
"email": "[email protected]"
}
],
"name": "avsc",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git://github.com/mtth/avsc.git"
},
"scripts": {
"bench": "python benchmarks >timings.json",
"cover": "istanbul cover _mocha -- --ui tdd",
"test": "mocha --ui tdd"
},
"version": "1.0.2"
}