简体   繁体   English

编解码器 - 方法太大

[英]scodec - Method too large

Have a sealed trait DataTag and its subtypes (86 case classes).具有密封特征 DataTag 及其子类型(86 个案例类)。 After upgrade project to scala 2.12, scodec-core 1.11.8 and scodec-bits 1.1.27, compilation fail with将项目升级到 scala 2.12、codec-core 1.11.8 和 codec-bits 1.1.27 后,编译失败

[error] Method too large: protocol/Payload/BasePacket$.tagCodec ()Lscodec/Codec;

The error is called by this method:此方法调用错误:

implicit def tagCodec: Codec[DataTag] = Codec.coproduct[DataTag].auto

Is there an alternative way to generate codec with a large number of subtypes?有没有替代方法来生成具有大量子类型的编解码器?

I tried to use the "key based discriminators" example ( https://github.com/scodec/scodec/blob/series/1.11.x/unitTests/src/test/scala/scodec/examples/CoproductsExample.scala ), but the result is the same.我尝试使用“基于密钥的鉴别器”示例( https://github.com/scodec/scodec/blob/series/1.11.x/unitTests/src/test/scala/scodec/examples/CoproductsExample.scala ),但是结果是一样的。

PS: I made an issue on github( https://github.com/scodec/scodec/issues/324 ), but no one has answered it yet. PS:我在github( https://github.com/scodec/scodec/issues/324 )上发了一个问题,但是还没有人回答。

Problem solved.问题解决了。 Codec wrote, specifying all codecs from subtypes сompanion objects through .typecase(discriminator, codec) .编解码器编写,通过.typecase(discriminator, codec)指定来自子类型和对象的所有编.typecase(discriminator, codec) This is ugly, but works.这很丑陋,但有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM