Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 751567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:40:53+00:00 2026-05-14T14:40:53+00:00

I need to parse some simple binary Files. (The files contains n entries which

  • 0

I need to parse some simple binary Files. (The files contains n entries which consists of several signed/unsigned Integers of different sizes etc.)

In the moment i do the parsing “by hand”. Does somebody know a library which helps to do this type of parsing?

Edit: “By hand” means that i get the Data Byte by Byte sort it in to the correct Order and convert it to an Int/Byte etc. Also some of the Data is unsigned.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:40:54+00:00Added an answer on May 14, 2026 at 2:40 pm

    I’ve used the sbinary library before and it’s very nice. The documentation is a little sparse but I would suggest first looking at the old wiki page as that gives you a starting point. Then check out the test specifications, as that gives you some very nice examples.

    The primary benefit of sbinary is that it gives you a way to describe the wire format of each object as a Format object. You can then encapsulate those formatted types in a higher level Format object and Scala does all the heavy lifting of looking up that type as long as you’ve included it in the current scope as an implicit object.

    As I say below, I’d now recommend people use scodec instead of sbinary. As an example of how to use scodec, I’ll implement how to read a binary representation in memory of the following C struct:

    struct ST
    {
       long long ll; // @ 0
       int i;        // @ 8
       short s;      // @ 12
       char ch1;     // @ 14
       char ch2;     // @ 15
    } ST;
    

    A matching Scala case class would be:

    case class ST(ll: Long, i: Int, s: Short, ch1: String, ch2: String)
    

    I’m making things a bit easier for myself by just saying we’re storing Strings instead of Chars and I’ll say that they are UTF-8 characters in the struct. I’m also not dealing with endian details or the actual size of the long and int types on this architecture and just assuming that they are 64 and 32 respectively.

    Scodec parsers generally use combinators to build higher level parsers from lower level ones. So for below, we’ll define a parser which combines a 8 byte value, a 4 byte value, a 2 byte value, a 1 byte value and one more 1 byte value. The return of this combination is a Tuple codec:

    val myCodec: Codec[Long ~ Int ~ Short ~ String ~ String] = 
      int64 ~ int32 ~ short16 ~ fixedSizeBits(8L, utf8) ~ fixedSizeBits(8L, utf8)
    

    We can then transform this into the ST case class by calling the xmap function on it which takes two functions, one to turn the Tuple codec into the destination type and another function to take the destination type and turn it into the Tuple form:

    val stCodec: Codec[ST] = myCodec.xmap[ST]({case ll ~ i ~ s ~ ch1 ~ ch2 => ST(ll, i, s, ch1, ch2)}, st => st.ll ~ st.i ~ st.s ~ st.ch1 ~ st.ch2)
    

    Now, you can use the codec like so:

    stCodec.encode(ST(1L, 2, 3.shortValue, "H", "I"))
    res0: scodec.Attempt[scodec.bits.BitVector] = Successful(BitVector(128 bits, 0x00000000000000010000000200034849))
    
    res0.flatMap(stCodec.decode)
    => res1: scodec.Attempt[scodec.DecodeResult[ST]] = Successful(DecodeResult(ST(1,2,3,H,I),BitVector(empty)))
    

    I’d encourage you to look at the Scaladocs and not at the Guide as there’s much more detail in the Scaladocs. The guide is a good start at the very basics but it doesn’t get into the composition part much but the Scaladocs cover that pretty well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 523k
  • Answers 523k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It turns out that the 'Main nib file base name'… May 16, 2026 at 9:40 pm
  • Editorial Team
    Editorial Team added an answer Javascript arrays are special objects that have an automatically set… May 16, 2026 at 9:40 pm
  • Editorial Team
    Editorial Team added an answer Remove the Pragma: no-cache header. This header prevents IE from… May 16, 2026 at 9:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

i need to parse some paths of an SVG file, they are simple lines.
Recently, I try to use the boost::spirit::qi binary endian parser to parse some binary
In need in my application to fetch remote HTML document and parse some parts
I was hoping to implement a simple XMPP server in Java. What I need
I'm trying to parse some JSON using the JSon.Net library. The documentation seems a
I'm looking for some guidance/code-snippets/tutorial on passing some simple data into my app. I
I'm hoping for some insight from someone better experienced than I for creating a
what are the advantages and disadvantages of the following libraries? PHP Simple HTML DOM
I'm looking for a standard markup language to transmit addresses (locations). I really need
I need to maintain a connection between a server and multiple clients so that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.