libp2p/vbuffer

    Dark Mode
Search:
Group by:
  Source   Edit

This module implements variable buffer.

Types

VBuffer = object
  buffer*: seq[byte]
  offset*: int
  Source   Edit

Procs

proc `$`(vb: VBuffer): string {....raises: [], tags: [].}
Return hexadecimal string representation of buffer vb.   Source   Edit
proc finish(vb: var VBuffer) {....raises: [], tags: [].}
Finishes vb.   Source   Edit
proc high(vb: VBuffer): int {....raises: [], tags: [].}
Returns number of bytes left in buffer vb.   Source   Edit
proc initVBuffer(): VBuffer {....raises: [], tags: [].}
Initialize empty VBuffer.   Source   Edit
proc initVBuffer(data: openArray[byte]; offset = 0): VBuffer {....raises: [],
    tags: [].}
Initialize VBuffer with copy of data.   Source   Edit
proc initVBuffer(data: seq[byte]; offset = 0): VBuffer {....raises: [], tags: [].}
Initialize VBuffer with shallow copy of data.   Source   Edit
proc len(vb: VBuffer): int {....raises: [], tags: [].}
Returns number of bytes left in buffer vb.   Source   Edit
proc peekArray[T: char | byte](vb: var VBuffer; value: var openArray[T]): int {.
    ...raises: [].}

Peek array from buffer vb and store result to value.

This procedure will not adjust internal offset.

Returns number of bytes peeked from vb or -1 on error.

  Source   Edit
proc peekSeq[T: string | seq[byte]](vb: var VBuffer; value: var T): int {.
    ...raises: [].}

Peek length prefixed array from buffer vb and store result to value.

This procedure will not adjust internal offset.

Returns number of bytes peeked from vb or -1 on error.

  Source   Edit
proc peekVarint(vb: var VBuffer; value: var LPSomeUVarint): int {....raises: [].}

Peek unsigned integer from buffer vb and store result to value.

This procedure will not adjust internal offset.

Returns number of bytes peeked from vb or -1 on error.

  Source   Edit
proc readArray[T: char | byte](vb: var VBuffer; value: var openArray[T]): int {.
    inline, ...raises: [].}

Read array from buffer vb and store result to value.

Returns number of bytes consumed from vb or -1 on error.

  Source   Edit
proc readSeq[T: string | seq[byte]](vb: var VBuffer; value: var T): int {.
    inline, ...raises: [].}

Read length prefixed array from buffer vb and store result to value.

Returns number of bytes consumed from vb or -1 on error.

  Source   Edit
proc readVarint(vb: var VBuffer; value: var LPSomeUVarint): int {.inline,
    ...raises: [].}

Read unsigned integer from buffer vb and store result to value.

Returns number of bytes consumed from vb or -1 on error.

  Source   Edit
proc writeArray[T: byte | char](vb: var VBuffer; value: openArray[T]) {.
    ...raises: [].}
Write array value to buffer vb, value will NOT be prefixed with varint length of the array.   Source   Edit
proc writeLPVarint(vb: var VBuffer; value: LPSomeUVarint) {....raises: [].}
Write value as variable unsigned integer.   Source   Edit
proc writePBVarint(vb: var VBuffer; value: PBSomeUVarint) {....raises: [].}
Write value as variable unsigned integer.   Source   Edit
proc writeSeq[T: byte | char](vb: var VBuffer; value: openArray[T]) {....raises: [].}
Write array value to buffer vb, value will be prefixed with varint length of the array.   Source   Edit
proc writeVarint(vb: var VBuffer; value: LPSomeUVarint) {....raises: [].}
  Source   Edit

Templates

template isEmpty(vb: VBuffer): bool
Returns true if buffer vb is empty.   Source   Edit
template isEnough(vb: VBuffer; length: int): bool
Returns true if buffer vb holds at least length bytes.   Source   Edit