AsciiMassage
AsciiMassageParser.h
1 /* * Copyright (C) 2017 Thomas O. Fredericks, Sofian Audry
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy of
4  * this software and associated documentation files (the "Software"), to deal in
5  * the Software without restriction, including without limitation the rights to
6  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7  * the Software, and to permit persons to whom the Software is furnished to do so,
8  * subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in all
11  * copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef AsciiMassageParser_h
22 #define AsciiMassageParser_h
23 
24 
25 #include "Massage/MassageParser.h"
26 
27 
30 {
31 public:
34 
36  virtual int8_t nextByte(bool* error=0);
37 
39  virtual int16_t nextInt(bool* error=0);
40 
42  virtual int32_t nextLong(bool* error=0);
43 
45  virtual float nextFloat(bool* error=0);
46 
47  // Reads next string.
48  virtual int nextString(char* receivedString, int bufferLength);
49 
51  virtual void flush();
52 
53 protected:
56  virtual bool _decode(int serialByte);
57 
58 private:
59  // Moves nextIndex to the next token.
60  bool _updateNextIndex();
61 
62  // Returns true iff it is still possible to call next*().
63  bool _hasNext() const;
64 
65  bool _parsingString;
66 
67  // Helper function to read next value.
68  void _nextBlock(bool isInteger, uint8_t* value, size_t n, bool* error);
69 
70  // Keeps track of next index where to store data in buffer.
71  size_t _nextIndex;
72 
73 
74 };
75 
76 
77 
78 
79 #endif
Main MassageParser abstract class.
Definition: MassageParser.h:40
virtual bool _decode(int serialByte)
Definition: AsciiMassageParser.cpp:95
virtual int nextString(char *receivedString, int bufferLength)
Reads next string.
Definition: AsciiMassageParser.cpp:71
virtual int16_t nextInt(bool *error=0)
Reads next int.
Definition: AsciiMassageParser.cpp:47
AsciiMassageParser()
Constructor.
Definition: AsciiMassageParser.cpp:29
Main AsciiMassageParser class.
Definition: AsciiMassageParser.h:29
virtual float nextFloat(bool *error=0)
Reads next float.
Definition: AsciiMassageParser.cpp:63
virtual void flush()
Flushes current message in buffer (if any).
Definition: AsciiMassageParser.cpp:33
virtual int32_t nextLong(bool *error=0)
Reads next long.
Definition: AsciiMassageParser.cpp:55
virtual int8_t nextByte(bool *error=0)
Reads next byte.
Definition: AsciiMassageParser.cpp:40