From cb791482a00fed6e36310b970562fafa3bdd3c37 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 29 Jun 2015 14:01:31 -0700 Subject: [PATCH] Serializer improvements: * Add getSlice() * Make getVLDataLength public --- src/ripple/protocol/Serializer.h | 12 +++++++++--- src/ripple/protocol/impl/Serializer.cpp | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ripple/protocol/Serializer.h b/src/ripple/protocol/Serializer.h index d6c851e46..05aea17e6 100644 --- a/src/ripple/protocol/Serializer.h +++ b/src/ripple/protocol/Serializer.h @@ -353,6 +353,15 @@ public: void getFieldID (int& type, int& name); + // Returns the size of the VL if the + // next object is a VL. Advances the iterator + // to the beginning of the VL. + int + getVLDataLength (); + + Slice + getSlice (std::size_t bytes); + // VFALCO DEPRECATED Returns a copy Blob getRaw (int size); @@ -364,9 +373,6 @@ public: Buffer getVLBuffer(); -private: - int getVLDataLength (); - template T getRawHelper (int size); }; diff --git a/src/ripple/protocol/impl/Serializer.cpp b/src/ripple/protocol/impl/Serializer.cpp index 63d39472a..d1d5e35bc 100644 --- a/src/ripple/protocol/impl/Serializer.cpp +++ b/src/ripple/protocol/impl/Serializer.cpp @@ -575,6 +575,19 @@ int SerialIter::getVLDataLength () return datLen; } +Slice +SerialIter::getSlice (std::size_t bytes) +{ + if (bytes > remain_) + throw std::runtime_error( + "invalid SerialIter getSlice"); + Slice s(p_, bytes); + p_ += bytes; + used_ += bytes; + remain_ -= bytes; + return s; +} + // VFALCO DEPRECATED Returns a copy Blob SerialIter::getVL()