| 28 | |
| 29 | |
| 30 | JSONReader::JSONReader(PacketReader& packet,const PoolBuffers& poolBuffers) : _pos(packet.position()),_pBuffer(poolBuffers),DataReader(packet),_isValid(false) { |
| 31 | |
| 32 | // check first '[' and last ']' or '{ and '}' |
| 33 | |
| 34 | const UInt8* cur = current(); |
| 35 | if (!cur) |
| 36 | return; |
| 37 | bool isArray(*cur=='['); |
| 38 | if (!isArray && *cur != '{') |
| 39 | return; |
| 40 | |
| 41 | packet.next(); |
| 42 | _pos = packet.position(); |
| 43 | |
| 44 | if (!(cur = current())) |
| 45 | return; |
| 46 | |
| 47 | const UInt8* end(cur + packet.available()); |
| 48 | |
| 49 | while (end-- > cur) { |
| 50 | if (!isspace(*end)) { |
| 51 | if (isArray) { |
| 52 | if (*end == ']') { |
| 53 | _isValid = true; |
| 54 | packet.shrink(end-cur); |
| 55 | } |
| 56 | } else if (*end == '}') { |
| 57 | _isValid = true; |
| 58 | packet.shrink(end-cur); |
| 59 | } |
| 60 | return; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | |
| 66 | UInt8 JSONReader::followingType() { |