Remove dynamic exceptions
[anna.git] / source / diameter / helpers / tme / codectypes / Unsigned16.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/helpers/tme/codectypes/Unsigned16.hpp>
11
12
13 //------------------------------------------------------------------------------
14 //---------------------------------------------------- Unsigned16::updateBasic()
15 //------------------------------------------------------------------------------
16 void anna::diameter::helpers::tme::codectypes::Unsigned16::updateBasic() noexcept(false) {
17   std::string result;
18   result += (char)(a_value >> 8);
19   result += (char)a_value;
20   OctetString::setValue(result);
21 }
22
23
24 //------------------------------------------------------------------------------
25 //--------------------------------------------- Unsigned16::setPrintableString()
26 //------------------------------------------------------------------------------
27 void anna::diameter::helpers::tme::codectypes::Unsigned16::setPrintableString(const char * printableString) noexcept(false) {
28   setValue(atoi(printableString));
29 }
30
31
32 //------------------------------------------------------------------------------
33 //--------------------------------------------------------- Unsigned16::decode()
34 //------------------------------------------------------------------------------
35 void anna::diameter::helpers::tme::codectypes::Unsigned16::decode(const char* buffer, const int size) noexcept(false) {
36   if(!buffer)
37     throw anna::RuntimeException("Unsigned16::decode | Null Buffer provided", ANNA_FILE_LOCATION);
38
39   if(size != 2)
40     throw anna::RuntimeException("Unsigned16::decode | Buffer length must be 2 bytes", ANNA_FILE_LOCATION);
41
42   a_value = (((U16)buffer[0] << 8)  & 0xFF00) +
43             ((U16)buffer[1]         & 0x00FF);
44   // Base class decode()
45   OctetString::decode(buffer, size);
46 }