~ehmry/nim-tkrzw

a78e1ce9f5780547ebdea3f8655b3961652d9152 — Emery Hemingway 2 years ago 81abfb1
StringView madness
2 files changed, 5 insertions(+), 4 deletions(-)

M src/tkrzw.nim
M tkrzw.nimble
M src/tkrzw.nim => src/tkrzw.nim +4 -3
@@ 73,6 73,7 @@ proc toStringView*(s: string): StringView {.inline.} =
proc toStringView*(buf: openarray[byte]): StringView {.inline.} =
  if buf.len == 0: toStringView(nil, 0)
  else: toStringView(unsafeAddr buf[0], buf.len)
proc toStringView*(sv: StringView): StringView {.inline.} = sv

type Status {.importcpp: "tkrzw::Status".} = object
proc IsOK(st: Status): bool {.importcpp: "#.IsOK()".}


@@ 150,9 151,9 @@ proc close*(dbm: DBM) =

proc get*(dbm; key: StringView; buf: pointer; len: Natural): bool =
  var src: CppString
  result = IsOK dbm.Get(key, addr src)
  result = result and (len == src.len.int)
  if result: copyMem(buf, src.data, len)
  if IsOK dbm.Get(key, addr src):
    result = len == src.len.int
    if result: copyMem(buf, src.data, len)

proc get*[A,B](dbm; key: A; dst: var B): bool =
  var src: CppString

M tkrzw.nimble => tkrzw.nimble +1 -1
@@ 1,6 1,6 @@
# Package

version = "20220910"
version = "20220922"
author        = "Emery Hemingway"
description   = "Wrapper of the Tkrzw key-value database library"
license       = "Apache-2.0"