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

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

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

import scodec.bits.BitVector

/**
 * Codec that provides a constant value from decode and ignores the value to encode.
 *
 * Useful as a combinator with [[DiscriminatorCodec]].
 */
private[codecs] final class ProvideCodec[A](value: A) extends Codec[A] {
  override def sizeBound = SizeBound.exact(0)
  override def encode(a: A) = Attempt.successful(BitVector.empty)
  override def decode(bv: BitVector) = Attempt.successful(DecodeResult(value, bv))
  override def toString = s"provide($value)"
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy