diff --git a/lib/cpp/protocol/TBinaryProtocol.cc b/lib/cpp/protocol/TBinaryProtocol.cc
index 4c10bab..1f31c8d 100644
--- a/lib/cpp/protocol/TBinaryProtocol.cc
+++ b/lib/cpp/protocol/TBinaryProtocol.cc
@@ -1,140 +1,246 @@
 #include "protocol/TBinaryProtocol.h"
-using namespace std;
+using std::string;
 
-string TBinaryProtocol::readFunction(TBuf& buf) const {
-  // Let readString increment the buffer position
-  return readString(buf);
+uint32_t TBinaryProtocol::writeStructBegin(TTransport* out,
+                                           const string& name) const {
+  return 0;
 }
 
-string TBinaryProtocol::writeFunction(const string& name,
-                                      const string& args) const{
-  return writeString(name) + args;
+uint32_t TBinaryProtocol::writeStructEnd(TTransport* out) const {
+  return 0;
 }
 
-map<uint32_t, TBuf> TBinaryProtocol::readStruct(TBuf& buf) const {
-  map<uint32_t, TBuf> fieldMap;
+uint32_t TBinaryProtocol::writeFieldBegin(TTransport* out,
+                                          const string& name,
+                                          const TType fieldType,
+                                          const uint16_t fieldId) const {
+  return
+    writeByte(out, (uint8_t)fieldType) +
+    writeU32(out, (uint32_t)fieldId);
+}
+
+uint32_t TBinaryProtocol::writeFieldEnd(TTransport* out) const {
+  return 0;
+}
+
+uint32_t TBinaryProtocol::writeFieldStop(TTransport* out) const {
+  return
+    writeByte(out, (uint8_t)T_STOP);
+}  
+                               
+uint32_t TBinaryProtocol::writeMapBegin(TTransport* out,
+                                        const TType keyType,
+                                        const TType valType,
+                                        const uint32_t size) const {
+  return
+    writeByte(out, (uint8_t)keyType) +
+    writeByte(out, (uint8_t)valType) +
+    writeU32(out, size);
+}
+
+uint32_t TBinaryProtocol::writeMapEnd(TTransport* out) const {
+  return 0;
+}
+
+uint32_t TBinaryProtocol::writeListBegin(TTransport* out,
+                                         const TType elemType,
+                                         const uint32_t size) const {
+  return
+    writeByte(out, (uint8_t) elemType) +
+    writeU32(out, size);
+}
+
+uint32_t TBinaryProtocol::writeListEnd(TTransport* out) const {
+  return 0;
+}
+
+uint32_t TBinaryProtocol::writeSetBegin(TTransport* out,
+                                        const TType elemType,
+                                        const uint32_t size) const {
+  return
+    writeByte(out, (uint8_t)elemType) +
+    writeU32(out, size);
+}
+
+uint32_t TBinaryProtocol::writeSetEnd(TTransport* out) const {
+  return 0;
+}
+
+uint32_t TBinaryProtocol::writeByte(TTransport* out,
+                                    const uint8_t byte) const {
+  out->write(&byte, 1);
+  return 1;
+}
+
+uint32_t TBinaryProtocol::writeU32(TTransport* out,
+                                   const uint32_t u32) const {
+  uint32_t net = (uint32_t)htonl(u32);
+  out->write((uint8_t*)&net, 4);
+  return 4;
+}
+
+uint32_t TBinaryProtocol::writeI32(TTransport* out,
+                                   const int32_t i32) const {
+  int32_t net = (int32_t)htonl(i32);
+  out->write((uint8_t*)&net, 4);
+  return 4;
+}
+
+uint32_t TBinaryProtocol::writeU64(TTransport* out,
+                                   const uint64_t u64) const {
+  uint64_t net = (uint64_t)htonll(u64);
+  out->write((uint8_t*)&net, 8);
+  return 8;
+}
+
+uint32_t TBinaryProtocol::writeI64(TTransport* out,
+                                   const int64_t i64) const {
+  int64_t net = (int64_t)htonll(i64);
+  out->write((uint8_t*)&net, 8);
+  return 8;
+}
+
+uint32_t TBinaryProtocol::writeString(TTransport* out,
+                                      const string& str) const {
+  uint32_t result = writeU32(out, str.size());
+  out->write((uint8_t*)str.data(), str.size());
+  return result + str.size();
+}
+
+/**
+ * Reading functions
+ */
+
+uint32_t TBinaryProtocol::readStructBegin(TTransport* in,
+                                          string& name) const {
+  name = "";
+  return 0;
+}
+
+uint32_t TBinaryProtocol::readStructEnd(TTransport* in) const {
+  return 0;
+}
+
+uint32_t TBinaryProtocol::readFieldBegin(TTransport* in,
+                                         string& name,
+                                         TType& fieldType,
+                                         uint16_t& fieldId) const {
+  uint32_t result = 0;
+  uint8_t type;
+  result += readByte(in, type);
+  fieldType = (TType)type;
+  if (fieldType == T_STOP) {
+    fieldId = 0;
+    return result;
+  }
+  uint32_t id;
+  result += readU32(in, id);
+  fieldId = (uint16_t)id;
+  return result;
+}
   
-  if (buf.len < 4) {
-    return fieldMap;
-  }
-  uint32_t total_size = readU32(buf);
-  if (buf.len < total_size) {
-    // Data looks corrupt, we don't have that much, we will try to read what
-    // we can but be sure not to go over
-    total_size = buf.len;
-  }
-
-  // Field headers are 8 bytes, 4 byte fid + 4 byte length
-  while (total_size > 0 && buf.len > 8) {
-    uint32_t fid  = readU32(buf);
-    uint32_t flen = readU32(buf);
-    if (flen > buf.len) {
-      // flen corrupt, there isn't that much data left
-      break;
-    }
-    fieldMap.insert(make_pair(fid, TBuf(buf.data, flen)));
-    buf.data += flen;
-    buf.len  -= flen;
-    total_size -= 8 + flen;
-  }
-
-  return fieldMap;
+uint32_t TBinaryProtocol::readFieldEnd(TTransport* in) const {
+  return 0;
 }
-
-string TBinaryProtocol::writeStruct(const map<uint32_t,string>& s) const {
-  string result = "";
-  map<uint32_t,string>::const_iterator s_iter;
-  for (s_iter = s.begin(); s_iter != s.end(); ++s_iter) {
-    result += writeU32(s_iter->first);
-    result += writeU32(s_iter->second.size());
-    result += s_iter->second;
-  }
-  return writeU32(result.size()) + result;
-}
-
-string TBinaryProtocol::readString(TBuf& buf) const {
-  uint32_t len = readU32(buf);
-  if (len == 0) {
-    return "";
-  }
-  string result((const char*)(buf.data), len);
-  buf.data += len;
-  buf.len  -= len;
+ 
+uint32_t TBinaryProtocol::readMapBegin(TTransport* in,
+                                       TType& keyType,
+                                       TType& valType,
+                                       uint32_t& size) const {
+  uint8_t k, v;
+  uint32_t result = 0;
+  result += readByte(in, k);
+  keyType = (TType)k;
+  result += readByte(in, v);
+  valType = (TType)v;
+  result += readU32(in, size);
   return result;
 }
 
-uint8_t TBinaryProtocol::readByte(TBuf& buf) const {
-  if (buf.len == 0) {
-    return 0;
-  }
-  uint8_t result = (uint8_t)buf.data[0];
-  buf.data += 1;
-  buf.len  -= 1;
+uint32_t TBinaryProtocol::readMapEnd(TTransport* in) const {
+  return 0;
+}
+
+uint32_t TBinaryProtocol::readListBegin(TTransport* in,
+                                        TType& elemType,
+                                        uint32_t& size) const {
+  uint8_t e;
+  uint32_t result = 0;
+  result += readByte(in, e);
+  elemType = (TType)e;
+  result += readU32(in, size);
   return result;
 }
 
-uint32_t TBinaryProtocol::readU32(TBuf& buf) const {
-  if (buf.len < 4) {
-    return 0;
-  }
-  uint32_t result = *(uint32_t*)buf.data;
-  buf.data += 4;
-  buf.len  -= 4;
+uint32_t TBinaryProtocol::readListEnd(TTransport* in) const {
+  return 0;
+}
+
+uint32_t TBinaryProtocol::readSetBegin(TTransport* in,
+                                       TType& elemType,
+                                       uint32_t& size) const {
+  uint8_t e;
+  uint32_t result = 0;
+  result += readByte(in, e);
+  elemType = (TType)e;
+  result += readU32(in, size);
   return result;
 }
 
-int32_t TBinaryProtocol::readI32(TBuf& buf) const {
-  if (buf.len < 4) {
-    return 0;
-  }
-  int32_t result = *(int32_t*)buf.data;
-  buf.data += 4;
-  buf.len  -= 4;
-  return result; 
+uint32_t TBinaryProtocol::readSetEnd(TTransport* in) const {
+  return 0;
 }
 
-uint64_t TBinaryProtocol::readU64(TBuf& buf) const {
-  if (buf.len < 8) {
-    return 0;
-  }
-  uint64_t result = *(uint64_t*)buf.data;
-  buf.data += 8;
-  buf.len  -= 8;
-  return result;
+uint32_t TBinaryProtocol::readByte(TTransport* in,
+                                   uint8_t& byte) const {
+  uint8_t b[1];
+  in->readAll(b, 1);
+  byte = *(uint8_t*)b;
+  return 1;
 }
 
-int64_t TBinaryProtocol::readI64(TBuf& buf) const {
-  if (buf.len < 8) {
-    return 0;
-  }
-  int64_t result = *(int64_t*)buf.data;
-  buf.data += 8;
-  buf.len  -= 8;
-  return result;
+uint32_t TBinaryProtocol::readU32(TTransport* in,
+                                  uint32_t& u32) const {
+  uint8_t b[4];
+  in->readAll(b, 4);
+  u32 = *(uint32_t*)b;
+  u32 = (uint32_t)ntohl(u32);
+  return 4;
 }
 
-string TBinaryProtocol::writeString(const string& str) const {
-  uint32_t size = str.size();
-  string result = string((const char*)&size, 4);
-  return result + str;
+uint32_t TBinaryProtocol::readI32(TTransport* in,
+                                  int32_t& i32) const {
+  uint8_t b[4];
+  in->readAll(b, 4);
+  i32 = *(int32_t*)b;
+  i32 = (int32_t)ntohl(i32);
+  return 4;
 }
 
-string TBinaryProtocol::writeByte(const uint8_t byte) const {
-  return string((const char*)&byte, 1);
+uint32_t TBinaryProtocol::readU64(TTransport* in,
+                                  uint64_t& u64) const {
+  uint8_t b[8];
+  in->readAll(b, 8);
+  u64 = *(uint64_t*)b;
+  u64 = (uint64_t)ntohll(u64);
+  return 8;
 }
 
-string TBinaryProtocol::writeU32(const uint32_t u32) const {
-  return string((const char*)&u32, 4);
+uint32_t TBinaryProtocol::readI64(TTransport* in,
+                                  int64_t& i64) const {
+  uint8_t b[8];
+  in->readAll(b, 8);
+  i64 = *(int64_t*)b;
+  i64 = (int64_t)ntohll(i64);
+  return 8;
 }
 
-string TBinaryProtocol::writeI32(int32_t i32) const {
-  return string((const char*)&i32, 4);
-}
-
-string TBinaryProtocol::writeU64(uint64_t u64) const {
-  return string((const char*)&u64, 8);
-}
-
-string TBinaryProtocol::writeI64(int64_t i64) const {
-  return string((const char*)&i64, 8);
+uint32_t TBinaryProtocol::readString(TTransport* in,
+                                     string& str) const {
+  uint32_t size, result;
+  result = readU32(in, size);
+  uint8_t b[size];
+  in->readAll(b, size);
+  str = string((char*)b, size);
+  return result+size;
 }
