PageRenderTime 167ms CodeModel.GetById 30ms app.highlight 114ms RepoModel.GetById 17ms app.codeStats 0ms

/src/buffer/struct_codec_macros.hpp

https://github.com/lianic/ardb
C++ Header | 928 lines | 813 code | 67 blank | 48 comment | 58 complexity | e10620adaa554e622ae8f3a5cddd4f45 MD5 | raw file
  1/*
  2 *Copyright (c) 2013-2013, yinqiwen <yinqiwen@gmail.com>
  3 *All rights reserved.
  4 *
  5 *Redistribution and use in source and binary forms, with or without
  6 *modification, are permitted provided that the following conditions are met:
  7 *
  8 *  * Redistributions of source code must retain the above copyright notice,
  9 *    this list of conditions and the following disclaimer.
 10 *  * Redistributions in binary form must reproduce the above copyright
 11 *    notice, this list of conditions and the following disclaimer in the
 12 *    documentation and/or other materials provided with the distribution.
 13 *  * Neither the name of Redis nor the names of its contributors may be used
 14 *    to endorse or promote products derived from this software without
 15 *    specific prior written permission.
 16 *
 17 *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 18 *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 19 *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 20 *ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 21 *BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 22 *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 23 *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 24 *INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 25 *CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 26 *ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 27 *THE POSSIBILITY OF SUCH DAMAGE.
 28 */
 29/*
 30 * struct_codec_macros.hpp
 31 *
 32 *  Created on: 2011-9-15
 33 *      Author: yinqiwen
 34 */
 35
 36#ifndef STRUCT_CODEC_MACROS_HPP_
 37#define STRUCT_CODEC_MACROS_HPP_
 38#include "buffer/buffer_helper.hpp"
 39#include "buffer/struct_code_templates.hpp"
 40#include <string>
 41#include <list>
 42#include <map>
 43#include <vector>
 44#include <deque>
 45#include <utility>
 46#include <btree_set.h>
 47#include <btree_map.h>
 48
 49using ardb::Buffer;
 50
 51#define ENCODE_DEFINE(...) \
 52    public:                  \
 53    bool Encode(Buffer& buf)  \
 54    { \
 55        return ardb::encode_arg(buf,__VA_ARGS__); \
 56    } \
 57
 58#define DECODE_DEFINE(...) \
 59    public:                  \
 60    bool Decode(Buffer& buf)  \
 61    { \
 62        return ardb::decode_arg(buf, __VA_ARGS__); \
 63    } \
 64
 65#define ENCODE2_DEFINE(...) \
 66    public:                  \
 67    bool Encode(Buffer& buf)  \
 68    { \
 69        return ardb::encode_arg_with_tag(buf,__VA_ARGS__); \
 70    } \
 71
 72#define DECODE2_DEFINE(...) \
 73    public:                  \
 74    bool Decode(Buffer& buf)  \
 75    { \
 76        return ardb::decode_arg_with_tag(buf, __VA_ARGS__); \
 77    } \
 78
 79#define CODEC2_DEFINE(...) \
 80            ENCODE2_DEFINE(__VA_ARGS__)\
 81            DECODE2_DEFINE(__VA_ARGS__)
 82
 83#define ENCODE_DEFINE_P(...) \
 84    public:                  \
 85    bool Encode(Buffer* buf)  \
 86    { \
 87        RETURN_FALSE_IF_NULL(buf); \
 88        return ardb::encode_arg(*buf,__VA_ARGS__); \
 89    }
 90
 91#define DECODE_DEFINE_P(...) \
 92    public:                  \
 93    bool Decode(Buffer* buf)  \
 94    { \
 95        RETURN_FALSE_IF_NULL(buf); \
 96        return ardb::decode_arg(*buf, __VA_ARGS__); \
 97    }
 98
 99#define FIX_ENCODE_DEFINE_P(...) \
