Beispiel #1
0
void BufferTest::testEvenMoreComplicatedSerialization()
{
  struct X
  {
    X() :  a((Real)3.4)
         , b(6)
         , c('c')
         , e((Real)-0.04)
    {
      for (int i = 0; i < 4; ++i)
        d[i] = 'A' + i;

      for (int i = 0; i < 3; ++i)
        f[i] = 100 + i;    
    }
    
    Real a;
    UInt32 b;
    Byte c;
    Byte d[4];
    Real e;
    Int32  f[3];
  };
  
  X xi[2];

  xi[0].a = (Real)8.8;
  xi[1].a = (Real)4.5;
  xi[1].c = 't';
  xi[1].d[0] = 'X';
  xi[1].e = (Real)3.14;
  xi[1].f[0] = -999;  
  // Write the two Xs to a buffer
  WriteBuffer wb;
  TEST2("BufferTest::testComplicatedSerialization(), empty WriteBuffer should have 0 size", wb.getSize() == 0);
  
  // Write the number of Xs
  UInt32 size = 2;
  wb.write((UInt32 &)size);
  // Write all Xs.
  for (UInt32 i = 0; i < size; ++i)
  {
    wb.write(xi[i].a);
    wb.write(xi[i].b);
    wb.write(xi[i].c);
    Size len = 4;
    wb.write((const Byte *)xi[i].d, len);
    wb.write(xi[i].e);
    len = 3;
    wb.write(xi[i].f, len);  
  }
  
  ReadBuffer rb(wb.getData(), wb.getSize());
  // Read number of Xs
  rb.read(size);
  // Allocate array of Xs
  X * xo = new X[size];
  for (Size i = 0; i < size; ++i)
  {
    rb.read(xo[i].a);
    rb.read(xo[i].b);
    rb.read(xo[i].c);
    Size len = 4;
    Int32 res = rb.read(xo[i].d, len);
    TEST2("BufferTest::testComplicatedSerialization(), rb.read(xi[i].d, 4) failed", res == 0);
    TEST2("BufferTest::testComplicatedSerialization(), rb.read(xi[i].d, 4) == 4", len == 4);
    rb.read(xo[i].e);
    len = 3;
    res = rb.read(xo[i].f, len);
    NTA_INFO << "xo[" << i << "]={" << xo[i].a << " "
             << xo[i].b << " " 
             << xo[i].c << " " 
             << "'" << std::string(xo[i].d, 4) << "'" 
             << " " << xo[i].e << " "
             << "'" << xo[i].f[0] << "," << xo[i].f[1] << "," << xo[i].f[2] << "'" 
             ;
  }
  
  TEST2("BufferTest::testComplicatedSerialization(), xo[0].a == 8.8", nearlyEqual(xo[0].a, nta::Real(8.8)));
  TEST2("BufferTest::testComplicatedSerialization(), xo[0].b == 6", xo[0].b == 6);
  TEST2("BufferTest::testComplicatedSerialization(), xo[0].c == 'c'", xo[0].c == 'c');
  TEST2("BufferTest::testComplicatedSerialization(), xo[0].d == ABCD", std::string(xo[0].d, 4) == std::string("ABCD"));
  TEST2("BufferTest::testComplicatedSerialization(), xo[0].e == -0.04", nearlyEqual(xo[0].e, nta::Real(-0.04)));
  TEST2("BufferTest::testComplicatedSerialization(), xo[0].f[0] == 100", xo[0].f[0] == 100);
  TEST2("BufferTest::testComplicatedSerialization(), xo[0].f[1] == 101", xo[0].f[1] == 101);
  TEST2("BufferTest::testComplicatedSerialization(), xo[0].f[2] == 102", xo[0].f[2] == 102);
  
  TEST2("BufferTest::testComplicatedSerialization(), xo[1].a == 4.5", xo[1].a == nta::Real(4.5));
  TEST2("BufferTest::testComplicatedSerialization(), xo[1].b == 6", xo[1].b == 6);
  TEST2("BufferTest::testComplicatedSerialization(), xo[1].c == 't'", xo[1].c == 't');
  TEST2("BufferTest::testComplicatedSerialization(), xo[1].d == XBCD", std::string(xo[1].d, 4) == std::string("XBCD"));
  TEST2("BufferTest::testComplicatedSerialization(), xo[1].e == 3.14", xo[1].e == nta::Real(3.14));
  TEST2("BufferTest::testComplicatedSerialization(), xo[1].f[0] == -999", xo[1].f[0] == -999);
  TEST2("BufferTest::testComplicatedSerialization(), xo[1].f[1] == 101", xo[1].f[1] == 101);
  TEST2("BufferTest::testComplicatedSerialization(), xo[1].f[2] == 102", xo[1].f[2] == 102);
}
void DataTypeFixedString::serializeBinary(const IColumn & column, size_t row_num, WriteBuffer & ostr) const
{
	ostr.write(reinterpret_cast<const char *>(&static_cast<const ColumnFixedString &>(column).getChars()[n * row_num]), n);
}