about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/serialise.cc32
-rw-r--r--src/libutil/serialise.hh8
2 files changed, 39 insertions, 1 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 92417507508a..aa16a20e6d35 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -155,6 +155,12 @@ void writeInt(unsigned int n, Sink & sink)
     sink(buf, sizeof(buf));
 }
 
+Sink & operator << (Sink & out, unsigned int n)
+{
+    writeInt(n, out);
+    return out;
+}
+
 
 void writeLongLong(unsigned long long n, Sink & sink)
 {
@@ -184,6 +190,12 @@ void writeString(const string & s, Sink & sink)
     writeString((const unsigned char *) s.data(), s.size(), sink);
 }
 
+Sink & operator << (Sink & out, const string & s)
+{
+    writeString(s, out);
+    return out;
+}
+
 
 template<class T> void writeStrings(const T & ss, Sink & sink)
 {
@@ -195,6 +207,18 @@ template<class T> void writeStrings(const T & ss, Sink & sink)
 template void writeStrings(const Paths & ss, Sink & sink);
 template void writeStrings(const PathSet & ss, Sink & sink);
 
+Sink & operator << (Sink & out, const Strings & s)
+{
+    writeStrings(s, out);
+    return out;
+}
+
+Sink & operator << (Sink & out, const StringSet & s)
+{
+    writeStrings(s, out);
+    return out;
+}
+
 
 void readPadding(size_t len, Source & source)
 {
@@ -258,7 +282,13 @@ string readString(Source & source)
     return string((char *) buf, len);
 }
 
- 
+Source & operator >> (Source & in, string & s)
+{
+    s = readString(in);
+    return in;
+}
+
+
 template<class T> T readStrings(Source & source)
 {
     unsigned int count = readInt(source);
diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh
index 6a6f028aa652..3a20ad032254 100644
--- a/src/libutil/serialise.hh
+++ b/src/libutil/serialise.hh
@@ -118,6 +118,12 @@ void writeString(const unsigned char * buf, size_t len, Sink & sink);
 void writeString(const string & s, Sink & sink);
 template<class T> void writeStrings(const T & ss, Sink & sink);
 
+Sink & operator << (Sink & out, unsigned int n);
+Sink & operator << (Sink & out, const string & s);
+Sink & operator << (Sink & out, const Strings & s);
+Sink & operator << (Sink & out, const StringSet & s);
+
+
 void readPadding(size_t len, Source & source);
 unsigned int readInt(Source & source);
 unsigned long long readLongLong(Source & source);
@@ -125,6 +131,8 @@ size_t readString(unsigned char * buf, size_t max, Source & source);
 string readString(Source & source);
 template<class T> T readStrings(Source & source);
 
+Source & operator >> (Source & in, string & s);
+
 
 MakeError(SerialisationError, Error)