summaryrefslogtreecommitdiffstats
path: root/frtstream
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /frtstream
Publish
Diffstat (limited to 'frtstream')
-rw-r--r--frtstream/.gitignore2
-rw-r--r--frtstream/CMakeLists.txt12
-rw-r--r--frtstream/OWNERS1
-rw-r--r--frtstream/docs/introduction.txt27
-rw-r--r--frtstream/src/.gitignore4
-rw-r--r--frtstream/src/example/.gitignore3
-rw-r--r--frtstream/src/example/CMakeLists.txt2
-rw-r--r--frtstream/src/example/simple.cpp45
-rw-r--r--frtstream/src/example/test.cpp74
-rw-r--r--frtstream/src/vespa/frtstream/.gitignore2
-rw-r--r--frtstream/src/vespa/frtstream/CMakeLists.txt7
-rw-r--r--frtstream/src/vespa/frtstream/frtclientstream.cpp57
-rw-r--r--frtstream/src/vespa/frtstream/frtclientstream.h40
-rw-r--r--frtstream/src/vespa/frtstream/frtserverstream.h31
-rw-r--r--frtstream/src/vespa/frtstream/frtstream.cpp65
-rw-r--r--frtstream/src/vespa/frtstream/frtstream.h95
-rw-r--r--frtstream/src/vespa/frtstream/frtstreamTemplateImp.hpp203
17 files changed, 670 insertions, 0 deletions
diff --git a/frtstream/.gitignore b/frtstream/.gitignore
new file mode 100644
index 00000000000..a9b20e8992d
--- /dev/null
+++ b/frtstream/.gitignore
@@ -0,0 +1,2 @@
+Makefile
+Testing
diff --git a/frtstream/CMakeLists.txt b/frtstream/CMakeLists.txt
new file mode 100644
index 00000000000..49a299926ec
--- /dev/null
+++ b/frtstream/CMakeLists.txt
@@ -0,0 +1,12 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_define_module(
+ DEPENDS
+ fastos
+ fnet
+
+ LIBS
+ src/vespa/frtstream
+
+ TESTS
+ src/example
+)
diff --git a/frtstream/OWNERS b/frtstream/OWNERS
new file mode 100644
index 00000000000..31af040f698
--- /dev/null
+++ b/frtstream/OWNERS
@@ -0,0 +1 @@
+bratseth
diff --git a/frtstream/docs/introduction.txt b/frtstream/docs/introduction.txt
new file mode 100644
index 00000000000..d733d7be0da
--- /dev/null
+++ b/frtstream/docs/introduction.txt
@@ -0,0 +1,27 @@
+FrtStream provides an iostream like interface to Frt. It consists of
+two main parts: FrtClientStream and FrtServerStream. Both streams can
+read/write integers, floating point numbers, strings(std), and
+standard c++ containers containing these types. Other types can be
+added by operator overloading.( like for iostreams )
+
+FrtClientStream
+This is a complete abstraction for making simple Frt clients.
+It's used the following way:
+
+FrtClientStream s(<connectionSpec>);
+s <<Method(<methodName>) <<param1 <<param2 ... <<paramN;
+s >> result1 >>result2 ... >>resultn
+
+s <<Method(<methodName2>) ...
+
+
+
+FrtServerStream
+This is currently only a wrapper to use around Request
+objects on the server to ease working with parameters and return
+values. It's used inside method handlers by making a FrtServerStream
+on the stack and passing the request object to it's constructor:
+
+FrtServerStream s(request);
+s >>param1 >>param2 .... >>paramn
+s <<return1 <<return2 ... <<returnn.
diff --git a/frtstream/src/.gitignore b/frtstream/src/.gitignore
new file mode 100644
index 00000000000..d7136fc6881
--- /dev/null
+++ b/frtstream/src/.gitignore
@@ -0,0 +1,4 @@
+Makefile.ini
+config_command.sh
+frtstream.mak
+project.dsw
diff --git a/frtstream/src/example/.gitignore b/frtstream/src/example/.gitignore
new file mode 100644
index 00000000000..56ab7d7b794
--- /dev/null
+++ b/frtstream/src/example/.gitignore
@@ -0,0 +1,3 @@
+Makefile
+test
+/.depend
diff --git a/frtstream/src/example/CMakeLists.txt b/frtstream/src/example/CMakeLists.txt
new file mode 100644
index 00000000000..2a9a5f6cc47
--- /dev/null
+++ b/frtstream/src/example/CMakeLists.txt
@@ -0,0 +1,2 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Ignored!
diff --git a/frtstream/src/example/simple.cpp b/frtstream/src/example/simple.cpp
new file mode 100644
index 00000000000..000a9edbc8f
--- /dev/null
+++ b/frtstream/src/example/simple.cpp
@@ -0,0 +1,45 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <iostream>
+#include <csignal>
+#include <vector>
+#include <string>
+#include <set>
+
+#include <vespa/frtstream/frtclientstream.h>
+
+
+using namespace std;
+using frtstream::FrtClientStream;
+using frtstream::Method;
+using frtstream::InvokationException;
+
+const string connectionSpec = "tcp/test-tonyv:9997";
+
+class TestApp : public FastOS_Application {
+public:
+ int Main() {
+ FrtClientStream s(connectionSpec);
+
+ try {
+ s <<Method("add") <<1 <<2;
+
+ int res;
+ s >> res;
+
+ cout <<"Result = " <<res <<endl;
+ } catch(const InvokationException& e) {
+ cerr <<e <<endl;
+ }
+ return 0;
+
+ }
+};
+
+
+int main(int argc, char** argv) {
+ TestApp app;
+ return app.Entry(argc, argv);
+
+
+}
diff --git a/frtstream/src/example/test.cpp b/frtstream/src/example/test.cpp
new file mode 100644
index 00000000000..5af115f9978
--- /dev/null
+++ b/frtstream/src/example/test.cpp
@@ -0,0 +1,74 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <iostream>
+#include <csignal>
+#include <vector>
+#include <string>
+#include <set>
+
+#include <vespa/frtstream/frtclientstream.h>
+
+
+using namespace std;
+using frtstream::FrtClientStream;
+using frtstream::Method;
+using frtstream::InvokationException;
+
+const string connectionSpec = "tcp/test-tonyv:9997";
+
+class TestApp : public FastOS_Application {
+public:
+ int Main() {
+ FrtClientStream s(connectionSpec);
+
+ std::vector<std::string> vec;
+ vec.push_back("Hello"); vec.push_back("world");
+
+ std::set<std::string> codeSet;
+ codeSet.insert("abc"); codeSet.insert("def");
+
+ std::vector<double> doubleVec;
+ doubleVec.push_back(99.98); doubleVec.push_back(98.97);
+
+ std::vector<float> floatVec;
+ floatVec.push_back(99.98); floatVec.push_back(98.97);
+
+ uint8_t i1 = 1;
+ int8_t i2 = 2;
+
+ uint16_t i3 = 1;
+ int16_t i4 = 2;
+
+ uint32_t i5 = 1;
+ int32_t i6 = 2;
+
+ uint64_t i7 = 1;
+ int64_t i8 = 2;
+
+ float f1 = 3.14;
+ double d1 = 123.456;
+
+ try {
+ s <<Method("add") <<1 <<2 <<i1 <<f1 <<d1 <<vec <<codeSet <<doubleVec <<floatVec
+ <<i1 <<i2 <<i3 <<i4 <<i5 <<i6 <<i7 <<i8;
+
+ int res;
+ s >> res >>vec >>codeSet >>doubleVec >>floatVec >>i1 >>f1 >>d1
+ >>i1 >>i2 >>i3 >>i4 >>i5 >>i6 >>i7 >>i8;
+
+ cout <<"Result = " <<res <<endl;
+ } catch(const InvokationException& e) {
+ cerr <<e <<endl;
+ }
+ return 0;
+
+ }
+};
+
+
+int main(int argc, char** argv) {
+ TestApp app;
+ return app.Entry(argc, argv);
+
+
+}
diff --git a/frtstream/src/vespa/frtstream/.gitignore b/frtstream/src/vespa/frtstream/.gitignore
new file mode 100644
index 00000000000..5dae353d999
--- /dev/null
+++ b/frtstream/src/vespa/frtstream/.gitignore
@@ -0,0 +1,2 @@
+.depend
+Makefile
diff --git a/frtstream/src/vespa/frtstream/CMakeLists.txt b/frtstream/src/vespa/frtstream/CMakeLists.txt
new file mode 100644
index 00000000000..046118a9204
--- /dev/null
+++ b/frtstream/src/vespa/frtstream/CMakeLists.txt
@@ -0,0 +1,7 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_library(frtstream STATIC
+ SOURCES
+ frtclientstream.cpp
+ frtstream.cpp
+ DEPENDS
+)
diff --git a/frtstream/src/vespa/frtstream/frtclientstream.cpp b/frtstream/src/vespa/frtstream/frtclientstream.cpp
new file mode 100644
index 00000000000..5c8de136fd4
--- /dev/null
+++ b/frtstream/src/vespa/frtstream/frtclientstream.cpp
@@ -0,0 +1,57 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/frtstream/frtclientstream.h>
+
+
+using namespace fnet;
+
+
+namespace frtstream {
+
+FrtClientStream::FrtClientStream(const std::string& connectionSpec)
+ : timeout(30),
+ executed(false),
+ _nextOutValue(0)
+
+{
+ supervisor.Start();
+ target = supervisor.GetTarget(connectionSpec.c_str());
+ if( ! target ) {
+ supervisor.ShutDown(true);
+ throw ConnectionException();
+ }
+ request = supervisor.AllocRPCRequest();
+}
+
+FrtClientStream::~FrtClientStream() {
+ request->SubRef();
+ target->SubRef();
+ supervisor.ShutDown(true);
+}
+
+FrtClientStream& FrtClientStream::operator<<(const Method& m) {
+ executed = false;
+ request = supervisor.AllocRPCRequest(request);
+ request->SetMethodName(m.name().c_str());
+
+ return *this;
+}
+
+FRT_Values& FrtClientStream::in() {
+ return *request->GetParams();
+}
+FRT_Value& FrtClientStream::nextOut() {
+ if(! executed ) {
+ target->InvokeSync(request, timeout);
+ executed = true;
+ _nextOutValue = 0;
+ if( request->GetErrorCode() != FRTE_NO_ERROR ) {
+ throw InvokationException(request->GetErrorCode(),
+ request->GetErrorMessage());
+ }
+ }
+ return request->GetReturn()->GetValue(_nextOutValue++);
+}
+
+
+} //end namespace frtstream
diff --git a/frtstream/src/vespa/frtstream/frtclientstream.h b/frtstream/src/vespa/frtstream/frtclientstream.h
new file mode 100644
index 00000000000..27d1f36b780
--- /dev/null
+++ b/frtstream/src/vespa/frtstream/frtclientstream.h
@@ -0,0 +1,40 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+//Requires gcc 3 or higher
+#if ! defined(__GNUC__) || (__GNUC__ > 2)
+
+
+#include <vespa/frtstream/frtstream.h>
+
+
+namespace frtstream {
+
+
+class FrtClientStream : public FrtStream {
+ FRT_Supervisor supervisor;
+ FRT_RPCRequest* request;
+ const double timeout;
+
+ FRT_Target* target;
+ bool executed;
+ uint32_t _nextOutValue;
+
+ FRT_Values& in();
+ FRT_Value& nextOut();
+public:
+ FrtClientStream(const std::string& connectionSpec);
+ ~FrtClientStream();
+
+ using FrtStream::operator<<;
+ using FrtStream::operator>>;
+ FrtClientStream& operator<<(const Method& m);
+};
+
+} //end namespace frtstream
+
+#else
+#error "Requires gcc 3 or higher"
+#endif
+
diff --git a/frtstream/src/vespa/frtstream/frtserverstream.h b/frtstream/src/vespa/frtstream/frtserverstream.h
new file mode 100644
index 00000000000..138c45aab50
--- /dev/null
+++ b/frtstream/src/vespa/frtstream/frtserverstream.h
@@ -0,0 +1,31 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+#include <vespa/frtstream/frtstream.h>
+
+namespace frtstream {
+
+class FrtServerStream : public FrtStream {
+ FRT_RPCRequest* request;
+ uint32_t _nextOutValue;
+
+ FRT_Values& in() {
+ return *request->GetReturn();
+ }
+
+ FRT_Value& nextOut() {
+ return request->GetParams()->GetValue(_nextOutValue++);
+ }
+public:
+ FrtServerStream(FRT_RPCRequest* req) :
+ request(req),
+ _nextOutValue(0) {}
+
+ using FrtStream::operator<<;
+ using FrtStream::operator>>;
+
+};
+
+
+} //end namespace frtstream
+
diff --git a/frtstream/src/vespa/frtstream/frtstream.cpp b/frtstream/src/vespa/frtstream/frtstream.cpp
new file mode 100644
index 00000000000..f4b1b9ddd7e
--- /dev/null
+++ b/frtstream/src/vespa/frtstream/frtstream.cpp
@@ -0,0 +1,65 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <algorithm>
+
+
+#include <vespa/frtstream/frtstream.h>
+
+using namespace fnet;
+
+namespace frtstream {
+
+
+
+#define _FRTSTREAM_INTEGER_OPERATOR(bits) \
+FrtStream& FrtStream::operator<<(uint##bits##_t i) { \
+ in().AddInt##bits(i); \
+ return *this; \
+} \
+FrtStream& FrtStream::operator>>(uint##bits##_t &i) { \
+ i = nextOut()._intval##bits; \
+ return *this; \
+}
+
+_FRTSTREAM_INTEGER_OPERATOR(8);
+_FRTSTREAM_INTEGER_OPERATOR(16);
+_FRTSTREAM_INTEGER_OPERATOR(32);
+_FRTSTREAM_INTEGER_OPERATOR(64);
+#undef _FRTSTREAM_INTEGER_OPERATOR
+
+#define _FRTSTREAM_FLOAT_OPERATOR(floatType, floatTypeCapitalized) \
+FrtStream& FrtStream::operator<<(floatType i) { \
+ in().Add##floatTypeCapitalized(i); \
+ return *this; \
+} \
+FrtStream& FrtStream::operator>>(floatType &i) { \
+ i = nextOut()._##floatType; \
+ return *this; \
+}
+
+_FRTSTREAM_FLOAT_OPERATOR(float, Float);
+_FRTSTREAM_FLOAT_OPERATOR(double, Double);
+#undef _FRTSTREAM_FLOAT_OPERATOR
+
+FrtStream& FrtStream::operator<<(const std::string &str) {
+ in().AddString(str.c_str());
+ return *this;
+}
+
+FrtStream& FrtStream::operator>>(std::string &str) {
+ str = nextOut()._string._str;
+ return *this;
+}
+
+
+std::ostream& operator<<(std::ostream& s, const InvokationException& e) {
+ s <<"InvocationException: " <<std::endl
+ <<"ErrorCode: " <<e.errorCode <<std::endl
+ <<"ErrorMessage: " <<e.errorMessage;
+ return s;
+}
+
+
+
+
+} //end namespace frtstream
diff --git a/frtstream/src/vespa/frtstream/frtstream.h b/frtstream/src/vespa/frtstream/frtstream.h
new file mode 100644
index 00000000000..55ee2870f38
--- /dev/null
+++ b/frtstream/src/vespa/frtstream/frtstream.h
@@ -0,0 +1,95 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+#include <string>
+#include <memory>
+#include <algorithm>
+#include <iostream>
+#include <iterator>
+
+#include <vespa/fastos/fastos.h>
+#include <vespa/fastos/types.h>
+#include <vespa/fnet/frt/frt.h>
+
+
+namespace frtstream {
+class ConnectionException{};
+class InvokationException{
+public:
+
+ uint32_t errorCode;
+ std::string errorMessage;
+ InvokationException(uint32_t code, const std::string& msg ):
+ errorCode(code), errorMessage(msg) {}
+};
+
+std::ostream& operator<<(std::ostream& s, const InvokationException& e);
+
+
+class Method {
+ std::string _name;
+public:
+ Method(const std::string& methodName) :
+ _name(methodName) {}
+ //implement in the future along with typechecking
+ //Method(const std::string& name, const std::string& typeString);
+
+ std::string name() const {
+ return _name;
+ }
+};
+
+class FrtStream {
+protected:
+ virtual FRT_Values& in() = 0;
+ virtual FRT_Value& nextOut() = 0;
+
+public:
+ virtual ~FrtStream() {}
+
+#define _FRTSTREAM_INTOPERATOR(bits) \
+ FrtStream& operator<<(uint##bits##_t); \
+ FrtStream& operator>>(uint##bits##_t&); \
+ FrtStream& operator<<(int##bits##_t val) { \
+ operator<<(static_cast<uint##bits##_t>(val)); \
+ return *this; \
+ } \
+ FrtStream& operator>>(int##bits##_t &val) { \
+ uint##bits##_t temp; \
+ *this>>temp; \
+ val = static_cast<int##bits##_t>(val); \
+ return *this; \
+ }
+
+ _FRTSTREAM_INTOPERATOR(8);
+ _FRTSTREAM_INTOPERATOR(16);
+ _FRTSTREAM_INTOPERATOR(32);
+ _FRTSTREAM_INTOPERATOR(64);
+#undef _FRTSTREAM_INTOPERATOR
+
+ FrtStream& operator<<(float);
+ FrtStream& operator>>(float&);
+
+ FrtStream& operator<<(double);
+ FrtStream& operator>>(double&);
+
+ FrtStream& operator<<(const std::string &str);
+ FrtStream& operator>>(std::string &str);
+
+ FrtStream& operator<<(std::string &str);
+
+ template <template<typename, typename> class CONT, class T, class ALLOC>
+ FrtStream& operator<<( const CONT<T, ALLOC> & cont );
+
+ template <template<typename, typename> class CONT, class T, class ALLOC>
+ FrtStream& operator>>( CONT<T, ALLOC> & cont );
+};
+
+
+
+
+} //end namespace frtstream
+
+
+#include "frtstreamTemplateImp.hpp"
+
diff --git a/frtstream/src/vespa/frtstream/frtstreamTemplateImp.hpp b/frtstream/src/vespa/frtstream/frtstreamTemplateImp.hpp
new file mode 100644
index 00000000000..4577f8a7e78
--- /dev/null
+++ b/frtstream/src/vespa/frtstream/frtstreamTemplateImp.hpp
@@ -0,0 +1,203 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+//template functions that must be included in the
+//header file, since the full definition needs to be
+//available to users.
+//Can be moved when(if ever) the export functionality
+//is implemented in the target compiler.
+
+
+namespace frtstream {
+
+template<class U>
+struct FrtStreamConverter{
+ typedef U type;
+ typedef U serializationType;
+
+ static const serializationType& convertTo(const U& u) {
+ return u;
+ }
+ static const U& convertFrom(const serializationType& s) {
+ return s;
+ }
+
+};
+
+//signed conversion
+#define _FRTSTREAM_CONVERTUNSIGNED_(signedType) \
+template <> \
+struct FrtStreamConverter< signedType > { \
+ typedef u##signedType serializationType; \
+\
+ static serializationType convertTo(signedType u) { \
+ return static_cast< serializationType >(u); \
+ } \
+ static signedType convertFrom(serializationType s) { \
+ return static_cast< signedType >(s); \
+ } \
+};
+
+_FRTSTREAM_CONVERTUNSIGNED_(int8_t);
+_FRTSTREAM_CONVERTUNSIGNED_(int16_t);
+_FRTSTREAM_CONVERTUNSIGNED_(int32_t);
+_FRTSTREAM_CONVERTUNSIGNED_(int64_t);
+
+#undef _FRTSTREAM_CONVERTUNSIGNED_
+//end signed conversion
+
+
+template<class T>
+struct FrtArray {
+ T* _pt;
+ uint32_t _len;
+};
+
+
+//ArrayTypeUtil
+
+//Little ugly hack to avoid code duplication
+//Needed since template based approach failed
+//to work because of anonymous type.
+#define _FRTSTREAM_FILLARRAY(arr, prefix) \
+arr._pt = prefix._pt; \
+arr._len = prefix._len;
+
+
+void PleaseAddSpecializationForYourType();
+
+template <class SerializationType>
+struct ArrayTypeUtil {
+ template <class Converter, class Cont>
+ static void addArray(FRT_Values& value, const Cont& c) {
+ frtstream::PleaseAddSpecializationForYourType();
+ }
+
+ static void getArray(FRT_Value& value) {
+ frtstream::PleaseAddSpecializationForYourType();
+ }
+};
+
+template <>
+struct ArrayTypeUtil<std::string> {
+ template<class Converter>
+ struct AddString{
+ FRT_StringValue* ptr;
+ FRT_Values& values;
+
+ AddString(FRT_StringValue* start, FRT_Values& val) :
+ ptr(start), values(val) {}
+ void operator()(const typename Converter::type& s) {
+ values.SetString(ptr++, Converter::convertTo(s).c_str());
+ }
+ };
+
+
+ template <class Converter, class Cont>
+ static void addArray(FRT_Values& value, const Cont& c) {
+ FRT_StringValue* start = value.AddStringArray(c.size());
+ std::for_each(c.begin(), c.end(), AddString<Converter>(start, value));
+
+ }
+ static FrtArray<FRT_StringValue> getArray(FRT_Value& value) {
+ FrtArray<FRT_StringValue> arr;
+ _FRTSTREAM_FILLARRAY(arr, value._string_array);
+ return arr;
+ }
+
+};
+
+#define _FRTSTREAM_ARRAYTYPE_UTIL_FLOAT(floatType, floatTypeCapitalized) \
+template <> \
+struct ArrayTypeUtil<floatType> { \
+ template <class Converter, class Cont> \
+ static void addArray(FRT_Values& values, const Cont & cont) { \
+ floatType* startPtr = values.Add##floatTypeCapitalized##Array(cont.size()); \
+ std::transform(cont.begin(), cont.end(), startPtr, Converter::convertTo); \
+ } \
+ static FrtArray<floatType> getArray(FRT_Value& value) { \
+ FrtArray<floatType> arr; \
+ _FRTSTREAM_FILLARRAY(arr, value._##floatType##_array); \
+ return arr; \
+ } \
+};
+
+_FRTSTREAM_ARRAYTYPE_UTIL_FLOAT(float, Float);
+_FRTSTREAM_ARRAYTYPE_UTIL_FLOAT(double, Double);
+#undef _FRTSTREAM_ARRAYTYPE_UTIL_FLOAT
+
+#define _FRTSTREAM_ARRAYTYPE_UTIL_INT(bits) \
+template <> \
+struct ArrayTypeUtil<uint##bits##_t> { \
+ template <class Converter, class Cont> \
+ static void addArray(FRT_Values& values, const Cont & cont) { \
+ uint##bits##_t* startPtr = values.AddInt##bits##Array(cont.size()); \
+ std::transform(cont.begin(), cont.end(), startPtr, \
+ Converter::convertTo); \
+ } \
+\
+ static FrtArray<uint##bits##_t> getArray(FRT_Value& value) { \
+ FrtArray<uint##bits##_t> arr; \
+ _FRTSTREAM_FILLARRAY(arr, value._int##bits##_array); \
+ return arr; \
+ } \
+};
+
+_FRTSTREAM_ARRAYTYPE_UTIL_INT(8);
+_FRTSTREAM_ARRAYTYPE_UTIL_INT(16);
+_FRTSTREAM_ARRAYTYPE_UTIL_INT(32);
+_FRTSTREAM_ARRAYTYPE_UTIL_INT(64);
+#undef _FRTSTREAM_ARRAYTYPE_UTIL_INT
+
+#undef _FRTSTREAM_FILLARRAY
+//End ArrayTypeUtil
+
+//ArrayReader
+template <class T>
+struct ArrayReader {
+ template<class Converter, class Iter, class ArrayImp>
+ static void read(Iter dest, ArrayImp arr) {
+ std::transform( arr._pt, arr._pt + arr._len, dest,
+ Converter::convertFrom );
+
+ }
+};
+
+template <>
+struct ArrayReader<std::string> {
+ template<class Converter, class Iter, class ArrayImp>
+ static void read(Iter dest, ArrayImp arr) {
+ FRT_StringValue* ptr = arr._pt;
+ for(uint32_t i = 0; i < arr._len; i++ ) {
+ *dest++ = Converter::convertFrom(ptr++ ->_str);
+ }
+ }
+};
+
+
+
+//End ArrayReader
+
+
+template <template<typename, typename> class CONT, class T, class ALLOC>
+FrtStream& FrtStream::operator<<( const CONT<T, ALLOC> & cont ) {
+ typedef FrtStreamConverter<typename CONT<T, ALLOC>::value_type> Converter;
+ typedef typename FrtStreamConverter<typename CONT<T, ALLOC>::value_type>::serializationType SerializationType;
+
+ frtstream::ArrayTypeUtil<SerializationType>::template addArray<Converter>(in(), cont);
+
+ return *this;
+}
+
+
+
+template <template<typename, typename> class CONT, class T, class ALLOC>
+FrtStream& FrtStream::operator>>( CONT<T, ALLOC> & cont ) {
+ typedef FrtStreamConverter<typename CONT<T, ALLOC>::value_type> Converter;
+ typedef typename FrtStreamConverter<typename CONT<T, ALLOC>::value_type>::serializationType SerializationType;
+
+ ArrayReader<SerializationType>::template read<Converter>( std::inserter(cont, cont.end()),
+ ArrayTypeUtil<SerializationType>::getArray(nextOut()) );
+
+ return *this;
+}
+
+} //end namespace frtstream