anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019-present Infosys Limited |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | */ |
| 6 | /****************************************************************************** |
| 7 | * |
| 8 | * This is an auto generated file. |
| 9 | * Please do not edit this file. |
| 10 | * All edits to be made through template source file |
| 11 | * <TOP-DIR/scripts/GtpV2StackCodeGen/tts/ietemplate.cpp.tt> |
| 12 | ******************************************************************************/ |
| 13 | |
| 14 | #include "ipAddressIe.h" |
| 15 | #include "dataTypeCodecUtils.h" |
| 16 | |
| 17 | IpAddressIe::IpAddressIe() |
| 18 | { |
| 19 | ieType = 74; |
| 20 | // TODO |
| 21 | |
| 22 | } |
| 23 | |
| 24 | IpAddressIe::~IpAddressIe() { |
| 25 | // TODO Auto-generated destructor stub |
| 26 | } |
| 27 | |
| 28 | bool IpAddressIe::encodeIpAddressIe(MsgBuffer &buffer, IpAddressIeData const &data) |
| 29 | { |
| 30 | if (data.ipAddressV4Present) |
| 31 | { |
| 32 | if (!(DataTypeCodecUtils::encodeIpAddressV4(buffer, data.ipAddressV4))) |
| 33 | { |
| 34 | errorStream.add((char *)"Encoding of ipAddressV4 failed\n"); |
| 35 | return false; |
| 36 | } |
| 37 | } |
| 38 | if (data.ipAddressV6Present) |
| 39 | { |
| 40 | if (!(DataTypeCodecUtils::encodeIpAddressV6(buffer, data.ipAddressV6))) |
| 41 | { |
| 42 | errorStream.add((char *)"Encoding of ipAddressV6 failed\n"); |
| 43 | return false; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | bool IpAddressIe::decodeIpAddressIe(MsgBuffer &buffer, IpAddressIeData &data, Uint16 length) |
| 51 | { |
| 52 | // TODO optimize the length checks |
| 53 | |
| 54 | Uint16 ieBoundary = buffer.getCurrentIndex() + length; |
| 55 | |
| 56 | Uint16 lengthLeft = length; |
| 57 | |
| 58 | if (length == 4) |
| 59 | { |
| 60 | lengthLeft = ieBoundary - buffer.getCurrentIndex(); |
| 61 | if (!(DataTypeCodecUtils::decodeIpAddressV4(buffer, data.ipAddressV4, lengthLeft))) |
| 62 | { |
| 63 | errorStream.add((char *)"Failed to decode: ipAddressV4\n"); |
| 64 | return false; |
| 65 | } |
| 66 | data.ipAddressV4Present = true; |
| 67 | } |
| 68 | |
| 69 | if (length == 6) |
| 70 | { |
| 71 | lengthLeft = ieBoundary - buffer.getCurrentIndex(); |
| 72 | if (!(DataTypeCodecUtils::decodeIpAddressV6(buffer, data.ipAddressV6, lengthLeft))) |
| 73 | { |
| 74 | errorStream.add((char *)"Failed to decode: ipAddressV6\n"); |
| 75 | return false; |
| 76 | } |
| 77 | data.ipAddressV6Present = true; |
| 78 | } |
| 79 | |
| 80 | // The IE is decoded now. The buffer index should be pointing to the |
| 81 | // IE Boundary. If not, we have some more data left for the IE which we don't know |
| 82 | // how to decode |
| 83 | if (ieBoundary == buffer.getCurrentIndex()) |
| 84 | { |
| 85 | return true; |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | errorStream.add((char *)"Unable to decode IE IpAddressIe\n"); |
| 90 | return false; |
| 91 | } |
| 92 | } |
| 93 | void IpAddressIe::displayIpAddressIe_v(IpAddressIeData const &data, Debug &stream) |
| 94 | { |
| 95 | stream.incrIndent(); |
| 96 | stream.add((char *)"IpAddressIeData:"); |
| 97 | stream.incrIndent(); |
| 98 | stream.endOfLine(); |
| 99 | |
| 100 | if (data.ipAddressV4Present) |
| 101 | { |
| 102 | stream.add((char *)"ipAddressV4:"); |
| 103 | stream.endOfLine(); |
| 104 | DataTypeCodecUtils::displayIpAddressV4_v(data.ipAddressV4, stream); |
| 105 | } |
| 106 | |
| 107 | if (data.ipAddressV6Present) |
| 108 | { |
| 109 | stream.add((char *)"ipAddressV6:"); |
| 110 | stream.endOfLine(); |
| 111 | DataTypeCodecUtils::displayIpAddressV6_v(data.ipAddressV6, stream); |
| 112 | } |
| 113 | stream.decrIndent(); |
| 114 | stream.decrIndent(); |
| 115 | } |