jangko / msgpack4nim

MessagePack serializer/deserializer implementation for Nim / msgpack.org[Nim]
http://msgpack.org/
119 stars 21 forks source link

Error: undeclared field: 'data' #30

Closed pb-cdunn closed 4 years ago

pb-cdunn commented 5 years ago

After I update to the latest msgpack4nim (720f8bb):

falcon/rr_hctg_track.nim(414, 19) template/generic instantiation from here
../repos/msgpack4nim/msgpack4nim.nim(1069, 53) template/generic instantiation from here
../repos/msgpack4nim/msgpack4collection.nim(38, 4) template/generic instantiation from here
../repos/msgpack4nim/msgpack4nim.nim(681, 6) template/generic instantiation from here
../repos/msgpack4nim/msgpack4nim.nim(727, 32) Error: undeclared field: 'data'
          s.pack_type undistinct(field)
                                 ^
  3 import "../msgpack4nim/msgpack4nim.nim"
  4 import "../msgpack4nim/msgpack4collection.nim"
...
413   var msgss = msgpack4nim.MsgStream.init() #you can pass some buffer capacity here https://github.com/jangko/msgpack4nim/is    sues/18
414   msgpack4nim.pack(msgss, rtn)
415   var ss = streams.newFileStream(fn_rtn, system.fmWrite)
416   defer: ss.close()
417   ss.write(msgss.data)

What do I need to change?

pb-cdunn commented 5 years ago

You seem to have a circular dependency between 4nim and 4collection. Is that the problem? Is that interacting with the "" style of import (which I need)?

24

pb-cdunn commented 5 years ago

If I skip the "4collection" import, I get this shorter stack-trace:

falcon/rr_hctg_track.nim(414, 19) template/generic instantiation from here
../repos/msgpack4nim/msgpack4nim.nim(1069, 53) template/generic instantiation from here
../repos/msgpack4nim/msgpack4nim.nim(727, 32) Error: undeclared field: 'data'
          s.pack_type undistinct(field)
                                 ^
pb-cdunn commented 5 years ago

I am serializing (i.e. "packing") myprioritytable:

 29 type
 30   # A ctg is a 9-char array.
 31   str9 = array[0..9, char]
 33   mytuple = tuple[score: int, rid: str9] #overlap_len, q_id
 35   myprioritytable = tables.Table[string, binaryheap.Heap[mytuple]]
pb-cdunn commented 5 years ago
-import "../msgpack4nim/msgpack4nim.nim"
-import "../msgpack4nim/msgpack4collection.nim"
+import ../msgpack4nim/msgpack4nim
+import ../msgpack4nim/msgpack4collection

Same problem that way.

pb-cdunn commented 5 years ago

I cannot use nimble because I have restrictions from my company. I use a directory structure like this:

src/fc_consensus.nim
src/falcon/rr_hctg_track.nim
src/msgpack4nim/
src/nim-heap/

src/fc_consensus.nim:

from falcon/rr_hctg_track import nil

src/falcon/rr_hctg_track.nim:

import ../msgpack4nim/msgpack4nim
import ../msgpack4nim/msgpack4collection
from "../nim-heap/binaryheap" import nil
jangko commented 5 years ago

change var MsgStream to MsgStream of unpack_type and pack_type

proc unpack_type*(ss: msgpack4nim.MsgStream, x: var str9) =
  var str: string
  msgpack4nim.unpack(ss, str)
  copyMem(addr x[0], addr str[0], 9)

proc pack_type*(ss: msgpack4nim.MsgStream, x: str9) =
  let str: string = tostring(x)
  msgpack4nim.pack(ss, str)

proc pack_type*(ss: msgpack4nim.MsgStream, x: binaryheap.Heap[mytuple]) =
  let xseq: seq[mytuple] = sequtils.toSeq(binaryheap.items(x)) # unsorted
  msgpack4nim.pack(ss, xseq)
jangko commented 5 years ago

your nim version and some of your submodules seems outdated. but hey, we are using nim. nim evolves quickly. :)

pb-cdunn commented 5 years ago

0.19.4. Should I use devel?

jangko commented 5 years ago

0.19.0 is enough