Skip to content

Commit

Permalink
0.2.4 ptr UncheckedArray[uint8] binny reading
Browse files Browse the repository at this point in the history
  • Loading branch information
guzba committed Feb 13, 2022
1 parent c3c4a40 commit 7d239fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flatty.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.2.3"
version = "0.2.4"
author = "Andre von Houck"
description = "Flatty - tools and serializer for plain flat binary files."
license = "MIT"
Expand Down
30 changes: 30 additions & 0 deletions src/flatty/binny.nim
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@ func addStr*(s: var seq[uint8], v: string) {.inline.} =
func readStr*(s: seq[uint8], i: int, v: int): string {.inline.} =
cast[string](s[i ..< min(s.len, i + v)])

func readUint8*(s: ptr UncheckedArray[uint8], i: int): uint8 {.inline.} =
cast[uint8](s[i])

func readUint16*(s: ptr UncheckedArray[uint8], i: int): uint16 {.inline.} =
result = cast[ptr uint16](s[i].addr)[]

func readUint32*(s: ptr UncheckedArray[uint8], i: int): uint32 {.inline.} =
result = cast[ptr uint32](s[i].addr)[]

func readUint64*(s: ptr UncheckedArray[uint8], i: int): uint64 {.inline.} =
result = cast[ptr uint64](s[i].addr)[]

func readInt8*(s: ptr UncheckedArray[uint8], i: int): int8 {.inline.} =
cast[int8](s.readUint8(i))

func readInt16*(s: ptr UncheckedArray[uint8], i: int): int16 {.inline.} =
cast[int16](s.readUint16(i))

func readInt32*(s: ptr UncheckedArray[uint8], i: int): int32 {.inline.} =
cast[int32](s.readUint32(i))

func readInt64*(s: ptr UncheckedArray[uint8], i: int): int64 {.inline.} =
cast[int64](s.readUint64(i))

func readFloat32*(s: ptr UncheckedArray[uint8], i: int): float32 {.inline.} =
cast[float32](s.readUint32(i))

func readFloat64*(s: ptr UncheckedArray[uint8], i: int): float64 {.inline.} =
cast[float64](s.readUint64(i))

func swap*(v: uint8): uint8 {.inline.} =
v

Expand Down

0 comments on commit 7d239fb

Please sign in to comment.