From ca3b89aa7de73f47d6767d5d5d6e408c54ffb696 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 22 Sep 2015 14:09:24 +0800 Subject: [PATCH] add kafka array, use c++ template. --- trunk/src/protocol/srs_kafka_stack.hpp | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/trunk/src/protocol/srs_kafka_stack.hpp b/trunk/src/protocol/srs_kafka_stack.hpp index 5b2f14b5d..5f52dda55 100644 --- a/trunk/src/protocol/srs_kafka_stack.hpp +++ b/trunk/src/protocol/srs_kafka_stack.hpp @@ -69,6 +69,35 @@ public: virtual int total_size(); }; +/** + * This is a notation for handling repeated structures. These will always be encoded as an + * int32 size containing the length N followed by N repetitions of the structure which can + * itself be made up of other primitive types. In the BNF grammars below we will show an + * array of a structure foo as [foo]. + * @see https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-Requests + */ +template +class SrsKafkaArray +{ +private: + int length; + std::vector elems; + typedef typename std::vector::iterator SrsIterator; +public: + SrsKafkaArray() + { + length = 0; + } + virtual ~SrsKafkaArray() + { + for (SrsIterator it = elems.begin(); it != elems.end(); ++it) { + T* elem = *it; + srs_freep(elem); + } + elems.clear(); + } +}; + /** * the header of request, includes the size of request. * @see https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-Requests