100    public:                  \
101    bool Encode(Buffer* buf)  \
102    { \
103        RETURN_FALSE_IF_NULL(buf); \
104        return ardb::fix_encode_arg(*buf,__VA_ARGS__); \
105    }
106
107#define FIX_DECODE_DEFINE_P(...) \
108    public:                  \
109    bool Decode(Buffer* buf)  \
110    { \
111        RETURN_FALSE_IF_NULL(buf); \
112        return ardb::fix_decode_arg(*buf, __VA_ARGS__); \
113    }
114
115#define CODEC_DEFINE(...) \
116        ENCODE_DEFINE(__VA_ARGS__)\
117        DECODE_DEFINE(__VA_ARGS__)
118
119#define CODEC_DEFINE_P(...) \
120        ENCODE_DEFINE_P(__VA_ARGS__)\
121        DECODE_DEFINE_P(__VA_ARGS__)
122
123#define FIX_CODEC_DEFINE_P(...) \
124        FIX_ENCODE_DEFINE_P(__VA_ARGS__)\
125        FIX_DECODE_DEFINE_P(__VA_ARGS__)
126
127namespace ardb
128{
129    inline bool encode_arg(Buffer& buf)
130    {
131        return true;
132    }
133
134    inline bool encode_arg(Buffer& buf, std::string& a0)
135    {
136        BufferHelper::WriteVarString(buf, a0);
137        return true;
138    }
139
140    inline bool encode_arg(Buffer& buf, float& a0)
141    {
142        BufferHelper::WriteFixFloat(buf, a0);
143        return true;
144    }
145
146    inline bool encode_arg(Buffer& buf, double& a0)
147    {
148        BufferHelper::WriteFixDouble(buf, a0);
149        return true;
150    }
151
152    inline bool encode_arg(Buffer& buf, uint8& a0)
153    {
154        BufferHelper::WriteFixUInt8(buf, a0);
155        return true;
156    }
157    inline bool encode_arg(Buffer& buf, const uint8& a0)
158    {
159        BufferHelper::WriteFixUInt8(buf, a0);
160        return true;
161    }
162    inline bool encode_arg(Buffer& buf, int8& a0)
163    {
164        BufferHelper::WriteFixInt8(buf, a0);
165        return true;
166    }
167
168    inline bool encode_arg(Buffer& buf, const int8& a0)
169    {
170        BufferHelper::WriteFixInt8(buf, a0);
171        return true;
172    }
173
174    inline bool encode_arg(Buffer& buf, bool& a0)
175    {
176        BufferHelper::WriteBool(buf, a0);
177        return true;
178    }
179    inline bool encode_arg(Buffer& buf, const bool& a0)
180    {
181        BufferHelper::WriteBool(buf, a0);
182        return true;
183    }
184    inline bool encode_arg(Buffer& buf, uint16& a0)
185    {
186        BufferHelper::WriteVarUInt16(buf, a0);
187        return true;
188    }
189    inline bool encode_arg(Buffer& buf, const uint16& a0)
190    {
191        BufferHelper::WriteVarUInt16(buf, a0);
192        return true;
193    }
194    inline bool encode_arg(Buffer& buf, int16& a0)
195    {
196        BufferHelper::WriteVarInt16(buf, a0);
197        return true;
198    }
199    inline bool encode_arg(Buffer& buf, const int16& a0)
200    {
201        BufferHelper::WriteVarInt16(buf, a0);
202        return true;
203    }
204    inline bool encode_arg(Buffer& buf, uint32& a0)
205    {
206        BufferHelper::WriteVarUInt32(buf, a0);
207        return true;
208    }
209    inline bool encode_arg(Buffer& buf, const uint32& a0)
210    {
211        BufferHelper::WriteVarUInt32(buf, a0);
212        return true;
213    }
214    inline bool encode_arg(Buffer& buf, int32& a0)
215    {
216        BufferHelper::WriteVarInt32(buf, a0);
217        return true;
218    }
219    inline bool encode_arg(Buffer& buf, const int32& a0)
220    {
221        BufferHelper::WriteVarInt32(buf, a0);
222        return true;
223    }
224    inline bool encode_arg(Buffer& buf, uint64& a0)
225    {
226        BufferHelper::WriteVarUInt64(buf, a0);
227        return true;
228    }
229    inline bool encode_arg(Buffer& buf, const uint64& a0)
230    {
231        BufferHelper::WriteVarUInt64(buf, a0);
232        return true;
233    }
234    inline bool encode_arg(Buffer& buf, int64& a0)
235    {
236        BufferHelper::WriteVarInt64(buf, a0);
237        return true;
238    }
239    inline bool encode_arg(Buffer& buf, const int64& a0)
240    {
241        BufferHelper::WriteVarInt64(buf, a0);
242        return true;
243    }
244    inline bool encode_arg(Buffer& buf, const std::string& a0)
245    {
246        BufferHelper::WriteVarString(buf, a0);
247        return true;
248    }
249
250    inline bool encode_arg(Buffer& buf, const char*& a0)
251    {
252        BufferHelper::WriteVarString(buf, a0);
253        return true;
254    }
255
256    //fix encode
257    inline bool fix_encode_arg(Buffer& buf)
258    {
259        return true;
260    }
261
262    template<typename A0>
263    inline bool fix_encode_arg(Buffer& buf, A0& a0)
264    {
265        return a0.Encode(buf);
266    }
267
268    template<typename T>
269    inline bool fix_encode_arg(Buffer& buf, std::list<T>& a0)
270    {
271        BufferHelper::WriteFixUInt32(buf, a0.size());
272        typename std::list<T>::iterator iter = a0.begin();
273        while (iter != a0.end())
274        {
275            fix_encode_arg(buf, *iter);
276            iter++;
277        }
278        return true;
279    }
280
281    template<typename T>
282    inline bool fix_encode_arg(Buffer& buf, std::vector<T>& a0)
283    {
284        BufferHelper::WriteFixUInt32(buf, a0.size());
285        typename std::vector<T>::iterator iter = a0.begin();
286        while (iter != a0.end())
287        {
288            fix_encode_arg(buf, *iter);
289            iter++;
290        }
291        return true;
292    }
293
294    template<typename T>
295    inline bool fix_encode_arg(Buffer& buf, std::deque<T>& a0)
296    {
297        BufferHelper::WriteFixUInt32(buf, a0.size());
298        typename std::deque<T>::iterator iter = a0.begin();
299        while (iter != a0.end())
300        {
301            fix_encode_arg(buf, *iter);
302            iter++;
303        }
304        return true;
305    }
306
307    template<typename K, typename V>
308    inline bool fix_encode_arg(Buffer& buf, std::map<K, V>& a0)
309    {
310        BufferHelper::WriteFixUInt32(buf, a0.size());
311        typename std::map<K, V>::iterator iter = a0.begin();
312        while (iter != a0.end())
313        {
314            fix_encode_arg(buf, iter->first);
315            fix_encode_arg(buf, iter->second);
316            iter++;
317        }
318        return true;
319    }
320
321    inline bool fix_encode_arg(Buffer& buf, float& a0)
322    {
323        BufferHelper::WriteFixFloat(buf, a0);
324        return true;
325    }
326    inline bool fix_encode_arg(Buffer& buf, double& a0)
327    {
328        BufferHelper::WriteFixDouble(buf, a0);
329        return true;
330    }
331
332    inline bool fix_encode_arg(Buffer& buf, uint8_t& a0)
333    {
334        BufferHelper::WriteFixUInt8(buf, a0);
335        return true;
336    }
337    inline bool fix_encode_arg(Buffer& buf, const uint8_t& a0)
338    {
339        BufferHelper::WriteFixUInt8(buf, a0);
340        return true;
341    }
342    inline bool fix_encode_arg(Buffer& buf, int8_t& a0)
343    {
344        BufferHelper::WriteFixInt8(buf, a0);
345        return true;
346    }
347
348    inline bool fix_encode_arg(Buffer& buf, const int8_t& a0)
349    {
350        BufferHelper::WriteFixInt8(buf, a0);
351        return true;
352    }
353
354    inline bool fix_encode_arg(Buffer& buf, bool& a0)
355    {
356        BufferHelper::WriteBool(buf, a0);
357        return true;
358    }
359    inline bool fix_encode_arg(Buffer& buf, const bool& a0)
360    {
361        BufferHelper::WriteBool(buf, a0);
362        return true;
363    }
364    inline bool fix_encode_arg(Buffer& buf, uint16_t& a0)
365    {
366        BufferHelper::WriteFixUInt16(buf, a0);
367        return true;
368    }
369    inline bool fix_encode_arg(Buffer& buf, const uint16_t& a0)
370    {
371        BufferHelper::WriteFixUInt16(buf, a0);
372        return true;
373    }
374    inline bool fix_encode_arg(Buffer& buf, int16_t& a0)
375    {
376        BufferHelper::WriteFixInt16(buf, a0);
377        return true;
378    }
379    inline bool fix_encode_arg(Buffer& buf, const int16_t& a0)
380    {
381        BufferHelper::WriteFixInt16(buf, a0);
382        return true;
383    }
384    inline bool fix_encode_arg(Buffer& buf, uint32_t& a0)
385    {
386        BufferHelper::WriteFixUInt32(buf, a0);
387        return true;
388    }
389    inline bool fix_encode_arg(Buffer& buf, const uint32_t& a0)
390    {
391        BufferHelper::WriteFixUInt32(buf, a0);
392        return true;
393    }
394    inline bool fix_encode_arg(Buffer& buf, int32_t& a0)
395    {
396        BufferHelper::WriteFixInt32(buf, a0);
397        return true;
398    }
399    inline bool fix_encode_arg(Buffer& buf, const int32_t& a0)
400    {
401        BufferHelper::WriteFixInt32(buf, a0);
402        return true;
403    }
404    inline bool fix_encode_arg(Buffer& buf, uint64_t& a0)
405    {
406        BufferHelper::WriteFixUInt64(buf, a0);
407        return true;
408    }
409    inline bool fix_encode_arg(Buffer& buf, const uint64_t& a0)
410    {
411        BufferHelper::WriteFixUInt64(buf, a0);
412        return true;
413    }
414    inline bool fix_encode_arg(Buffer& buf, int64_t& a0)
415    {
416        BufferHelper::WriteFixInt64(buf, a0);
417        return true;
418    }
419    inline bool fix_encode_arg(Buffer& buf, const int64_t& a0)
420    {
421        BufferHelper::WriteFixInt64(buf, a0);
422        return true;
423    }
424    inline bool fix_encode_arg(Buffer& buf, std::string& a0)
425    {
426        BufferHelper::WriteFixString(buf, a0);
427        return true;
428    }
429    inline bool fix_encode_arg(Buffer& buf, const std::string& a0)
430    {
431        BufferHelper::WriteFixString(buf, a0);
432        return true;
433    }
434
435    inline bool fix_encode_arg(Buffer& buf, const char*& a0)
436    {
437        BufferHelper::WriteFixString(buf, a0);
438        return true;
439    }
440
441    inline bool decode_arg(Buffer& buf)
442    {
443        return true;
444    }
445
446    template<typename A0>
447    inline bool decode_arg(Buffer& buf, A0& a0)
448    {
449        return a0.Decode(buf);
450    }
451
452    //template<>
453    inline bool decode_arg(Buffer& buf, float& a0)
454    {
455        return BufferHelper::ReadFixFloat(buf, a0);
456    }
457    inline bool decode_arg(Buffer& buf, double& a0)
458    {
459        return BufferHelper::ReadFixDouble(buf, a0);
460    }
461
462    inline bool decode_arg(Buffer& buf, uint8& a0)
463    {
464        return BufferHelper::ReadFixUInt8(buf, a0);
465    }
466    inline bool decode_arg(Buffer& buf, int8& a0)
467    {
468        return BufferHelper::ReadFixInt8(buf, a0);
469    }
470
471    inline bool decode_arg(Buffer& buf, bool& a0)
472    {
473        return BufferHelper::ReadBool(buf, a0);
474    }
475
476    //template<>
477    inline bool decode_arg(Buffer& buf, uint16& a0)
478    {
479        return BufferHelper::ReadVarUInt16(buf, a0);
480    }
481    inline bool decode_arg(Buffer& buf, int16& a0)
482    {
483        return BufferHelper::ReadVarInt16(buf, a0);
484    }
485
486    //template<>
487    inline bool decode_arg(Buffer& buf, uint32& a0)
488    {
489        return BufferHelper::ReadVarUInt32(buf, a0);
490    }
491    inline bool decode_arg(Buffer& buf, int32& a0)
492    {
493        return BufferHelper::ReadVarInt32(buf, a0);
494    }
495    //template<>
496    inline bool decode_arg(Buffer& buf, uint64& a0)
497    {
498        return BufferHelper::ReadVarUInt64(buf, a0);
499    }
500    inline bool decode_arg(Buffer& buf, int64& a0)
501    {
502        return BufferHelper::ReadVarInt64(buf, a0);
503    }
504    //template<>
505    inline bool decode_arg(Buffer& buf, std::string& a0)
506    {
507        return BufferHelper::ReadVarString(buf, a0);
508    }
509    //template<>
510    inline bool decode_arg(Buffer& buf, char*& a0)
511    {
512        return BufferHelper::ReadVarString(buf, a0);
513    }
514
515    //Fix decode
516    template<typename A0>
517    inline bool fix_decode_arg(Buffer& buf, A0& a0)
518    {
519        return a0.Decode(buf);
520    }
521
522    template<typename T>
523    inline bool fix_decode_arg(Buffer& buf, std::list<T>& a0)
524    {
525        uint32 size;
526        if (!BufferHelper::ReadFixUInt32(buf, size))
527        {
528            return false;
529        }
530        uint32 i = 0;
531        while (i < size)
532        {
533            T t;
534            if (!fix_decode_arg(buf, t))
535            {
536                return false;
537            }
538            a0.push_back(t);
539            i++;
540        }
541        return true;
542    }
543
544    template<typename T>
545    inline bool fix_decode_arg(Buffer& buf, std::vector<T>& a0)
546    {
547        uint32 size;
548        if (!BufferHelper::ReadFixUInt32(buf, size))
549        {
550            return false;
551        }
552        uint32 i = 0;
553        while (i < size)
554        {
555            T t;
556            if (!fix_decode_arg(buf, t))
557            {
558                return false;
559            }
560            a0.push_back(t);
561            i++;
562        }
563        return true;
564    }
565
566    template<typename T>
567    inline bool fix_decode_arg(Buffer& buf, std::deque<T>& a0)
568    {
569        uint32 size;
570        if (!BufferHelper::ReadFixUInt32(buf, size))
571        {
572            return false;
573        }
574        uint32 i = 0;
575        while (i < size)
576        {
577            T t;
578            if (!fix_decode_arg(buf, t))
579            {
580                return false;
581            }
582            a0.push_back(t);
583            i++;
584        }
585        return true;
586    }
587
588    template<typename K, typename V>
589    inline bool fix_decode_arg(Buffer& buf, std::map<K, V>& a0)
590    {
591        uint32 size;
592        if (!BufferHelper::ReadFixUInt32(buf, size))
593        {
594            return false;
595        }
596        uint32 i = 0;
597        while (i < size)
598        {
599            K k;
600            V v;
601            if (!fix_decode_arg(buf, k) || !fix_decode_arg(buf, v))
602            {
603                return false;
604            }
605            a0.insert(std::make_pair(k, v));
606            i++;
607        }
608        return true;
609    }
610
611    //template<>
612    inline bool fix_decode_arg(Buffer& buf, uint8_t& a0)
613    {
614        return BufferHelper::ReadFixUInt8(buf, a0);
615    }
616    inline bool fix_decode_arg(Buffer& buf, int8_t& a0)
617    {
618        return BufferHelper::ReadFixInt8(buf, a0);
619    }
620
621    inline bool fix_decode_arg(Buffer& buf, bool& a0)
622    {
623        return BufferHelper::ReadBool(buf, a0);
624    }
625
626    //template<>
627    inline bool fix_decode_arg(Buffer& buf, uint16_t& a0)
628    {
629        return BufferHelper::ReadFixUInt16(buf, a0);
630    }
631    inline bool fix_decode_arg(Buffer& buf, int16_t& a0)
632    {
633        return BufferHelper::ReadFixInt16(buf, a0);
634    }
635
636    //template<>
637    inline bool fix_decode_arg(Buffer& buf, uint32_t& a0)
638    {
639        return BufferHelper::ReadFixUInt32(buf, a0);
640    }
641    inline bool fix_decode_arg(Buffer& buf, int32_t& a0)
642    {
643        return BufferHelper::ReadFixInt32(buf, a0);
644    }
645    //template<>
646    inline bool fix_decode_arg(Buffer& buf, uint64_t& a0)
647    {
648        return BufferHelper::ReadFixUInt64(buf, a0);
649    }
650    inline bool fix_decode_arg(Buffer& buf, int64_t& a0)
651    {
652        return BufferHelper::ReadFixInt64(buf, a0);
653    }
654    //template<>
655    inline bool fix_decode_arg(Buffer& buf, std::string& a0)
656    {
657        return BufferHelper::ReadFixString(buf, a0);
658    }
659    //template<>
660    inline bool fix_decode_arg(Buffer& buf, char*& a0)
661    {
662        return BufferHelper::ReadFixString(buf, a0);
663    }
664
665    template<typename A0>
666    inline bool encode_arg(Buffer& buf, A0* a0)
667    {
668        return a0->Encode(buf);
669    }
670
671    template<typename A0>
672    inline bool encode_arg(Buffer& buf, A0& a0)
673    {
674        return a0.Encode(buf);
675    }
676
677    template<typename T>
678    inline bool encode_arg(Buffer& buf, std::list<T>& a0)
679    {
680        BufferHelper::WriteVarUInt32(buf, a0.size());
681        typename std::list<T>::iterator iter = a0.begin();
682        while (iter != a0.end())
683        {
684            encode_arg(buf, *iter);
685            iter++;
686        }
687        return true;
688    }
689
690    template<typename T>
691    inline bool encode_arg(Buffer& buf, std::set<T>& a0)
692    {
693        BufferHelper::WriteVarUInt32(buf, a0.size());
694        typename std::set<T>::iterator iter = a0.begin();
695        while (iter != a0.end())
696        {
697            encode_arg(buf, *iter);
698            iter++;
699        }
700        return true;
701    }
702
703    template<typename T>
704    inline bool encode_arg(Buffer& buf, btree::btree_set<T>& a0)
705    {
706        BufferHelper::WriteVarUInt32(buf, a0.size());
707        typename btree::btree_set<T>::iterator iter = a0.begin();
708        while (iter != a0.end())
709        {
710            encode_arg(buf, *iter);
711            iter++;
712        }
713        return true;
714    }
715
716    template<typename T>
717    inline bool encode_arg(Buffer& buf, std::vector<T>& a0)
718    {
719        BufferHelper::WriteVarUInt32(buf, a0.size());
720        typename std::vector<T>::iterator iter = a0.begin();
721        while (iter != a0.end())
722        {
723            encode_arg(buf, *iter);
724            iter++;
725        }
726        return true;
727    }
728
729    template<typename T>
730    inline bool encode_arg(Buffer& buf, std::deque<T>& a0)
731    {
732        BufferHelper::WriteVarUInt32(buf, a0.size());
733        typename std::deque<T>::iterator iter = a0.begin();
734        while (iter != a0.end())
735        {
736            encode_arg(buf, *iter);
737            iter++;
738        }
739        return true;
740    }
741
742    template<typename K, typename V>
743    inline bool encode_arg(Buffer& buf, std::map<K, V>& a0)
744    {
745        BufferHelper::WriteVarUInt32(buf, a0.size());
746        typename std::map<K, V>::iterator iter = a0.begin();
747        while (iter != a0.end())
748        {
749            encode_arg(buf, iter->first);
750            encode_arg(buf, iter->second);
751            iter++;
752        }
753        return true;
754    }
755
756    template<typename K, typename V>
757    inline bool encode_arg(Buffer& buf, btree::btree_map<K, V>& a0)
758    {
759        BufferHelper::WriteVarUInt32(buf, a0.size());
760        typename btree::btree_map<K, V>::iterator iter = a0.begin();
761        while (iter != a0.end())
762        {
763            encode_arg(buf, iter->first);
764            encode_arg(buf, iter->second);
765            iter++;
766        }
767        return true;
768    }
769
770    template<typename T>
771    inline bool decode_arg(Buffer& buf, std::list<T>& a0)
772    {
773        uint32 size;
774        if (!BufferHelper::ReadVarUInt32(buf, size))
775        {
776            return false;
777        }
778        uint32 i = 0;
779        while (i < size)
780        {
781            T t;
782            if (!decode_arg(buf, t))
783            {
784                return false;
785            }
786            a0.push_back(t);
787            i++;
788        }
789        return true;
790    }
791
792    template<typename T>
793    inline bool decode_arg(Buffer& buf, std::set<T>& a0)
794    {
795        uint32 size;
796        if (!BufferHelper::ReadVarUInt32(buf, size))
797        {
798            return false;
799        }
800        uint32 i = 0;
801        while (i < size)
802        {
803            T t;
804            if (!decode_arg(buf, t))
805            {
806                return false;
807            }
808            a0.insert(t);
809            i++;
810        }
811        return true;
812    }
813
814    template<typename T>
815    inline bool decode_arg(Buffer& buf, btree::btree_set<T>& a0)
816    {
817        uint32 size;
818        if (!BufferHelper::ReadVarUInt32(buf, size))
819        {
820            return false;
821        }
822        uint32 i = 0;
823        while (i < size)
824        {
825            T t;
826            if (!decode_arg(buf, t))
827            {
828                return false;
829            }
830            a0.insert(t);
831            i++;
832        }
833        return true;
834    }
835
836    template<typename T>
837    inline bool decode_arg(Buffer& buf, std::vector<T>& a0)
838    {
839        uint32 size;
840        if (!BufferHelper::ReadVarUInt32(buf, size))
841        {
842            return false;
843        }
844        uint32 i = 0;
845        while (i < size)
846        {
847            T t;
848            if (!decode_arg(buf, t))
849            {
850                return false;
851            }
852            a0.push_back(t);
853            i++;
854        }
855        return true;
856    }
857
858    template<typename T>
859    inline bool decode_arg(Buffer& buf, std::deque<T>& a0)
860    {
861        uint32 size;
862        if (!BufferHelper::ReadVarUInt32(buf, size))
863        {
864            return false;
865        }
866        uint32 i = 0;
867        while (i < size)
868        {
869            T t;
870            if (!decode_arg(buf, t))
871            {
872                return false;
873            }
874            a0.push_back(t);
875            i++;
876        }
877        return true;
878    }
879
880    template<typename K, typename V>
881    inline bool decode_arg(Buffer& buf, std::map<K, V>& a0)
882    {
883        uint32 size;
884        if (!BufferHelper::ReadVarUInt32(buf, size))
885        {
886            return false;
887        }
888        uint32 i = 0;
889        while (i < size)
890        {
891            K k;
892            V v;
893            if (!decode_arg(buf, k) || !decode_arg(buf, v))
894            {
895                return false;
896            }
897            a0.insert(std::make_pair(k, v));
898            i++;
899        }
900        return true;
901    }
902
903    template<typename K, typename V>
904    inline bool decode_arg(Buffer& buf, btree::btree_map<K, V>& a0)
905    {
906        uint32 size;
907        if (!BufferHelper::ReadVarUInt32(buf, size))
908        {
909            return false;
910        }
911        uint32 i = 0;
912        while (i < size)
913        {
914            K k;
915            V v;
916            if (!decode_arg(buf, k) || !decode_arg(buf, v))
917            {
918                return false;
919            }
920            a0.insert(std::make_pair(k, v));
921            i++;
922        }
923        return true;
924    }
925
926}
927
928#endif /* STRUCT_CODEC_MACROS_HPP_ */