FieldPacket.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. module.exports = FieldPacket;
  2. function FieldPacket(options) {
  3. options = options || {};
  4. this.catalog = options.catalog;
  5. this.db = options.db;
  6. this.table = options.table;
  7. this.orgTable = options.orgTable;
  8. this.name = options.name;
  9. this.orgName = options.orgName;
  10. this.filler1 = undefined;
  11. this.charsetNr = options.charsetNr;
  12. this.length = options.length;
  13. this.type = options.type;
  14. this.flags = options.flags;
  15. this.decimals = options.decimals;
  16. this.filler2 = undefined;
  17. this.default = options.default;
  18. this.zeroFill = options.zeroFill;
  19. }
  20. FieldPacket.prototype.parse = function(parser) {
  21. this.catalog = parser.parseLengthCodedString();
  22. this.db = parser.parseLengthCodedString();
  23. this.table = parser.parseLengthCodedString();
  24. this.orgTable = parser.parseLengthCodedString();
  25. this.name = parser.parseLengthCodedString();
  26. this.orgName = parser.parseLengthCodedString();
  27. this.filler1 = parser.parseFiller(1);
  28. this.charsetNr = parser.parseUnsignedNumber(2);
  29. this.fieldLength = parser.parseUnsignedNumber(4);
  30. this.type = parser.parseUnsignedNumber(1);
  31. this.flags = parser.parseUnsignedNumber(2);
  32. this.decimals = parser.parseUnsignedNumber(1);
  33. this.filler2 = parser.parseFiller(2);
  34. // parsed flags
  35. this.zeroFill = (this.flags & 0x0040 ? true : false);
  36. if (parser.reachedPacketEnd()) {
  37. return;
  38. }
  39. this.default = parser.parseLengthCodedNumber();
  40. };
  41. FieldPacket.prototype.write = function(writer) {
  42. writer.writeLengthCodedString(this.catalog);
  43. writer.writeLengthCodedString(this.db);
  44. writer.writeLengthCodedString(this.table);
  45. writer.writeLengthCodedString(this.orgTable);
  46. writer.writeLengthCodedString(this.name);
  47. writer.writeLengthCodedString(this.orgName);
  48. writer.writeFiller(1);
  49. writer.writeUnsignedNumber(2, this.charsetNr || 0);
  50. writer.writeUnsignedNumber(4, this.fieldLength || 0);
  51. writer.writeUnsignedNumber(1, this.type) || 0;
  52. writer.writeUnsignedNumber(2, this.flags || 0);
  53. writer.writeUnsignedNumber(1, this.decimals || 0);
  54. writer.writeFiller(2);
  55. if (this.default !== undefined) {
  56. writer.writeLengthCodedString(this.default);
  57. }
  58. };