Questions tagged [scodec]
scodec is a pure functional Scala library that allows encoding/decoding of binary data.
35
questions
0
votes
1
answer
113
views
scodec - Method too large
Have a sealed trait DataTag and its subtypes (86 case classes). After upgrade project to scala 2.12, scodec-core 1.11.8 and scodec-bits 1.1.27, compilation fail with
[error] Method too large: protocol/...
0
votes
0
answers
94
views
shapeless.~?>.witness[Nothing, Nothing, T](shapeless.~?>.rel[Nothing, Nothing])when upgrading scala version from 2 to 3
I'm upgrading my scala project from version 2 to 3.
This is my build.sbt for version scala version 2
scalaVersion := "2.13.5"
version := "1.0.0"
libraryDependencies += ...
0
votes
1
answer
86
views
Scodec - Reading in a fixed-length String
I'm writing a file parser that is reading an existing file format that incorporates fixed length, 0 padded strings.
So, for example I've got two case classes for binary structures within the file I ...
0
votes
1
answer
76
views
Could not prove that Long :: String :: Option[Long] :: Option[java.util.UUID] :: shapeless.HNil can be converted to/from SimpleMp4BoxHeader
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 ...
0
votes
1
answer
123
views
How to install scodec library in scala/sbt?
I have been asked by my developers to have scodec libraries installed on a linux server and I'm lost as I can't find any documentation that points about installing the scodec library!
1
vote
1
answer
170
views
How to write scodec codec for Collection Map
I have below case class
case class Foo(code: Int, msg: String, headers: Map[String,String] = Map.empty)
Below is the code that I've tried so far -
import scodec._
import scodec.codecs._
implicit ...
1
vote
1
answer
92
views
How to dynamically provide N codecs to process fields as a VectorCodec for a record of binary fields that do not contain size bytes
Considering this function in Decoder:
final def decodeCollect[F[_], A](dec: Decoder[A], limit: Option[Int])(buffer: BitVector)(implicit cbf: Factory[A, F[A]]): Attempt[DecodeResult[F[A]]] = {
What ...
2
votes
0
answers
48
views
How can I Throw error inside scodec Attempt?
I have the following code to decode a BitVector. How can I remove the exception and throw a failure?
def decode(b: BitVector) = {
if (!applies) {
Attempt.successful(DecodeResult.apply(null, b)...
0
votes
1
answer
147
views
How to ignore Codec after using it to limit size bytes
I would create a model for the KMIP protocols that works with TTLV encoding (Tag, Type, Length, Value)
The ttlv function is "high level" and accepts the tag, the type and the codec of the value.
...
0
votes
1
answer
108
views
How do I make Codec[Option[T]] that is driven by prefix?
I'm trying to implement codec for PSQL COPY BINARY format. Details are at Tuple section
Int, Bool, String fields are encoded as <4 byte length><var length payload>
I implemented them ...
0
votes
1
answer
44
views
Scodec - Literal binary unsigned integer string with length specified as input?
raw beginner with scodec here. Does scodec provide a nice way to convert an unsigned decimal integer value to a literal binary unsigned integer string with length specified as an input, left-padding ...
1
vote
2
answers
122
views
Scodec: Using vectorOfN with a vlong field
I am playing around with the Bitcoin blockchain to learn Scala and some useful libraries.
Currently I am trying to decode and encode Blocks with SCodec and my problem is that the vectorOfN function ...
0
votes
2
answers
121
views
codec for a Vector[N] where N determines the end of the vector
I am using Scodec to decode Flac metadata. One of the specifications is that there is a Header and a Block that can be repeated a number of times together. Header has a flag which indicates if the ...
3
votes
0
answers
165
views
How do I define value of discriminator for coproduct codecs?
Could you please explain how coproducts really work? Here is my code
sealed trait ArdbData
case class ArdbDataString(value: String) extends ArdbData
case class ArdbDataLong(value: Long) extends ...
3
votes
1
answer
106
views
Transforming a Hlist[F[A]] into F[B] where case class B has aligned types with A
Note: I am learning shapeless, so please ask for clarification if I miss any details.
Background:
I am building an encoding/decoding solution for fixed-length format while practising Shapeless. The ...
2
votes
1
answer
173
views
Missing scodec.Codec[Command] implicit because of class with non-value fields
I'm trying to use discriminators in existing project and something is wrong with my classes I guess.
Consider this scodec example. If I change TurnLeft and its codec to
sealed class TurnLeft(degrees:...
2
votes
2
answers
317
views
Records are discriminated hierarchically
I have to implement some proprietary binary format and wanted to do this with scodec. However, I cannot find a concise solution.
The format is as follows: A file consists of multiple Records, where ...
2
votes
2
answers
156
views
Encoding vector length field not adjacent to the vector
I have the following structure I like to encode.
I'm aware that I can encode a vector with vector() if the size field is directly in front of the vector data. But here the field encoding the vector ...
2
votes
1
answer
152
views
Efficiently pack a list of Longs in Scodec representation
I have a case class with a List[Long] attribute that I am converting into a token using the Scodec library. Right now, it is not efficient (space-wise) because I am using this codec:
listOfN(uint16, ...
2
votes
1
answer
96
views
Can't find scodec-akka published to Maven Central
I need to convert the ByteString received by AKKA Streams to BitVector int order to decode it by scodec.
The library is said to be be published to Maven central under org.scodec %% scodec-akka as ...
1
vote
0
answers
160
views
Byte align BitVector after decoding misaligned value
I've come across an interesting problem with scodec. I have a peculiar encoding scheme that requires a stream byte alignment when the current bit pointer mod 8 is not zero (not aligned to the nearest ...
1
vote
1
answer
127
views
Schema of codec is part of the data stream
I'm currently evaluating if scodec is the right tool for my task. I have to parse an InputStream (file or network) which is structured the following:
| Header - FieldDesc1 - FieldDesc2 - ... \...
5
votes
1
answer
299
views
Flatten an arbitrarily nested codec?
As a new user of SCodec, there is quite a learning curve. I've hit a snag that I can't seem to solve despite reading the source and docs.
I want to be able to define popular codecs as functions like ...
6
votes
1
answer
647
views
Scodec combinators: Header contains magic number that is used to discriminate types
I am looking for a way to approach a protocol like the following example:
case class Request(bodyType: Int, foo: Int, bar: Int, body: RequestBody)
sealed trait RequestBody
case class Read(key: ...
3
votes
1
answer
321
views
scodec variableSizePrefixBytes transformation
I have a use case where a header can contain 7 bytes plus an optional 0-15 Bytes of information where the size information is in the lower 4 bits of the 5th Byte
so the format is:
4 bytes | 4 bits | ...
2
votes
1
answer
387
views
define `Codec` for recursive data structure
I have a class looking like this,
case class Foo ( bar: Int, foos: Vector[Foo] )
to define a Codec[Foo], I tried this,
def fc = shapeless.Lazy((int32 ~~ vector(fc)).widenOpt( (Foo.apply _).tupled, ...
2
votes
1
answer
583
views
Scodec: Coproducts could not find implicit value for parameter auto: scodec.codecs.CoproductBuilderAuto
I am trying to define an Scodec coproduct codec for communicating with an EELink GPS.
Here is the code:
import scodec.Codec
import scodec.bits.ByteVector
import scodec.codecs._
trait Message
object ...
3
votes
1
answer
723
views
Scodec: How to create a codec for an optional byte
I must create a codec for a message that has the following specification
The message length is indicated by a byte of which the least significant bit is an extension flag that, when set indicates that ...
3
votes
2
answers
1k
views
Mapping C structs in Scala
What is the best way to read and write C-styled byte stuctures in Scala, like this:
struct account {
int id;
char[10] data1;
char[10] data2;
float ...
2
votes
1
answer
452
views
Using nested case classes with scodec
When defining my messages with scodec, I would like to use nested case classes. For example:
case class Foo(x: Int, y: Int)
object Foo {
def baseCodec = uint16 :: uint16
def codec = baseCodec.as[...
2
votes
1
answer
141
views
.dropUnit on .hlist'ed codecs doesnt seem to work
For "big" codecs, the Scala phase typer takes forever (we're talking minutes) when creating a codec directly from HLists and applying .dropUnits
( ignore(6) ::
uint(2) ::
uint(30) ::
int(4) ::
...
4
votes
1
answer
567
views
Scodec - Coproducts could not find implicit value for parameter auto: scodec.codecs.CoproductBuilderAuto
On version:
"org.typelevel" %% "scodec-core" % "1.5.0"
I'm trying to use coproduct functionality, as shown in the test case demonstrate fixing the codec to a known subtype.
I keep getting the ...
2
votes
1
answer
633
views
scodec decode/encode split length field
I am using scodec: https://github.com/scodec/scodec to decode/encode a binary protocol.
I am struggling with a part of the spec where a "length" field is split into two parts by a "moreflag". The ...
3
votes
1
answer
283
views
scodec ignore last value in codec conversion between hlist and case class
I'm just starting out with typelevel's "scodec" library: https://github.com/scodec/scodec
I've found that I've been using the following function a lot:
/**
* When called on a `Codec[L]` for some `L ...
6
votes
1
answer
273
views
Shapeless: Inversion of filterNot on an HList
I'm trying to write a combinator for the scodec library that converts a Codec[K] in to a Codec[L] where K is an HList and L is the equivalent HList with all Unit elements removed.
Implementing ...