168a9c94013b686172dc1d3f938396301a58a113
[anna.git] / Unsigned32.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 // Local
10 #include <anna/diameter/codec/basetypes/Unsigned32.hpp>
11
12
13 //------------------------------------------------------------------------------
14 //------------------------------------------------------ Unsigned32::codeBasic()
15 //------------------------------------------------------------------------------
16 void anna::diameter::codec::basetypes::Unsigned32::codeBasic(char* buffer, int &size) throw(anna::RuntimeException) {
17   buffer[0] = (char)(a_value >> 24);
18   buffer[1] = (char)(a_value >> 16);
19   buffer[2] = (char)(a_value >> 8);
20   buffer[3] = (char)a_value;
21   size = getSize();
22 }
23
24
25 //------------------------------------------------------------------------------
26 //--------------------------------------------- Unsigned32::setPrintableString()
27 //------------------------------------------------------------------------------
28 void anna::diameter::codec::basetypes::Unsigned32::setPrintableString(const char * printableString) throw(anna::RuntimeException) {
29   setValue(atoi(printableString));
30 }
31
32
33 //------------------------------------------------------------------------------
34 //--------------------------------------------------------- Unsigned32::decode()
35 //------------------------------------------------------------------------------
36 void anna::diameter::codec::basetypes::Unsigned32::decode(const char* buffer, const int size) throw(anna::RuntimeException) {
37   if(!buffer)
38     throw anna::RuntimeException("Unsigned32::decode | Null Buffer provided", ANNA_FILE_LOCATION);
39
40   if(size != 4)
41     throw anna::RuntimeException("Unsigned32::decode | Buffer length must be 4 bytes", ANNA_FILE_LOCATION);
42
43   a_value = (((U32)buffer[0] << 24) & 0xFF000000) +
44             (((U32)buffer[1] << 16) & 0x00FF0000) +
45             (((U32)buffer[2] << 8)  & 0x0000FF00) +
46             ((U32)buffer[3]         & 0x000000FF);
47 }
48