diff --git a/src/nimhdf5/copyflat.nim b/src/nimhdf5/copyflat.nim index fe896d9..a2d68a3 100644 --- a/src/nimhdf5/copyflat.nim +++ b/src/nimhdf5/copyflat.nim @@ -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 @@ -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) @@ -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)