i am a starter and working on MP4 file decoding.when i code as the following, it reports "Could not prove that Long :: String :: Option[Long] :: Option[java.util.UUID] :: shapeless.HNil can be converted to/from SimpleMp4BoxHeader". how can i fix this problem?

sealed trait Mp4BoxHeader {
  def size: Int
  def btype: String
}

case class SimpleMp4BoxHeader(size: Int, btype: String) extends Mp4BoxHeader

object SimpleMp4BoxHeader {
  // val scodec = uint32 ~ ascii32

  def apply(size: Int, btype: String): SimpleMp4BoxHeader = SimpleMp4BoxHeader(size, btype)

  implicit def codec: Codec[SimpleMp4BoxHeader] = "simpleMp4BoxHeader" | { ("size" | uint32 ) :: ("btype" | ascii32) }.as[SimpleMp4BoxHeader]

}
1

There are 1 best solutions below

2
On BEST ANSWER

It's because of uint32 is Codec for Long type but your size is should be Int, take a look at scodec.codecs package object:

/**
 * Codec for 16-bit unsigned big-endian integers.
 * @group numbers
 */
val uint16: Codec[Int] = new IntCodec(16, false, ByteOrdering.BigEndian)

/**
 * Codec for 24-bit unsigned big-endian integers.
 * @group numbers
 */
val uint24: Codec[Int] = new IntCodec(24, false, ByteOrdering.BigEndian)

/**
 * Codec for 32-bit unsigned big-endian integers.
 * @group numbers
 */
val uint32: Codec[Long] = new LongCodec(32, false, ByteOrdering.BigEndian)

there are some codecs you should choose most compatible Codec for Int (uint24 or uint16), replace uint32 to chosen and your code will compile.