Skip to content

Commit

Permalink
[serialize] correctly handle distinct types in copyflat
Browse files Browse the repository at this point in the history
  • Loading branch information
Vindaar committed May 21, 2024
1 parent f1a3f9f commit 7dfaa08
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/nimhdf5/copyflat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ proc copyFlat*[T: SimpleTypes](buf: var Buffer, x: T) =
var target = buf.data +% buf.offsetOf
target.copyMem(address(x), size)

proc copyFlat*[T: distinct](buf: var Buffer, x: T) =
let size = calcSize(x)
var target = buf.data +% buf.offsetOf
target.copyMem(address(x), size)

proc copyFlat*[T; N: static int](buf: var Buffer, x: array[N, T]) =
let size = calcSize(x)
var target = buf.data +% buf.offsetOf
Expand All @@ -103,6 +98,9 @@ proc copyFlat*[T](buf: var Buffer, x: seq[T]) =
# copy child address
buf.copyFlat((csize_t(x.len), cast[uint](child.data))) # `hvl_t` like data structure

proc copyFlat*[T: distinct](buf: var Buffer, x: T) =
buf.copyFlat(distinctBase(x))

import ./type_utils
proc copyFlat*[T: object | tuple](buf: var Buffer, x: T) =
var tmp: genCompatibleTuple(T, replaceVlen = true)
Expand Down Expand Up @@ -138,6 +136,9 @@ proc fromFlat*[T: SimpleTypes | pointer](x: var T, buf: Buffer) =
var source = buf.data +% buf.offsetOf
copyMem(addr(x), source, size)

proc fromFlat*[T: distinct](x: var T, buf: Buffer) =
fromFlat(distinctBase(x), buf)

## XXX: `fromFlat` for fixed length arrays!
proc fromFlat*[T: array](x: var T, buf: Buffer) =
let size = calcSize(x)
Expand Down

0 comments on commit 7dfaa08

Please sign in to comment.