Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38028
| Path | csiph.com!news.mixmin.net!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Kiwi User <martin@mydomain.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: bit package |
| Date | Sat, 17 Feb 2018 12:40:35 +0000 (UTC) |
| Organization | albasani.net |
| Lines | 55 |
| Message-ID | <p697s2$4go$1@news.albasani.net> (permalink) |
| References | <bebd1080-35be-485d-ac9d-f7e2d4b361da@googlegroups.com> <p696af$tiv$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.albasani.net Y1YHa9mnfoYoPUwJMY7g4rYjPJ/mh6Kg1ysf4tSAqy3sN+nIDv/0uop9v1sqbHlkXslt2G6IMgecAzRPMpKtxw== |
| NNTP-Posting-Date | Sat, 17 Feb 2018 12:40:35 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="i9kSHXnkuqFDntLg/fP/NWqMIP/JL+Cmg03i3NeVK0eOKvtdkkurozSGbhgH0MoYbHd84O8MDenhquLwvdBGLfIFEhasMM7JfsDcr6phqj7ZXi+KjVNhjUjsF8ssJlmK"; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Pan/0.144 (Time is the enemy; 28ab3ba git.gnome.org/pan2) |
| Cancel-Lock | sha1:1eW/qdu1OU11zKfpumGFU4KXanI= |
| Xref | csiph.com comp.lang.java.programmer:38028 |
Show key headers only | View raw
On Sat, 17 Feb 2018 07:14:05 -0500, Eric Sosman wrote:
> On 2/17/2018 3:33 AM, Philipp Kraus wrote:
>> Hello,
>>
>> I'm building a network communication protocol for
>> hardware-communication, so I need a bit representation of my dara like
>> a C struct:
>>
>> struct {
>> unint8 field1; unint16 field2;
>> ...
>> }
>
> Aside: This approach won't always work, not even in C. (Think
> padding bytes, endianness, ...)
>
>> On my Java classes I have got int, long, ... so how can I create such
>> bit structures?
>> My first try is to use a BitSet and convert all datatypes manually, but
>> is there a better possibility to create such bit sequences. I need a
>> sending and receiving structure. I'm working with Java 9.
>>
>> I the best case I create an object like
>>
>> BitObject l_obj = new BitObject( 8, 16, 8, 32 );
>> l_object.set(0, mybyte)
>> l_object.set(1, myshort)
>> l_object.set(2, mybyte)
>> l_object.set(3, myint)
>>
>> and on reseiving
>>
>> BitObject l_obj = new BitObject( mybytearray_from_socket, 8, 16, 8, 32
>> );
>> l_obj.get(0)
>> l_obj.get(1)
>> ...
>>
>> Can you suggest a library or anything for doing this?
>
> It's not clear to me precisely what you're trying to do (the
> semantics of l_object.set() are not obvious), but I think you might find
> java.nio.ByteBuffer a good starting place.
The BitSet class looks fairly straight forward and is explicitly little
endian.
I can't comment on BitObject because I'm using OpenJava 8, the current
version for RedHat Fedora 27. This doesn't provide a BitObject class.
--
Martin | martin at
Gregorie | gregorie dot org
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
bit package Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2018-02-17 00:33 -0800
Re: bit package Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-02-17 07:14 -0500
Re: bit package Kiwi User <martin@mydomain.invalid> - 2018-02-17 12:40 +0000
Re: bit package Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-02-17 08:16 -0500
Re: bit package Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2018-02-17 07:51 -0800
Re: bit package Arne Vajhøj <arne@vajhoej.dk> - 2018-02-17 11:11 -0500
Re: bit package Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2018-02-17 11:41 -0800
Re: bit package Arne Vajhøj <arne@vajhoej.dk> - 2018-02-17 14:55 -0500
Re: bit package Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-02-17 11:12 -0500
Re: bit package Arne Vajhøj <arne@vajhoej.dk> - 2018-02-17 12:27 -0500
Re: bit package Daniele Futtorovic <da.futt.news@laposte.net> - 2018-02-17 20:55 +0100
Re: bit package Robert Klemme <shortcutter@googlemail.com> - 2018-02-17 16:23 +0100
Re: bit package Arne Vajhøj <arne@vajhoej.dk> - 2018-02-17 10:25 -0500
csiph-web