Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
util/SmartRestTemplate.cpp@100:dbcd3bc51758, 2015-05-08 (annotated)
- Committer:
- xinlei
- Date:
- Fri May 08 12:19:57 2015 +0000
- Revision:
- 100:dbcd3bc51758
- Parent:
- 91:48069375dffa
v2.1rc3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xinlei | 100:dbcd3bc51758 | 1 | #include <string.h> |
Cumulocity | 41:804f6a0bda26 | 2 | #include "SmartRestTemplate.h" |
Cumulocity | 41:804f6a0bda26 | 3 | |
Cumulocity | 41:804f6a0bda26 | 4 | SmartRestTemplate::SmartRestTemplate() |
Cumulocity | 41:804f6a0bda26 | 5 | { |
Cumulocity | 41:804f6a0bda26 | 6 | _len = NULL; |
Cumulocity | 41:804f6a0bda26 | 7 | } |
Cumulocity | 41:804f6a0bda26 | 8 | |
Cumulocity | 41:804f6a0bda26 | 9 | bool SmartRestTemplate::add(const char *line) |
Cumulocity | 41:804f6a0bda26 | 10 | { |
Cumulocity | 41:804f6a0bda26 | 11 | if (_len == SMARTREST_TEMPLATE_FIXED_SIZE) |
Cumulocity | 41:804f6a0bda26 | 12 | return false; |
Cumulocity | 41:804f6a0bda26 | 13 | _buffer[_len++] = line; |
xinlei | 91:48069375dffa | 14 | return true; |
Cumulocity | 41:804f6a0bda26 | 15 | } |
Cumulocity | 41:804f6a0bda26 | 16 | |
Cumulocity | 41:804f6a0bda26 | 17 | size_t SmartRestTemplate::writeTo(AbstractDataSink& sink) const |
Cumulocity | 41:804f6a0bda26 | 18 | { |
Cumulocity | 41:804f6a0bda26 | 19 | size_t len = 0; |
Cumulocity | 41:804f6a0bda26 | 20 | |
Cumulocity | 41:804f6a0bda26 | 21 | for (size_t n = 0; n < _len; n++) |
Cumulocity | 41:804f6a0bda26 | 22 | len += sink.write((char*)_buffer[n], strlen(_buffer[n])); |
Cumulocity | 41:804f6a0bda26 | 23 | |
Cumulocity | 41:804f6a0bda26 | 24 | return len; |
Cumulocity | 41:804f6a0bda26 | 25 | } |
Cumulocity | 41:804f6a0bda26 | 26 | |
Cumulocity | 41:804f6a0bda26 | 27 | size_t SmartRestTemplate::writtenLength() const |
Cumulocity | 41:804f6a0bda26 | 28 | { |
Cumulocity | 41:804f6a0bda26 | 29 | size_t len = 0; |
Cumulocity | 41:804f6a0bda26 | 30 | |
Cumulocity | 41:804f6a0bda26 | 31 | for (size_t n = 0; n < _len; n++) |
Cumulocity | 41:804f6a0bda26 | 32 | len += strlen(_buffer[n]); |
Cumulocity | 41:804f6a0bda26 | 33 | |
Cumulocity | 41:804f6a0bda26 | 34 | return len; |
Cumulocity | 41:804f6a0bda26 | 35 | } |
Cumulocity | 41:804f6a0bda26 | 36 | |
Cumulocity | 41:804f6a0bda26 | 37 | DataGenerator * SmartRestTemplate::copy() const |
Cumulocity | 41:804f6a0bda26 | 38 | { |
Cumulocity | 41:804f6a0bda26 | 39 | return NULL; |
Cumulocity | 41:804f6a0bda26 | 40 | } |