Field.js 770 B

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