common.d.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /// <reference types="node" />
  2. /**
  3. * BufferVisitor is a visit tool to manipulate buffer.
  4. */
  5. export declare class BufferVisitor {
  6. start: number;
  7. end: number;
  8. readonly buf: Buffer;
  9. constructor(buf: Buffer, start?: number, end?: number);
  10. /**
  11. * return the underlying buffer length
  12. */
  13. readonly length: number;
  14. /**
  15. * Reset visitor' start and end value.
  16. * @param start
  17. * @param end
  18. */
  19. reset(start?: number, end?: number): this;
  20. /**
  21. * consume some bytes.
  22. * @param steps steps to walk
  23. */
  24. walk(steps: number): this;
  25. /**
  26. * The buffer should have remaining the "steps" of bytes to consume,
  27. * otherwise it will throw an error with given message.
  28. * @param steps steps to consume.
  29. * @param message message to throw.
  30. */
  31. mustHas(steps: number, message?: string): this;
  32. /**
  33. * Check the remaining bytes with bufferVisitor.mustHas method and then walk.
  34. * @param steps steps to consume.
  35. * @param message message to throw.
  36. */
  37. mustWalk(steps: number, message?: string): this;
  38. }