diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-11-29 02:28:21 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-11-29 02:28:21 +0300 |
commit | 0d7e12ce55d1ff4f303b37fb89fc01fad5dfb8cf (patch) | |
tree | 1453013a445ccb93c23c7b69faa494056abc8d5e /src/p18/response.h | |
parent | 46c308bc1406ccf7415698ca24e69865022edaee (diff) |
p18: fix variable field lengths in get-p-rated
Diffstat (limited to 'src/p18/response.h')
-rw-r--r-- | src/p18/response.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/p18/response.h b/src/p18/response.h index b14c9b0..42b84b8 100644 --- a/src/p18/response.h +++ b/src/p18/response.h @@ -125,6 +125,26 @@ public: /** + * Some helpers + */ +class FieldLength { +protected: + size_t min_; + size_t max_; + +public: + FieldLength(size_t n) : min_(n), max_(n) {} + FieldLength(size_t min, size_t max) : min_(min), max_(max) {} + + [[nodiscard]] bool validate(size_t len) const { + return len >= min_ && len <= max_; + } + + friend std::ostream& operator<<(std::ostream& os, FieldLength fl); +}; + + +/** * Base responses */ @@ -145,7 +165,7 @@ class GetResponse : public BaseResponse { protected: const char* getData() const; size_t getDataSize() const; - std::vector<std::string> getList(std::vector<size_t> itemLengths, int expectAtLeast = -1) const; + std::vector<std::string> getList(std::vector<FieldLength> itemLengths, int expectAtLeast = -1) const; public: using BaseResponse::BaseResponse; |