Skip to content
Browse files

Revert "Update c++ client protocol to match server and respective tes…

…ts."

This reverts commit 692edef. The c++
version of the protocol buffers IO classses seem to be buggy, asking
for more data than needed. This interacts badly with blocking streams
causing it to block forever.
  • Loading branch information...
1 parent 692edef commit a1ed1828ed12bf085f0f260fc942ba1b86b3bbcb @ijuma ijuma committed Jul 24, 2009
View
32 clients/cpp/src/ProtocolBuffersRequestFormat.cpp
@@ -105,25 +105,31 @@ static void throwException(const voldemort::Error& error) {
static void writeMessageWithLength(std::ostream* outputStream,
google::protobuf::Message* message) {
-
- uint32_t messageSize = message->ByteSize();
- OstreamOutputStream zos(outputStream);
- CodedOutputStream cos(&zos);
- cos.WriteVarint32(messageSize);
- message->SerializeToCodedStream(&cos);
+ uint32_t mLen = htonl(message->ByteSize());
+ //OstreamOutputStream zos(outputStream);
+ //CodedOutputStream os(&zos);
+
+ //os.WriteVarint32(message->ByteSize());
+ outputStream->write((char*)&mLen, 4);
+ message->SerializeToOstream(outputStream);
+ //message->SerializeToCodedStream(&os);
CHECK_STREAM_OUT(outputStream);
}
static void readMessageWithLength(std::istream* inputStream,
google::protobuf::Message* message) {
uint32_t mLen;
- IstreamInputStream zis(inputStream);
- CodedInputStream cis(&zis);
- cis.ReadVarint32(&mLen);
- cis.PushLimit(mLen);
- message->ParseFromCodedStream(&cis);
- //For some reason ReadVarint32 causes inputStream->fail() to return true
- //CHECK_STREAM(inputStream);
+ READ_INT(inputStream, mLen);
+
+ //IstreamInputStream zis(inputStream);
+ //CodedInputStream cis(&zis);
+ //cis.ReadVarint32(&mLen);
+ //
+ std::vector<char> buffer(mLen);
+ inputStream->read(&buffer[0], mLen);
+ CHECK_STREAM(inputStream);
+
+ message->ParseFromArray((void*)&buffer[0], mLen);
}
void ProtocolBuffersRequestFormat::writeGetRequest(std::ostream* outputStream,
View
14 clients/cpp/test/ProtocolBuffersRequestFormat_test.cpp
@@ -29,7 +29,6 @@ using namespace google::protobuf::io;
#include <sstream>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <arpa/inet.h>
-#include <google/protobuf/io/coded_stream.h>
BOOST_AUTO_TEST_SUITE(ProtocolBuffersRequestFormat_test)
@@ -40,11 +39,12 @@ BOOST_AUTO_TEST_SUITE(ProtocolBuffersRequestFormat_test)
static void readMessageWithLength(std::istream* inputStream,
google::protobuf::Message* message) {
uint32_t mLen;
- IstreamInputStream zis(inputStream);
- CodedInputStream cis(&zis);
- cis.ReadVarint32(&mLen);
- cis.PushLimit(mLen);
- message->ParseFromCodedStream(&cis);
+ READ_INT(inputStream, mLen);
+
+ IstreamInputStream isis(inputStream);
+ LimitingInputStream lis(&isis, (uint64_t)mLen);
+
+ message->ParseFromZeroCopyStream(&lis);
}
BOOST_AUTO_TEST_CASE( get_req_test ) {
@@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE( get_res_test ) {
ProtocolBuffersRequestFormat rf;
stringstream streamwithlen;
- streamwithlen.write("\x18\x0a\x16\x0a\x05\x77\x6f\x72\x6c\x64\x12\x0d\x0a\x04\x08\x00\x10\x01\x10\xf8\x9d\xe2\x88\x9b\x24", 0x18+1);
+ streamwithlen.write("\x00\x00\x00\x18\x0a\x16\x0a\x05\x77\x6f\x72\x6c\x64\x12\x0d\x0a\x04\x08\x00\x10\x01\x10\xf8\x9d\xe2\x88\x9b\x24", 0x18+4);
streamwithlen << "Some more gibberish";
auto_ptr<std::list<VersionedValue> > vv(rf.readGetResponse(&streamwithlen));

0 comments on commit a1ed182

Please sign in to comment.
Something went wrong with that request. Please try again.