AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.3.1
CompositeMessageParser.hpp
1 //
3 // Copyright (c) 2010-2021 60East Technologies Inc., All Rights Reserved.
4 //
5 // This computer software is owned by 60East Technologies Inc. and is
6 // protected by U.S. copyright laws and other laws and by international
7 // treaties. This computer software is furnished by 60East Technologies
8 // Inc. pursuant to a written license agreement and may be used, copied,
9 // transmitted, and stored only in accordance with the terms of such
10 // license agreement and with the inclusion of the above copyright notice.
11 // This computer software or any other copies thereof may not be provided
12 // or otherwise made available to any other person.
13 //
14 // U.S. Government Restricted Rights. This computer software: (a) was
15 // developed at private expense and is in all respects the proprietary
16 // information of 60East Technologies Inc.; (b) was not developed with
17 // government funds; (c) is a trade secret of 60East Technologies Inc.
18 // for all purposes of the Freedom of Information Act; and (d) is a
19 // commercial item and thus, pursuant to Section 12.212 of the Federal
20 // Acquisition Regulations (FAR) and DFAR Supplement Section 227.7202,
21 // Government's use, duplication or disclosure of the computer software
22 // is subject to the restrictions set forth by 60East Technologies Inc..
23 //
25 
26 #ifndef _AMPS_COMPOSITEMESSAGEPARSER_HPP_
27 #define _AMPS_COMPOSITEMESSAGEPARSER_HPP_
28 #include <Field.hpp>
29 #include <vector>
30 
31 namespace AMPS
32 {
46  {
47  public:
50 
61  template <class T>
62  size_t parse(const T& message_);
63 
71  size_t parse(const char* data_, size_t length_);
72 
76  size_t size(void) const;
77 
84  AMPS::Field getPart(size_t index_) const;
85  private:
86  typedef std::pair<const char*,size_t> PartLocator;
87  typedef std::vector<PartLocator> PartVector;
88  PartVector _parts;
89  };
90 
92  {;}
93 
94  template <class T>
95  inline size_t
96  CompositeMessageParser::parse(const T& message_)
97  {
98  const char* data;
99  size_t length;
100  message_.getRawData(&data, &length);
101  return parse(data, length);
102  }
103 
104  inline size_t
105  CompositeMessageParser::parse(const char* data_, size_t length_)
106  {
107  _parts.clear();
108  const unsigned char* end = (const unsigned char*) data_ + length_;
109  const unsigned char* p = (const unsigned char*) data_;
110  while((p+4) <= end)
111  {
112  size_t partLength = p[0];
113  partLength = partLength << 8 | p[1];
114  partLength = partLength << 8 | p[2];
115  partLength = partLength << 8 | p[3];
116 
117  p += 4;
118  if(p+partLength <= end)
119  {
120  _parts.push_back(PartLocator((const char*)(p),partLength));
121  }
122  p += partLength;
123  }
124  return _parts.size();
125  }
126  inline size_t
128  {
129  return _parts.size();
130  }
131  inline AMPS::Field
132  CompositeMessageParser::getPart(size_t index_) const
133  {
134  if (index_ < _parts.size())
135  {
136  const PartLocator& part = _parts[index_];
137  return AMPS::Field(part.first, part.second);
138  }
139  else
140  {
141  return AMPS::Field();
142  }
143  }
144 }
145 #endif
146 
147 
size_t size(void) const
Returns the number of valid message parts in the message that was last parsed.
Definition: CompositeMessageParser.hpp:127
Defines the AMPS::Field class, which represents the value of a field in a message.
CompositeMessageParser(void)
Creates a new CompositeMessageParser with 0 valid parts.
Definition: CompositeMessageParser.hpp:91
Field represents the value of a single field in a Message.
Definition: Field.hpp:84
AMPS::Field getPart(size_t index_) const
Returns the data of a message part.
Definition: CompositeMessageParser.hpp:132
size_t parse(const T &message_)
Parses a composite message, first clearing any existing data in the parser.
Definition: CompositeMessageParser.hpp:96
Definition: ampsplusplus.hpp:103
Used to retrieve individual message parts from AMPS composite messages, which are messages where the ...
Definition: CompositeMessageParser.hpp:45