mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			66 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| // Copyright Benoit Blanchon 2014-2017
 | |
| // MIT License
 | |
| //
 | |
| // Arduino JSON library
 | |
| // https://bblanchon.github.io/ArduinoJson/
 | |
| // If you like this project, please add a star!
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #if ARDUINOJSON_ENABLE_ARDUINO_STREAM
 | |
| 
 | |
| #include <Stream.h>
 | |
| 
 | |
| #include "../TypeTraits/EnableIf.hpp"
 | |
| #include "../TypeTraits/IsBaseOf.hpp"
 | |
| #include "../TypeTraits/RemoveReference.hpp"
 | |
| 
 | |
| namespace ArduinoJson {
 | |
| namespace Internals {
 | |
| 
 | |
| struct ArduinoStreamTraits {
 | |
|   class Reader {
 | |
|     Stream& _stream;
 | |
|     char _current, _next;
 | |
| 
 | |
|    public:
 | |
|     Reader(Stream& stream) : _stream(stream), _current(0), _next(0) {}
 | |
| 
 | |
|     void move() {
 | |
|       _current = _next;
 | |
|       _next = 0;
 | |
|     }
 | |
| 
 | |
|     char current() {
 | |
|       if (!_current) _current = read();
 | |
|       return _current;
 | |
|     }
 | |
| 
 | |
|     char next() {
 | |
|       // assumes that current() has been called
 | |
|       if (!_next) _next = read();
 | |
|       return _next;
 | |
|     }
 | |
| 
 | |
|    private:
 | |
|     char read() {
 | |
|       // don't use _stream.read() as it ignores the timeout
 | |
|       char c = 0;
 | |
|       _stream.readBytes(&c, 1);
 | |
|       return c;
 | |
|     }
 | |
|   };
 | |
| };
 | |
| 
 | |
| template <typename TStream>
 | |
| struct StringTraits<TStream,
 | |
|                     // match any type that is derived from Stream:
 | |
|                     typename TypeTraits::EnableIf<TypeTraits::IsBaseOf<
 | |
|                         Stream, typename TypeTraits::RemoveReference<
 | |
|                                     TStream>::type>::value>::type>
 | |
|     : ArduinoStreamTraits {};
 | |
| }
 | |
| }
 | |
| 
 | |
| #endif
 |