@@ -503,7 +503,7 @@ static inline Wrapper<Formatter, T&> Using(T&& t) { return Wrapper<Formatter, T&
503503#define VARINT_MODE (obj, mode ) Using<VarIntFormatter<mode>>(obj)
504504#define VARINT (obj ) Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj)
505505#define COMPACTSIZE (obj ) Using<CompactSizeFormatter>(obj)
506- #define LIMITED_STRING (obj,n ) LimitedString< n >(REF( obj) )
506+ #define LIMITED_STRING (obj,n ) Using<LimitedStringFormatter<n>>( obj)
507507
508508/* * Serialization wrapper class for integers in VarInt format. */
509509template <VarIntMode Mode>
@@ -588,31 +588,23 @@ struct CompactSizeFormatter
588588};
589589
590590template <size_t Limit>
591- class LimitedString
591+ struct LimitedStringFormatter
592592{
593- protected:
594- std::string& string;
595- public:
596- explicit LimitedString (std::string& _string) : string(_string) {}
597-
598593 template <typename Stream>
599- void Unserialize (Stream& s)
594+ void Unser (Stream& s, std::string& v )
600595 {
601596 size_t size = ReadCompactSize (s);
602597 if (size > Limit) {
603598 throw std::ios_base::failure (" String length limit exceeded" );
604599 }
605- string.resize (size);
606- if (size != 0 )
607- s.read ((char *)string.data (), size);
600+ v.resize (size);
601+ if (size != 0 ) s.read ((char *)v.data (), size);
608602 }
609603
610604 template <typename Stream>
611- void Serialize (Stream& s) const
605+ void Ser (Stream& s, const std::string& v)
612606 {
613- WriteCompactSize (s, string.size ());
614- if (!string.empty ())
615- s.write ((char *)string.data (), string.size ());
607+ s << v;
616608 }
617609};
618610
0 commit comments