Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

binary-parser.d.ts 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { FieldInstance } from '../enums';
  2. import { SerializedType } from '../types/serialized-type';
  3. import { Buffer } from 'buffer/';
  4. /**
  5. * BinaryParser is used to compute fields and values from a HexString
  6. */
  7. declare class BinaryParser {
  8. private bytes;
  9. /**
  10. * Initialize bytes to a hex string
  11. *
  12. * @param hexBytes a hex string
  13. */
  14. constructor(hexBytes: string);
  15. /**
  16. * Peek the first byte of the BinaryParser
  17. *
  18. * @returns The first byte of the BinaryParser
  19. */
  20. peek(): number;
  21. /**
  22. * Consume the first n bytes of the BinaryParser
  23. *
  24. * @param n the number of bytes to skip
  25. */
  26. skip(n: number): void;
  27. /**
  28. * read the first n bytes from the BinaryParser
  29. *
  30. * @param n The number of bytes to read
  31. * @return The bytes
  32. */
  33. read(n: number): Buffer;
  34. /**
  35. * Read an integer of given size
  36. *
  37. * @param n The number of bytes to read
  38. * @return The number represented by those bytes
  39. */
  40. readUIntN(n: number): number;
  41. readUInt8(): number;
  42. readUInt16(): number;
  43. readUInt32(): number;
  44. size(): number;
  45. end(customEnd?: number): boolean;
  46. /**
  47. * Reads variable length encoded bytes
  48. *
  49. * @return The variable length bytes
  50. */
  51. readVariableLength(): Buffer;
  52. /**
  53. * Reads the length of the variable length encoded bytes
  54. *
  55. * @return The length of the variable length encoded bytes
  56. */
  57. readVariableLengthLength(): number;
  58. /**
  59. * Reads the field ordinal from the BinaryParser
  60. *
  61. * @return Field ordinal
  62. */
  63. readFieldOrdinal(): number;
  64. /**
  65. * Read the field from the BinaryParser
  66. *
  67. * @return The field represented by the bytes at the head of the BinaryParser
  68. */
  69. readField(): FieldInstance;
  70. /**
  71. * Read a given type from the BinaryParser
  72. *
  73. * @param type The type that you want to read from the BinaryParser
  74. * @return The instance of that type read from the BinaryParser
  75. */
  76. readType(type: typeof SerializedType): SerializedType;
  77. /**
  78. * Get the type associated with a given field
  79. *
  80. * @param field The field that you wan to get the type of
  81. * @return The type associated with the given field
  82. */
  83. typeForField(field: FieldInstance): typeof SerializedType;
  84. /**
  85. * Read value of the type specified by field from the BinaryParser
  86. *
  87. * @param field The field that you want to get the associated value for
  88. * @return The value associated with the given field
  89. */
  90. readFieldValue(field: FieldInstance): SerializedType;
  91. /**
  92. * Get the next field and value from the BinaryParser
  93. *
  94. * @return The field and value
  95. */
  96. readFieldAndValue(): [FieldInstance, SerializedType];
  97. }
  98. export { BinaryParser };