0d5083ba39a0cf4d36ba38ac08384caaedcacfca
[anna.git] / Unsigned64.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/Unsigned64.hpp>
11
12
13 //------------------------------------------------------------------------------
14 //------------------------------------------------------ Unsigned64::codeBasic()
15 //------------------------------------------------------------------------------
16 void anna::diameter::codec::basetypes::Unsigned64::codeBasic(char* buffer, int &size) throw(anna::RuntimeException) {
17   buffer[0] = (char)(a_value >> 56);
18   buffer[1] = (char)(a_value >> 48);
19   buffer[2] = (char)(a_value >> 40);
20   buffer[3] = (char)(a_value >> 32);
21   buffer[4] = (char)(a_value >> 24);
22   buffer[5] = (char)(a_value >> 16);
23   buffer[6] = (char)(a_value >> 8);
24   buffer[7] = (char)a_value;
25   size = getSize();
26 }
27
28
29 //------------------------------------------------------------------------------
30 //--------------------------------------------- Unsigned64::setPrintableString()
31 //------------------------------------------------------------------------------
32 void anna::diameter::codec::basetypes::Unsigned64::setPrintableString(const char * printableString) throw(anna::RuntimeException) {
33   setValue(atoll(printableString));
34 }
35
36
37 //------------------------------------------------------------------------------
38 //--------------------------------------------------------- Unsigned64::decode()
39 //------------------------------------------------------------------------------
40 void anna::diameter::codec::basetypes::Unsigned64::decode(const char* buffer, const int size) throw(anna::RuntimeException) {
41   if(!buffer)
42     throw anna::RuntimeException("Unsigned64::decode | Null Buffer provided", ANNA_FILE_LOCATION);
43
44   if(size != 8)
45     throw anna::RuntimeException("Unsigned64::decode | Buffer length must be 8 bytes", ANNA_FILE_LOCATION);
46
47   a_value = (((U64)buffer[0] << 56) & 0xFF00000000000000LL) +    // LL es para compatibilizar con linux gcc 3.3.2
48             (((U64)buffer[1] << 48) & 0x00FF000000000000LL) +
49             (((U64)buffer[2] << 40) & 0x0000FF0000000000LL) +
50             (((U64)buffer[3] << 32) & 0x000000FF00000000LL) +
51             (((U64)buffer[4] << 24) & 0x00000000FF000000LL) +
52             (((U64)buffer[5] << 16) & 0x0000000000FF0000LL) +
53             (((U64)buffer[6] << 8)  & 0x000000000000FF00LL) +
54             ((U64)buffer[7]         & 0x00000000000000FFLL);
55 }
56