1/*
2 * Copyright 2023, Andrew Lindesay <apl@lindesay.co.nz>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5#ifndef CHECKSUM_JSON_EVENT_LISTENER_H
6#define CHECKSUM_JSON_EVENT_LISTENER_H
7
8
9#include <JsonEventListener.h>
10
11
12/*!	This class can be used by a text to accept JSON events and then to maintain a checksum of the
13	strings and numbers that it encounters in order to get some sort of a checksum on the data
14	that it is seeing. It can then compare this to the data that was emitted in order to verify
15	that the JSON parser has parsed and passed-through all of the data correctly.
16*/
17
18class ChecksumJsonEventListener : public BJsonEventListener {
19public:
20								ChecksumJsonEventListener(int32 checksumLimit);
21	virtual						~ChecksumJsonEventListener();
22
23	virtual bool				Handle(const BJsonEvent& event);
24	virtual void				HandleError(status_t status, int32 line, const char* message);
25	virtual void				Complete();
26
27			uint32				Checksum() const;
28			status_t			Error() const;
29
30private:
31			void				_ChecksumProcessCharacters(const char* content, size_t len);
32
33private:
34			uint32				fChecksum;
35			uint32				fChecksumLimit;
36			status_t			fError;
37			bool				fCompleted;
38};
39
40#endif // CHECKSUM_JSON_EVENT_LISTENER_H
41