Field.js 716 B

1234567891011121314151617181920212223242526272829303132
  1. var Types = require('../constants/types');
  2. module.exports = Field;
  3. function Field(options) {
  4. options = options || {};
  5. this.parser = options.parser;
  6. this.db = options.packet.db;
  7. this.table = options.packet.table;
  8. this.name = options.packet.name;
  9. this.type = typeToString(options.packet.type);
  10. this.length = options.packet.length;
  11. }
  12. Field.prototype.string = function () {
  13. return this.parser.parseLengthCodedString();
  14. };
  15. Field.prototype.buffer = function () {
  16. return this.parser.parseLengthCodedBuffer();
  17. };
  18. Field.prototype.geometry = function () {
  19. return this.parser.parseGeometryValue();
  20. };
  21. function typeToString(t) {
  22. for (var k in Types) {
  23. if (Types[k] == t) return k;
  24. }
  25. }