binary-serializer.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { FieldInstance } from '../enums';
  2. import { SerializedType } from '../types/serialized-type';
  3. import { Buffer } from 'buffer/';
  4. /**
  5. * Bytes list is a collection of buffer objects
  6. */
  7. declare class BytesList {
  8. private bytesArray;
  9. /**
  10. * Get the total number of bytes in the BytesList
  11. *
  12. * @return the number of bytes
  13. */
  14. getLength(): number;
  15. /**
  16. * Put bytes in the BytesList
  17. *
  18. * @param bytesArg A Buffer
  19. * @return this BytesList
  20. */
  21. put(bytesArg: Buffer): BytesList;
  22. /**
  23. * Write this BytesList to the back of another bytes list
  24. *
  25. * @param list The BytesList to write to
  26. */
  27. toBytesSink(list: BytesList): void;
  28. toBytes(): Buffer;
  29. toHex(): string;
  30. }
  31. /**
  32. * BinarySerializer is used to write fields and values to buffers
  33. */
  34. declare class BinarySerializer {
  35. private sink;
  36. constructor(sink: BytesList);
  37. /**
  38. * Write a value to this BinarySerializer
  39. *
  40. * @param value a SerializedType value
  41. */
  42. write(value: SerializedType): void;
  43. /**
  44. * Write bytes to this BinarySerializer
  45. *
  46. * @param bytes the bytes to write
  47. */
  48. put(bytes: Buffer): void;
  49. /**
  50. * Write a value of a given type to this BinarySerializer
  51. *
  52. * @param type the type to write
  53. * @param value a value of that type
  54. */
  55. writeType(type: typeof SerializedType, value: SerializedType): void;
  56. /**
  57. * Write BytesList to this BinarySerializer
  58. *
  59. * @param bl BytesList to write to BinarySerializer
  60. */
  61. writeBytesList(bl: BytesList): void;
  62. /**
  63. * Calculate the header of Variable Length encoded bytes
  64. *
  65. * @param length the length of the bytes
  66. */
  67. private encodeVariableLength;
  68. /**
  69. * Write field and value to BinarySerializer
  70. *
  71. * @param field field to write to BinarySerializer
  72. * @param value value to write to BinarySerializer
  73. */
  74. writeFieldAndValue(field: FieldInstance, value: SerializedType, isUnlModifyWorkaround?: boolean): void;
  75. /**
  76. * Write a variable length encoded value to the BinarySerializer
  77. *
  78. * @param value length encoded value to write to BytesList
  79. */
  80. writeLengthEncoded(value: SerializedType, isUnlModifyWorkaround?: boolean): void;
  81. }
  82. export { BytesList, BinarySerializer };