Steam IO endianess for Read and Write attributes

I’m finally getting around to relearning Ada and I’m working with the networking example displayed here: Ada Programming/Libraries/GNAT.Sockets - Wikibooks, open books for an open world

I’m writing the equivalent programs in Plan 9 C with matching food.h, client.c, and server.c with the goal being that server.adb can be called by client.c and vice versa.

My issue is the endianess over the wire is that of the machine, little endian. I much prefer network order as that is what I am used to working with.

How can I switch the endianess of the ‘Read, ’Write or ‘Input and ‘Output attributes? Or is this a case where I need to write my own attribute routines?

Yes, you must implement these attributes yourself. In Ada you can override these for user-defined types.

P.S. For communication purpose stream attributes have limited use. Normally you would rather deal with network packets stored in a buffer, usually in a Stream_Element_Array. It is more efficient and more flexible because you need to validate the input. Then network and data representation protocols specify endianness and general encoding. Then some protocols use chunking, you don’t want to accumulate all serialized object in the memory before for a stream attribute or use a secondary task with a pipeline stream.

You have many options. One of them, to specify representation, see

1 Like

Thank you for the information. I have been reading through your Simple Components libraries; lots of good stuff in there as I work in industrial automation. I was studying your Modbus library as I have written a very light weight client and server library myself in c.

It has been a while since using the pure oop approach so it takes a while to understand the the entirety of the jungle. Would you say this is your preferred approach or are there other approaches using Ada?