faster
This commit is contained in:
parent
268e653b05
commit
e67f257479
1 changed files with 14 additions and 6 deletions
|
@ -110,15 +110,23 @@ proc readUint8(state: var DecoderState): uint8 =
|
||||||
|
|
||||||
proc readUint16be(state: var DecoderState): uint16 =
|
proc readUint16be(state: var DecoderState): uint16 =
|
||||||
## Reads uint16 big-endian from the input stream.
|
## Reads uint16 big-endian from the input stream.
|
||||||
(state.readUint8().uint16 shl 8) or state.readUint8()
|
if state.pos + 2 > state.len:
|
||||||
|
failInvalid()
|
||||||
|
result =
|
||||||
|
(state.buffer[state.pos].uint16 shl 8) or
|
||||||
|
state.buffer[state.pos + 1]
|
||||||
|
state.pos += 2
|
||||||
|
|
||||||
proc readUint32be(state: var DecoderState): uint32 =
|
proc readUint32be(state: var DecoderState): uint32 =
|
||||||
## Reads uint32 big-endian from the input stream.
|
## Reads uint32 big-endian from the input stream.
|
||||||
return
|
if state.pos + 4 > state.len:
|
||||||
(state.readUint8().uint32 shl 24) or
|
failInvalid()
|
||||||
(state.readUint8().uint32 shl 16) or
|
result =
|
||||||
(state.readUint8().uint32 shl 8) or
|
(state.buffer[state.pos + 0].uint32 shl 24) or
|
||||||
state.readUint8().uint32
|
(state.buffer[state.pos + 1].uint32 shl 16) or
|
||||||
|
(state.buffer[state.pos + 2].uint32 shl 8) or
|
||||||
|
state.buffer[state.pos + 3]
|
||||||
|
state.pos += 4
|
||||||
|
|
||||||
proc readStr(state: var DecoderState, n: int): string =
|
proc readStr(state: var DecoderState, n: int): string =
|
||||||
## Reads n number of bytes as a string.
|
## Reads n number of bytes as a string.
|
||||||
|
|
Loading…
Reference in a new issue