Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/flatty.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
## Convert any Nim objects, numbers, strings, refs to and from binary format.
import
std/[tables, typetraits, sets],
flatty/objvar

when defined(js):
import flatty/jsbinny
else:
import flatty/binny
import flatty/objvar, tables, typetraits, sets, sequtils

type SomeTable*[K, V] = Table[K, V] | OrderedTable[K, V]
type SomeSet[A] = set[A] | HashSet[A] | OrderedSet[A]
Expand Down Expand Up @@ -43,7 +46,7 @@ proc toFlatty*(s: var string, x: char) =
proc fromFlatty*(s: string, i: var int, x: var char) =
x = s.readUint8(i).char
i += 1

# Numbers
proc toFlatty*(s: var string, x: uint8) = s.addUint8(x)
proc toFlatty*(s: var string, x: int8) = s.addInt8(x)
Expand Down
4 changes: 2 additions & 2 deletions src/flatty/binlisting.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Takes bin-listing in ASCII format and turns them into real binary.
import parseutils, strutils
import std/[parseutils, strutils]

proc decodeBinListing*(text: string): string =

## Takes bin-listing in ASCII format and turns them into real binary.
for line in text.split("\n"):
let line = line.strip()
if line == "": continue
Expand Down
2 changes: 1 addition & 1 deletion src/flatty/encode.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unicode
import std/unicode

proc maybeSwap(u: uint16, swap: bool): uint16 =
## Swaps from big endian to little endian if swap is true.
Expand Down
4 changes: 3 additions & 1 deletion src/flatty/hashy.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Hash functions based on flatty, hash any nested object.

import flatty, hashes
import
std/hashes,
flatty

export Hash

Expand Down
4 changes: 3 additions & 1 deletion src/flatty/hashy2.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Hash functions based on flatty, hash any nested object.

import flatty/objvar, typetraits
import
std/typetraits,
flatty/objvar

{.push overflowChecks: off.}

Expand Down
4 changes: 1 addition & 3 deletions src/flatty/hexprint.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import strutils
import std/strutils

when defined(js):

proc hexPrint*(buf: string): string =
## Prints a string in hex format of the old DOS debug program.
## Useful for looking at binary dumps.
Expand Down Expand Up @@ -41,7 +40,6 @@ when defined(js):
result.add("\n")

else:

proc hexPrint*(p: ptr uint8, len: int, startAddress = 0): string =
## Prints a string in hex format of the old DOS debug program.
## Useful for looking at binary dumps.
Expand Down
2 changes: 1 addition & 1 deletion src/flatty/objvar.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import macros
import std/macros

proc hasKind(node: NimNode, kind: NimNodeKind): bool =
for c in node.children:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_flatty.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import flatty, intsets, json, tables, sets, flatty/hexprint
import
std/[intsets, json, tables, sets],
flatty

# Test booleans.
doAssert true.toFlatty.fromFlatty(bool) == true
Expand Down
Loading