All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scodec.codecs.IgnoreCodec.scala Maven / Gradle / Ivy

There is a newer version: 1.11.3
Show newest version
package scodec
package codecs

import scodec.bits.BitVector

private[codecs] final class IgnoreCodec(bits: Long) extends Codec[Unit] {

  override def sizeBound = SizeBound.exact(bits)

  override def encode(unit: Unit) =
    Attempt.successful(BitVector.low(bits))

  override def decode(buffer: BitVector) =
    buffer.acquire(bits) match {
      case Left(e) => Attempt.failure(Err.insufficientBits(bits, buffer.size))
      case Right(_) => Attempt.successful(DecodeResult((), buffer.drop(bits)))
    }

  override def toString = s"ignore($bits bits)"
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy