1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Portable exchange of binary/packed data

Discussion in 'Embedded' started by Oliver Betz, Jul 17, 2010.

  1. Oliver Betz

    Oliver Betz Guest

    Hello All,

    refactoring a system where data is exchanged and stored in a terse
    binary format, I'm looking for abstraction methods.

    The packets consist of length, version and a version dependent
    sequence of byte and (two-byte) word values.

    The legacy version uses a set of defines with offsets and type casts
    to access the byte and word values directly in the raw byte array. Of
    course this is limited to controllers with the same endianness
    (currently that's true). Not pretty but fast.

    I'm considering a table based copy to a working structure for the
    faster hosts, but that's not possible in the resource (speed and
    memory) limited 8 bit controller.

    Besides this, it will be difficult to use the same structure
    definition for both methods, and I would dislike somewhat to to keep
    two representations in sync (manually or by an automatic converter).

    Any thoughts?

    Oliver Betz, Jul 17, 2010
    1. Advertisements

  2. Oliver Betz

    Tim Watts Guest

    I've used this for network communications (actual network and unix domain
    sockets). It's reasonably pleasant, lots of high level language libraries
    exist for various languages and it's efficient.

    To deal with the problem of "packetising" data over a stream, I wrapped the
    whole lot in SLIP.
    Tim Watts, Jul 17, 2010
    1. Advertisements

  3. Oliver Betz

    Thad Smith Guest

    I suggest adding an explicit byte order to the message specification. The
    processor can load or write the proper order. This can done, if you wish, in
    portable code that works on either endian machine.
    ASN.1 BER encoding is a reasonable standardized binary encoding technique. As
    an option, you can formally specify the message in ASN.1.
    I don't know what you mean there.
    Thad Smith, Jul 17, 2010
  4. Oliver Betz

    Oliver Betz Guest

    the byte order is specified.
    I was not clear in my question. I was looking for maintainable C code
    to abstract the access to message elements in the different targets.

    These targets range from tiny and "slow" 8 bit controllers where I
    need direct access to the elements up to 32 bit controllers with
    plenty of computing power to use indirect methods to access the
    message elements, e.g. a table.

    Direct access could be a "struct" or a bunch of defines with offsets
    and type casts. That's rather simple to maintain in code and works for
    all targets if:
    * the endianness is the same,
    * the target supports misaligned access (if the message requires for).
    And of course the "struct" method only works if the compiler (for the
    larger processors) has extensions to control the packing.
    So this method would result in some limitation on future targets.

    Larger, faster targets have enough resources to convert the message to
    and from a working structure using an abstract description of the
    message. But I'm afraid that there is no maintainable solution to have
    _one_ message description for the tiny and the abstract format, IOW I
    hade to maintain different versions of the message
    description/abstraction sources.

    Oliver Betz, Jul 21, 2010
  5. Oliver Betz


    Jul 23, 2010
    Likes Received:

    Thanks very much for this comment. It help me to think about my ideals.

    Apart from that, this link below may be useful: humanresources.hrvinet.com/systems-interview-questions
    Tks again and pls keep posting.
    Last edited: Aug 3, 2010
    jerryvn01, Jul 23, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.