Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create CaseMapCodecs with recursive case classes #7

Open
shogun656 opened this issue Jul 23, 2018 · 0 comments
Open

How to create CaseMapCodecs with recursive case classes #7

shogun656 opened this issue Jul 23, 2018 · 0 comments

Comments

@shogun656
Copy link

shogun656 commented Jul 23, 2018

I have two case classes, one being recursive while the other references the recursive case class.

case class InitFunction(
  id: String,
  timestamp: Long,
  tree: Function
)

case class Function(
  name: String,
  path: String,
  callees: Option[List[Function]]
)

This was how I was planning to create codecs for these case classes:

    val factory = new PackerUnpackerFactory {
      def packer: MsgOutBuffer = MsgOutBuffer.create()
      def unpacker(bytes: Array[Byte]) = MsgInBuffer(bytes)
    }

    val mapCodec = CaseMapCodec.string(factory)

    implicit lazy val codec: MsgpackCodec[PythonFunction] = mapCodec.codec(PythonFunction.apply _, PythonFunction.unapply _)("name", "path", "callees")

    implicit val initCodec: MsgpackCodec[PythonInitFunction] = mapCodec.codec(PythonInitFunction.apply _, PythonInitFunction.unapply _)("id", "timestamp", "tree")

but I was getting a java.lang.StackOverflowError from the lazy codec constantly calling itself. Is there a correct way to unpack recursive case classes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant