Skip to content

Instantly share code, notes, and snippets.

@sqs
Created November 26, 2012 22:47
Show Gist options
  • Save sqs/4151179 to your computer and use it in GitHub Desktop.
Save sqs/4151179 to your computer and use it in GitHub Desktop.
Sample Avro JS codegen'd file
if (typeof require !== "undefined" && typeof Avro === "undefined") {
var Avro = require("../lib/validator.js").Avro;
}
/**
* autograph.model.gen.PersonId (AUTOGENERATED)
*/
if (typeof autograph === "undefined") {
var autograph = {};
}
if (!autograph.model) {
autograph.model = {};
}
if (!autograph.model.gen) {
autograph.model.gen = {};
}
autograph.model.gen.PersonId = function(data) {
this.__data = {};
if (typeof data !== "undefined") {
this.update(data);
}
};
autograph.model.gen.PersonId.schema = {"type":"record","name":"PersonId","fields":[{"name":"email","type":"string"}],"namespace":"autograph.model.gen"};
autograph.model.gen.PersonId.fieldNames = ["email"];
///////////////////
// Setters
autograph.model.gen.PersonId.prototype.update = function(data) {
if (!data || typeof data !== "object" || data instanceof Array) {
throw new TypeError("attempt to update with a non-Object: " + data);
}
for (fieldName in data) {
if (data.hasOwnProperty(fieldName)) {
if (autograph.model.gen.PersonId.fieldNames.indexOf(fieldName) === -1) {
throw new TypeError("no such field: " + fieldName);
}
this[fieldName] = data[fieldName];
}
}
};
autograph.model.gen.PersonId.prototype.toJSON = function() {
this.__avroValidate();
return this.__data;
}
Object.defineProperty(autograph.model.gen.PersonId.prototype, "email", {
get: function() {
return this.__data.email;
},
set: function(new_email) {
this.__avroValidate_email(new_email);
this.__data.email = new_email;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment