t23749.nim 866 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. discard """
  2. action: compile
  3. """
  4. {.pragma: callback, gcsafe, raises: [].}
  5. type
  6. DataProc* = proc(val: openArray[byte]) {.callback.}
  7. GetProc = proc (db: RootRef, key: openArray[byte], onData: DataProc): bool {.nimcall, callback.}
  8. KvStoreRef* = ref object
  9. obj: RootRef
  10. getProc: GetProc
  11. template get(dbParam: KvStoreRef, key: openArray[byte], onData: untyped): bool =
  12. let db = dbParam
  13. db.getProc(db.obj, key, onData)
  14. func decode(input: openArray[byte], maxSize = 128): seq[byte] =
  15. @[]
  16. proc getSnappySSZ(db: KvStoreRef, key: openArray[byte]): string =
  17. var status = "not found"
  18. proc decode(data: openArray[byte]) =
  19. status =
  20. if true: "found"
  21. else: "corrupted"
  22. discard db.get(key, decode)
  23. status
  24. var ksr: KvStoreRef
  25. var k = [byte(1), 2, 3, 4, 5]
  26. proc foo(): string =
  27. getSnappySSZ(ksr, toOpenArray(k, 1, 3))
  28. echo foo()