/[Apache-SVN]
ViewVC logotype

Revision 665209


Jump to revision: Previous Next
Author: yunfang
Date: Sun Aug 19 22:18:38 2007 UTC (17 years, 2 months ago)
Changed paths: 1
Log Message:
[adding TStringBuffer for serialization/deserialization from a string]
Summary:
/**
 * A string buffer is a tranpsort that simply reads from and writes to a
 * string. Anytime you call write on it, the data is serialized
 * into the underlying buffer, you can call getString() to get the serialized
 * string.  Before you call read, you should call resetString(data) to set the
 * underlying buffer, you can then call read to get the
 * de-serialized data structure.
 *
 * The string buffer is inherited from the memory buffer
 * Thus, buffers are allocated using C constructs malloc,realloc, and the size
 * doubles as necessary.
 */

Reviewed by: aditya

Test Plan:
int main(int argc, char** argv) {
  shared_ptr<TStringBuffer> strBuffer(new TStringBuffer());
  shared_ptr<TBinaryProtocol> binaryProtcol(new TBinaryProtocol(strBuffer));

  testStruct a;
  a.i1 = 10;
  a.i2 = 30;
  a.s1 = string("holla back a");

  a.write(binaryProtcol.get());
  string serialized = strBuffer->getString();

  shared_ptr<TStringBuffer> strBuffer2(new TStringBuffer());
  shared_ptr<TBinaryProtocol> binaryProtcol2(new TBinaryProtocol(strBuffer2));

  strBuffer2->resetString(serialized);
  testStruct a2;
  a2.read(binaryProtcol2.get());

  if (a == a2) {
    printf("serialization working\n");
  } else {
    printf("serialization not working\n");
  }
}


Changed paths

Path Details
Directoryincubator/thrift/trunk/lib/cpp/src/transport/TTransportUtils.h modified , text changed

infrastructure at apache.org
ViewVC Help
Powered by ViewVC 1.1.26