Changeset 78bbe4c in rtems-tools for rtemstoolkit/rld-buffer.h
- Timestamp:
- Aug 16, 2017, 8:09:59 AM (2 years ago)
- Branches:
- master
- Children:
- f2bb439
- Parents:
- 0ea1c27
- git-author:
- Chris Johns <chrisj@…> (08/16/17 08:09:59)
- git-committer:
- Chris Johns <chrisj@…> (08/16/17 08:18:35)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtemstoolkit/rld-buffer.h
r0ea1c27 r78bbe4c 60 60 ~buffer (); 61 61 62 /* 63 * Return true if the byte order is little-endian. 64 */ 65 bool little_endian () const { 66 return le; 67 } 68 62 69 /** 63 70 * Clear the buffer reseting the level to zero. … … 149 156 uint8_t bytes[sizeof (T)]; 150 157 T v = value; 151 int b = sizeof (T) - 1; 152 while (b >= 0) 153 { 154 bytes[b--] = (uint8_t) v; 155 v >>= 8; 158 if (buf.little_endian ()) 159 { 160 size_t b = sizeof (T); 161 while (b != 0) 162 { 163 bytes[--b] = (uint8_t) v; 164 v >>= 8; 165 } 166 } 167 else 168 { 169 size_t b = 0; 170 while (b < sizeof (T)) 171 { 172 bytes[b++] = (uint8_t) v; 173 v >>= 8; 174 } 156 175 } 157 176 buf.write (bytes, sizeof (T)); … … 165 184 { 166 185 uint8_t bytes[sizeof (T)]; 167 int b = sizeof (T) - 1; 168 buf.read (bytes, sizeof(T)); 186 buf.read (bytes, sizeof (T)); 169 187 value = 0; 170 while (b >= 0) 171 { 172 value <<= 8; 173 value |= (T) bytes[b--]; 188 if (buf.little_endian ()) 189 { 190 size_t b = sizeof (T); 191 while (b != 0) 192 { 193 value <<= 8; 194 value |= (T) bytes[--b]; 195 } 196 } 197 else 198 { 199 size_t b = 0; 200 while (b < sizeof (T)) 201 { 202 value <<= 8; 203 value |= (T) bytes[b++]; 204 } 174 205 } 175 206 }
Note: See TracChangeset
for help on using the changeset viewer.