94fe9598dd6609de4de8f8279de87ab571d53232
[ctsim.git] / include / byteorder.h
1 #ifndef NETORDER_H
2 #define NETORDER_H
3
4 #include <iostream>
5
6 /* netorder.cpp */
7
8 bool read_nint16 (kuint16 *n, int fd);
9 bool write_nint16 (kuint16 const *n, int fd);
10 bool read_nint32 (kuint32 *n, int fd);
11 bool write_nint32 (kuint32 const *n, int fd);
12 bool read_nfloat32 (float *f, int fd);
13 bool write_nfloat32 (float const *f, int fd);
14 bool read_nfloat64 (double *d, int fd);
15 bool write_nfloat64 (double const *d, int fd);
16 void  ConvertNetworkOrder (void* buffer, size_t bytes);
17 void  ConvertReverseNetworkOrder (void* buffer, size_t bytes);
18
19 class inetorderstream : public istream {
20  public:
21     inetorderstream& readInt16 (kuint16& n);
22     inetorderstream& readInt32 (kuint32& n);
23     inetorderstream& readFloat32 (kfloat32& n);
24     inetorderstream& readFloat64 (kfloat64& n);
25 };
26
27 class onetorderstream : public ostream {
28  public:
29     onetorderstream& writeInt16 (kuint16 n);
30     onetorderstream& writeInt32 (kuint32 n);
31     onetorderstream& writeFloat32 (kfloat32 n);
32     onetorderstream& writeFloat64 (kfloat64 n);
33 };
34
35 void read_rnint16 (kuint16& n, istream istr);
36 void write_rnint16 (kuint16 n, ostream ostr);
37 void read_rnint32 (kuint32& n, istream istr);
38 void write_rnint32 (kuint32 n, ostream ostr);
39 void read_rnfloat32 (kfloat32& n, istream istr);
40 void write_rnfloat32 (kfloat32 n, ostream ostr);
41 void read_rnfloat64 (kfloat64& n, istream istr);
42 void write_rnfloat64 (kfloat64 n, ostream ostr);
43
44 #endif