aboutsummaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-17 12:00:59 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-01-17 12:30:07 +0000
commit5eaae9afb93ad82a931e117a14babdbb271762c6 (patch)
treed987288d506fe18bdd323e873a6ef910fd312a68 /document
parentc9b92a456b0dd9980dfa17806b4f0948be60002f (diff)
Simplify as functionality is abandoned.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/documenttestcase.cpp3
-rw-r--r--document/src/tests/testbytebuffer.cpp344
-rw-r--r--document/src/vespa/document/fieldvalue/serializablearray.cpp2
-rw-r--r--document/src/vespa/document/fieldvalue/structfieldvalue.cpp5
-rw-r--r--document/src/vespa/document/util/bytebuffer.cpp113
-rw-r--r--document/src/vespa/document/util/bytebuffer.h55
-rw-r--r--document/src/vespa/document/util/serializable.cpp3
-rw-r--r--document/src/vespa/document/util/serializable.h5
8 files changed, 155 insertions, 375 deletions
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp
index 9a3d9c94a91..39a92352a5e 100644
--- a/document/src/tests/documenttestcase.cpp
+++ b/document/src/tests/documenttestcase.cpp
@@ -32,9 +32,8 @@ TEST(DocumentTest, testSizeOf)
{
EXPECT_EQ(24u, sizeof(std::vector<char>));
EXPECT_EQ(24u, sizeof(vespalib::alloc::Alloc));
- EXPECT_EQ(56u, sizeof(ByteBuffer));
+ EXPECT_EQ(48u, sizeof(ByteBuffer));
EXPECT_EQ(32u, sizeof(vespalib::GrowableByteBuffer));
- EXPECT_EQ(56u, sizeof(ByteBuffer));
EXPECT_EQ(88ul, sizeof(IdString));
EXPECT_EQ(104ul, sizeof(DocumentId));
EXPECT_EQ(200ul, sizeof(Document));
diff --git a/document/src/tests/testbytebuffer.cpp b/document/src/tests/testbytebuffer.cpp
index feb3252a48c..b90db980683 100644
--- a/document/src/tests/testbytebuffer.cpp
+++ b/document/src/tests/testbytebuffer.cpp
@@ -22,95 +22,13 @@ void assign(S &lhs, const S &rhs)
TEST(ByteBuffer_Test, test_constructors)
{
- ByteBuffer* simple=new ByteBuffer();
- delete simple;
-
- ByteBuffer* less_simple=new ByteBuffer("hei",3);
- EXPECT_TRUE(strcmp(less_simple->getBufferAtPos(),"hei")==0);
- delete less_simple;
-}
-
-TEST(ByteBuffer_Test, test_assignment_operator)
-{
- try {
- ByteBuffer b1;
- ByteBuffer b2 = b1;
-
- EXPECT_EQ(b1.getPos(),b2.getPos());
- EXPECT_EQ(b1.getLength(),b2.getLength());
- EXPECT_EQ(b1.getLimit(),b2.getLimit());
- EXPECT_EQ(b1.getRemaining(),b2.getRemaining());
-
- } catch (std::exception &e) {
- FAIL() << "Unexpected exception at " << VESPA_STRLOC << ": \"" << e.what() << "\"";
- }
-
- try {
- ByteBuffer b1(100);
- b1.putInt(1);
- b1.putInt(2);
-
- ByteBuffer b2 = b1;
-
- EXPECT_EQ(b1.getPos(),b2.getPos());
- EXPECT_EQ(b1.getLength(),b2.getLength());
- EXPECT_EQ(b1.getLimit(),b2.getLimit());
- EXPECT_EQ(b1.getRemaining(),b2.getRemaining());
-
- int test = 0;
- b2.flip();
- b2.getInt(test);
- EXPECT_EQ(1,test);
- b2.getInt(test);
- EXPECT_EQ(2,test);
-
-
- EXPECT_EQ(b1.getPos(),b2.getPos());
- EXPECT_EQ(b1.getLength(),b2.getLength());
- EXPECT_EQ((size_t) 8,b2.getLimit());
- EXPECT_EQ((size_t) 0,b2.getRemaining());
-
- // Test Selfassignment == no change
- //
- assign(b2, b2);
-
-
- EXPECT_EQ(b1.getPos(),b2.getPos());
- EXPECT_EQ(b1.getLength(),b2.getLength());
- EXPECT_EQ((size_t) 8,b2.getLimit());
- EXPECT_EQ((size_t) 0,b2.getRemaining());
-
- ByteBuffer b3;
- // Empty
- b2 = b3;
-
- EXPECT_EQ((size_t) 0,b2.getPos());
- EXPECT_EQ((size_t) 0,b2.getLength());
- EXPECT_EQ((size_t) 0,b2.getLimit());
- EXPECT_EQ((size_t) 0,b2.getRemaining());
-
- } catch (std::exception &e) {
- FAIL() << "Unexpected exception at " << VESPA_STRLOC << ": \"" << e.what() << "\"";
- }
+ ByteBuffer less_simple("hei",3);
+ EXPECT_TRUE(strcmp(less_simple.getBufferAtPos(),"hei")==0);
}
TEST(ByteBuffer_Test, test_copy_constructor)
{
try {
- // Empty buffer first
- ByteBuffer b1;
- ByteBuffer b2(b1);
-
- EXPECT_EQ(b1.getPos(),b2.getPos());
- EXPECT_EQ(b1.getLength(),b2.getLength());
- EXPECT_EQ(b1.getLimit(),b2.getLimit());
- EXPECT_EQ(b1.getRemaining(),b2.getRemaining());
-
- } catch (std::exception &e) {
- FAIL() << "Unexpected exception at " << VESPA_STRLOC << ": \"" << e.what() << "\"";
- }
-
- try {
ByteBuffer b1(100);
b1.putInt(1);
b1.putInt(2);
@@ -119,7 +37,6 @@ TEST(ByteBuffer_Test, test_copy_constructor)
EXPECT_EQ(b1.getPos(),b2.getPos());
EXPECT_EQ(b1.getLength(),b2.getLength());
- EXPECT_EQ(b1.getLimit(),b2.getLimit());
EXPECT_EQ(b1.getRemaining(),b2.getRemaining());
int test = 0;
@@ -136,251 +53,248 @@ TEST(ByteBuffer_Test, test_copy_constructor)
TEST(ByteBuffer_Test, test_putGetFlip)
{
- ByteBuffer* newBuf=new ByteBuffer(100);
+ ByteBuffer newBuf(100);
try {
- newBuf->putInt(10);
+ newBuf.putInt(10);
int test;
- newBuf->flip();
+ newBuf.flip();
- newBuf->getInt(test);
- EXPECT_TRUE(test==10);
+ newBuf.getInt(test);
+ EXPECT_EQ(test, 10);
- newBuf->clear();
- newBuf->putDouble(3.35);
- newBuf->flip();
- EXPECT_TRUE(newBuf->getRemaining()==sizeof(double));
+ newBuf.clear();
+ newBuf.putDouble(3.35);
+ newBuf.flip();
+ EXPECT_EQ(newBuf.getRemaining(), 100);
double test2;
- newBuf->getDouble(test2);
+ newBuf.getDouble(test2);
EXPECT_TRUE(test2==3.35);
- newBuf->clear();
- newBuf->putBytes("heisann",8);
- newBuf->putInt(4);
- EXPECT_TRUE(newBuf->getPos()==12);
- EXPECT_TRUE(newBuf->getLength()==100);
- newBuf->flip();
- EXPECT_TRUE(newBuf->getRemaining()==12);
+ newBuf.clear();
+ newBuf.putBytes("heisann",8);
+ newBuf.putInt(4);
+ EXPECT_EQ(newBuf.getPos(), 12);
+ EXPECT_EQ(newBuf.getLength(), 100);
+ newBuf.flip();
+ EXPECT_EQ(newBuf.getRemaining(), 100);
char testStr[12];
- newBuf->getBytes(testStr, 8);
+ newBuf.getBytes(testStr, 8);
EXPECT_TRUE(strcmp(testStr,"heisann")==0);
- newBuf->getInt(test);
+ newBuf.getInt(test);
EXPECT_TRUE(test==4);
} catch (std::exception &e) {
FAIL() << "Unexpected exception at " << VESPA_STRLOC << ": \"" << e.what() << "\"";
}
- delete newBuf;
}
TEST(ByteBuffer_Test, test_NumberEncodings)
{
- ByteBuffer* buf=new ByteBuffer(1024);
+ ByteBuffer buf(1024);
// Check 0
- buf->putInt1_2_4Bytes(124);
- buf->putInt2_4_8Bytes(124);
- buf->putInt1_4Bytes(124);
+ buf.putInt1_2_4Bytes(124);
+ buf.putInt2_4_8Bytes(124);
+ buf.putInt1_4Bytes(124);
// Check 1
- buf->putInt1_2_4Bytes(127);
- buf->putInt2_4_8Bytes(127);
- buf->putInt1_4Bytes(127);
+ buf.putInt1_2_4Bytes(127);
+ buf.putInt2_4_8Bytes(127);
+ buf.putInt1_4Bytes(127);
// Check 2
- buf->putInt1_2_4Bytes(128);
- buf->putInt2_4_8Bytes(128);
- buf->putInt1_4Bytes(128);
+ buf.putInt1_2_4Bytes(128);
+ buf.putInt2_4_8Bytes(128);
+ buf.putInt1_4Bytes(128);
// Check 3
- buf->putInt1_2_4Bytes(255);
- buf->putInt2_4_8Bytes(255);
- buf->putInt1_4Bytes(255);
+ buf.putInt1_2_4Bytes(255);
+ buf.putInt2_4_8Bytes(255);
+ buf.putInt1_4Bytes(255);
// Check 4
- buf->putInt1_2_4Bytes(256);
- buf->putInt2_4_8Bytes(256);
- buf->putInt1_4Bytes(256);
+ buf.putInt1_2_4Bytes(256);
+ buf.putInt2_4_8Bytes(256);
+ buf.putInt1_4Bytes(256);
// Check 5
- buf->putInt1_2_4Bytes(0);
- buf->putInt2_4_8Bytes(0);
- buf->putInt1_4Bytes(0);
+ buf.putInt1_2_4Bytes(0);
+ buf.putInt2_4_8Bytes(0);
+ buf.putInt1_4Bytes(0);
// Check 6
- buf->putInt1_2_4Bytes(1);
- buf->putInt2_4_8Bytes(1);
- buf->putInt1_4Bytes(1);
+ buf.putInt1_2_4Bytes(1);
+ buf.putInt2_4_8Bytes(1);
+ buf.putInt1_4Bytes(1);
// Check 7
try {
- buf->putInt1_2_4Bytes(0x7FFFFFFF);
+ buf.putInt1_2_4Bytes(0x7FFFFFFF);
FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
- buf->putInt2_4_8Bytes(0x7FFFFFFFll);
- buf->putInt1_4Bytes(0x7FFFFFFF);
+ buf.putInt2_4_8Bytes(0x7FFFFFFFll);
+ buf.putInt1_4Bytes(0x7FFFFFFF);
try {
- buf->putInt2_4_8Bytes(0x7FFFFFFFFFFFFFFFll);
+ buf.putInt2_4_8Bytes(0x7FFFFFFFFFFFFFFFll);
FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
- buf->putInt1_2_4Bytes(0x7FFF);
+ buf.putInt1_2_4Bytes(0x7FFF);
// Check 8
- buf->putInt2_4_8Bytes(0x7FFFll);
- buf->putInt1_4Bytes(0x7FFF);
- buf->putInt1_2_4Bytes(0x7F);
+ buf.putInt2_4_8Bytes(0x7FFFll);
+ buf.putInt1_4Bytes(0x7FFF);
+ buf.putInt1_2_4Bytes(0x7F);
// Check 9
- buf->putInt2_4_8Bytes(0x7Fll);
- buf->putInt1_4Bytes(0x7F);
+ buf.putInt2_4_8Bytes(0x7Fll);
+ buf.putInt1_4Bytes(0x7F);
try {
- buf->putInt1_2_4Bytes(-1);
+ buf.putInt1_2_4Bytes(-1);
FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
- buf->putInt2_4_8Bytes(-1);
+ buf.putInt2_4_8Bytes(-1);
FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
- buf->putInt1_4Bytes(-1);
+ buf.putInt1_4Bytes(-1);
FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
- buf->putInt1_2_4Bytes(-0x7FFFFFFF);
+ buf.putInt1_2_4Bytes(-0x7FFFFFFF);
FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
- buf->putInt2_4_8Bytes(-0x7FFFFFFF);
+ buf.putInt2_4_8Bytes(-0x7FFFFFFF);
FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
- buf->putInt1_4Bytes(-0x7FFFFFFF);
+ buf.putInt1_4Bytes(-0x7FFFFFFF);
FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
- buf->putInt2_4_8Bytes(-0x7FFFFFFFFFFFFFFFll);
+ buf.putInt2_4_8Bytes(-0x7FFFFFFFFFFFFFFFll);
FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
- uint32_t endWritePos = buf->getPos();
- buf->setPos(0);
+ uint32_t endWritePos = buf.getPos();
+ buf.setPos(0);
int32_t tmp32;
int64_t tmp64;
// Check 0
- buf->getInt1_2_4Bytes(tmp32);
+ buf.getInt1_2_4Bytes(tmp32);
EXPECT_EQ(124, tmp32);
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)124, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(124, tmp32);
// Check 1
- buf->getInt1_2_4Bytes(tmp32);
+ buf.getInt1_2_4Bytes(tmp32);
EXPECT_EQ(127, tmp32);
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)127, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(127, tmp32);
// Check 2
- buf->getInt1_2_4Bytes(tmp32);
+ buf.getInt1_2_4Bytes(tmp32);
EXPECT_EQ(128, tmp32);
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)128, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(128, tmp32);
// Check 3
- buf->getInt1_2_4Bytes(tmp32);
+ buf.getInt1_2_4Bytes(tmp32);
EXPECT_EQ(255, tmp32);
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)255, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(255, tmp32);
// Check 4
- buf->getInt1_2_4Bytes(tmp32);
+ buf.getInt1_2_4Bytes(tmp32);
EXPECT_EQ(256, tmp32);
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)256, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(256, tmp32);
// Check 5
- buf->getInt1_2_4Bytes(tmp32);
+ buf.getInt1_2_4Bytes(tmp32);
EXPECT_EQ(0, tmp32);
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)0, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(0, tmp32);
// Check 6
- buf->getInt1_2_4Bytes(tmp32);
+ buf.getInt1_2_4Bytes(tmp32);
EXPECT_EQ(1, tmp32);
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)1, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(1, tmp32);
// Check 7
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)0x7FFFFFFF, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(0x7FFFFFFF, tmp32);
- buf->getInt1_2_4Bytes(tmp32);
+ buf.getInt1_2_4Bytes(tmp32);
EXPECT_EQ(0x7FFF, tmp32);
// Check 8
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)0x7FFF, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(0x7FFF, tmp32);
- buf->getInt1_2_4Bytes(tmp32);
+ buf.getInt1_2_4Bytes(tmp32);
EXPECT_EQ(0x7F, tmp32);
// Check 9
- buf->getInt2_4_8Bytes(tmp64);
+ buf.getInt2_4_8Bytes(tmp64);
EXPECT_EQ((int64_t)0x7F, tmp64);
- buf->getInt1_4Bytes(tmp32);
+ buf.getInt1_4Bytes(tmp32);
EXPECT_EQ(0x7F, tmp32);
- uint32_t endReadPos = buf->getPos();
+ uint32_t endReadPos = buf.getPos();
EXPECT_EQ(endWritePos, endReadPos);
- delete buf;
}
TEST(ByteBuffer_Test, test_NumberLengths)
{
- ByteBuffer b;
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(0));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(1));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(4));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(31));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(126));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(127));
- EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(128));
- EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(129));
- EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(255));
- EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(256));
- EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(0x7FFFFFFF));
-
- EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(0));
- EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(1));
- EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(4));
- EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(31));
- EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(126));
- EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(127));
- EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(128));
- EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(32767));
- EXPECT_EQ((size_t) 4, b.getSerializedSize2_4_8Bytes(32768));
- EXPECT_EQ((size_t) 4, b.getSerializedSize2_4_8Bytes(32769));
- EXPECT_EQ((size_t) 4, b.getSerializedSize2_4_8Bytes(1030493));
- EXPECT_EQ((size_t) 4, b.getSerializedSize2_4_8Bytes(0x3FFFFFFF));
- EXPECT_EQ((size_t) 8, b.getSerializedSize2_4_8Bytes(0x40000000));
- EXPECT_EQ((size_t) 8, b.getSerializedSize2_4_8Bytes(0x40000001));
-
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(0));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(1));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(4));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(31));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(126));
- EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(127));
- EXPECT_EQ((size_t) 2, b.getSerializedSize1_2_4Bytes(128));
- EXPECT_EQ((size_t) 2, b.getSerializedSize1_2_4Bytes(16383));
- EXPECT_EQ((size_t) 4, b.getSerializedSize1_2_4Bytes(16384));
- EXPECT_EQ((size_t) 4, b.getSerializedSize1_2_4Bytes(16385));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_4Bytes(0));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_4Bytes(1));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_4Bytes(4));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_4Bytes(31));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_4Bytes(126));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_4Bytes(127));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize1_4Bytes(128));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize1_4Bytes(129));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize1_4Bytes(255));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize1_4Bytes(256));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize1_4Bytes(0x7FFFFFFF));
+
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize2_4_8Bytes(0));
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize2_4_8Bytes(1));
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize2_4_8Bytes(4));
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize2_4_8Bytes(31));
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize2_4_8Bytes(126));
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize2_4_8Bytes(127));
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize2_4_8Bytes(128));
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize2_4_8Bytes(32767));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize2_4_8Bytes(32768));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize2_4_8Bytes(32769));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize2_4_8Bytes(1030493));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize2_4_8Bytes(0x3FFFFFFF));
+ EXPECT_EQ((size_t) 8, ByteBuffer::getSerializedSize2_4_8Bytes(0x40000000));
+ EXPECT_EQ((size_t) 8, ByteBuffer::getSerializedSize2_4_8Bytes(0x40000001));
+
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_2_4Bytes(0));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_2_4Bytes(1));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_2_4Bytes(4));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_2_4Bytes(31));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_2_4Bytes(126));
+ EXPECT_EQ((size_t) 1, ByteBuffer::getSerializedSize1_2_4Bytes(127));
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize1_2_4Bytes(128));
+ EXPECT_EQ((size_t) 2, ByteBuffer::getSerializedSize1_2_4Bytes(16383));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize1_2_4Bytes(16384));
+ EXPECT_EQ((size_t) 4, ByteBuffer::getSerializedSize1_2_4Bytes(16385));
}
TEST(ByteBuffer_Test, test_SerializableArray)
diff --git a/document/src/vespa/document/fieldvalue/serializablearray.cpp b/document/src/vespa/document/fieldvalue/serializablearray.cpp
index 3917a8a63a4..3887c97bb5e 100644
--- a/document/src/vespa/document/fieldvalue/serializablearray.cpp
+++ b/document/src/vespa/document/fieldvalue/serializablearray.cpp
@@ -26,7 +26,6 @@ public:
}
-
SerializableArray::SerializableArray()
: _serializedCompression(CompressionConfig::NONE),
_uncompressedLength(0)
@@ -218,7 +217,6 @@ SerializableArray::deCompress() // throw (DeserializeException)
VESPA_STRLOC);
}
assert(newSerialization->getBuffer() == unCompressed.getData());
- newSerialization->setLimit(_uncompressedLength);
_uncompSerData = std::move(newSerialization);
LOG_ASSERT(_uncompressedLength == _uncompSerData->getRemaining());
}
diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp
index fbdc08bee0e..b861537f6f7 100644
--- a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp
@@ -244,9 +244,7 @@ serializeDoc(const FieldValue & fv) {
nbostream::Buffer buf;
stream.swap(buf);
size_t sz = buf.size();
- auto bb = std::make_unique<ByteBuffer>(nbostream::Buffer::stealAlloc(std::move(buf)), sz);
- bb->setPos(sz);
- return bb;
+ return std::make_unique<ByteBuffer>(nbostream::Buffer::stealAlloc(std::move(buf)), sz);
}
}
@@ -256,7 +254,6 @@ StructFieldValue::setFieldValue(const Field& field, FieldValue::UP value)
int fieldId = field.getId();
std::unique_ptr<ByteBuffer> serialized = serializeDoc(*value);
- serialized->flip();
if (_chunks.empty()) {
_chunks.push_back(std::make_unique<SerializableArray>());
}
diff --git a/document/src/vespa/document/util/bytebuffer.cpp b/document/src/vespa/document/util/bytebuffer.cpp
index 1b586a448cf..415aeebf969 100644
--- a/document/src/vespa/document/util/bytebuffer.cpp
+++ b/document/src/vespa/document/util/bytebuffer.cpp
@@ -37,65 +37,39 @@ InputOutOfRangeException::InputOutOfRangeException(
{
}
-ByteBuffer::ByteBuffer() :
- _buffer(nullptr),
- _len(0),
- _pos(0),
- _limit(0),
- _ownedBuffer()
-{
- set(nullptr, 0);
-}
-
ByteBuffer::ByteBuffer(size_t len) :
ByteBuffer(Alloc::alloc(len), len)
{
}
ByteBuffer::ByteBuffer(const char* buffer, size_t len) :
- _buffer(nullptr),
- _len(0),
+ _buffer(const_cast<char *>(buffer)),
+ _len(len),
_pos(0),
- _limit(0),
_ownedBuffer()
{
- set(buffer, len);
}
ByteBuffer::ByteBuffer(Alloc buffer, size_t len) :
_buffer(static_cast<char *>(buffer.get())),
_len(len),
_pos(0),
- _limit(len),
_ownedBuffer(std::move(buffer))
{
}
-ByteBuffer::ByteBuffer(const ByteBuffer& bb) :
- _buffer(0),
- _len(0),
- _pos(0),
- _limit(0),
+ByteBuffer::ByteBuffer(const ByteBuffer& rhs) :
+ _buffer(nullptr),
+ _len(rhs._len),
+ _pos(rhs._pos),
_ownedBuffer()
{
- *this = bb;
-}
-
-ByteBuffer& ByteBuffer::operator=(const ByteBuffer & org)
-{
- if (this != & org) {
- cleanUp();
- if (org._len > 0 && org._buffer) {
- Alloc::alloc(org._len + 1).swap(_ownedBuffer);
- _buffer = static_cast<char *>(_ownedBuffer.get());
- memcpy(_buffer,org._buffer,org._len);
- _buffer[org._len] = 0;
- }
- _len = org._len;
- _pos = org._pos;
- _limit = org._limit;
+ if (rhs._len > 0 && rhs._buffer) {
+ Alloc::alloc(rhs._len + 1).swap(_ownedBuffer);
+ _buffer = static_cast<char *>(_ownedBuffer.get());
+ memcpy(_buffer, rhs._buffer, rhs._len);
+ _buffer[rhs._len] = 0;
}
- return *this;
}
ByteBuffer::~ByteBuffer() = default;
@@ -120,32 +94,19 @@ ByteBuffer* ByteBuffer::copyBuffer(const char* buffer, size_t len)
void
ByteBuffer::setPos(size_t pos) // throw (BufferOutOfBoundsException)
{
- if (pos>_limit) {
- throwOutOfBounds(pos, _limit);
+ if (pos > _len) {
+ throwOutOfBounds(pos, _len);
} else {
_pos=pos;
}
}
-void
-ByteBuffer::setLimit(size_t limit) // throw (BufferOutOfBoundsException)
-{
- if (limit>_len) {
- throwOutOfBounds(limit, _len);
- } else {
- _limit=limit;
- }
-}
-
void ByteBuffer::incPos(size_t pos)
{
- if (_pos + pos > _limit) {
- throwOutOfBounds(_pos + pos, _limit);
+ if (_pos + pos > _len) {
+ throwOutOfBounds(_pos + pos, _len);
} else {
_pos+=pos;
-#ifdef __FORCE_VALGRIND_ON_SERIALIZE__
- forceValgrindStart2Pos();
-#endif
}
}
@@ -167,33 +128,6 @@ void ByteBuffer::putNumeric(uint8_t v) {
}
}
-size_t ByteBuffer::forceValgrindStart2Pos() const
-{
- size_t zeroCount(0);
- if (_buffer) {
- for(const char * c(_buffer), *e(c + _pos); c < e; c++) {
- if (*c == 0) {
- zeroCount++;
- }
- }
- }
- return zeroCount;
-}
-
-size_t ByteBuffer::forceValgrindPos2Lim() const
-{
- size_t zeroCount(0);
- if (_buffer) {
- for(const char * c(getBufferAtPos()), *e(c + getRemaining()); c < e; c++) {
- if (*c == 0) {
- zeroCount++;
- }
- }
- }
- return zeroCount;
-}
-
-
void ByteBuffer::getNumericNetwork(int16_t & v) {
if (__builtin_expect(getRemaining() < sizeof(v), 0)) {
throwOutOfBounds(getRemaining(), sizeof(v));
@@ -502,22 +436,5 @@ void ByteBuffer::putBytes(const void *buf, size_t count) {
incPosNoCheck(count);
}
}
-std::string ByteBuffer::toString() {
- std::ostringstream ost;
- StringUtil::printAsHex(ost, getBuffer(), getLength());
- return ost.str();
-}
-
-void ByteBuffer::swap(ByteBuffer& other) {
- std::swap(_buffer, other._buffer);
- std::swap(_len, other._len);
- std::swap(_pos, other._pos);
- std::swap(_limit, other._limit);
-}
-
-void ByteBuffer::cleanUp() {
- Alloc().swap(_ownedBuffer);
- _buffer = nullptr;
-}
} // document
diff --git a/document/src/vespa/document/util/bytebuffer.h b/document/src/vespa/document/util/bytebuffer.h
index a49bd55f8fe..b97c9ecee1a 100644
--- a/document/src/vespa/document/util/bytebuffer.h
+++ b/document/src/vespa/document/util/bytebuffer.h
@@ -22,14 +22,9 @@ class ByteBuffer
{
public:
typedef std::unique_ptr<ByteBuffer> UP;
- /**
- * Creates a byte buffer with no underlying buffer.
- * Use set() to set the buffer.
- */
- ByteBuffer();
ByteBuffer(const ByteBuffer &);
- ByteBuffer& operator=(const ByteBuffer &);
+ ByteBuffer& operator=(const ByteBuffer &) = delete;
ByteBuffer(ByteBuffer &&) = default;
ByteBuffer& operator=(ByteBuffer &&) = default;
@@ -55,21 +50,6 @@ public:
ByteBuffer(vespalib::alloc::Alloc buffer, size_t len);
/**
- * Sets the buffer pointed to by this buffer. Allows for multiple
- * usages of the same ByteBuffer.
- */
- void set(const char* buffer, size_t len) {
- cleanUp();
- _buffer = const_cast<char*>(buffer);
- _len=len;
- _limit=len;
- _pos=0;
- }
-
- /** Clear this buffer, and set free the underlying BufferHolder. */
- void reset() { set(nullptr, 0); }
-
- /**
* Creates a ByteBuffer object from another buffer. allocates
* a new buffer of same size and copies the content.
*
@@ -93,14 +73,11 @@ public:
/** @return Returns the index of the current position in the buffer. */
size_t getPos() const { return _pos; }
- /** @return Returns the limit. */
- size_t getLimit() const { return _limit; }
-
/**
* @return Returns the number of bytes remaining in the buffer - that is,
* getLimit()-getPos().
*/
- size_t getRemaining() const { return _limit-_pos; }
+ size_t getRemaining() const { return _len -_pos; }
/**
* Changes the position in the buffer.
@@ -110,17 +87,6 @@ public:
void setPos(size_t pos);
/**
- * Sets the buffer limit.
- *
- * @param limit The new limit.
- * @return True if the limit is legal (less than the length)
- * @throws BufferOutOfBoundsException;
- */
- void setLimit(size_t limit);
- size_t forceValgrindStart2Pos() const __attribute__ ((noinline));
- size_t forceValgrindPos2Lim() const __attribute__ ((noinline));
-
- /**
* Moves the position in the buffer.
*
* @param pos The number of bytes to move the position. The new position
@@ -134,9 +100,6 @@ public:
void incPosNoCheck(size_t pos) {
_pos += pos;
-#ifdef __FORCE_VALGRIND_ON_SERIALIZE__
- forceValgrindStart2Pos();
-#endif
}
/**
@@ -144,7 +107,6 @@ public:
* from a buffer you have written to
*/
void flip() {
- _limit = _pos;
_pos = 0;
}
@@ -154,7 +116,6 @@ public:
*/
void clear() {
_pos=0;
- _limit=_len;
}
void getNumeric(uint8_t & v);
@@ -340,16 +301,10 @@ public:
void putBytes(const void *buf, size_t count);
private:
- char * _buffer;
- size_t _len;
- size_t _pos;
- size_t _limit;
+ char * _buffer;
+ size_t _len;
+ size_t _pos;
vespalib::alloc::Alloc _ownedBuffer;
-public:
-
- std::string toString();
- void swap(ByteBuffer& other);
- void cleanUp();
};
} // document
diff --git a/document/src/vespa/document/util/serializable.cpp b/document/src/vespa/document/util/serializable.cpp
index 32c7bef90f0..e6881c598ac 100644
--- a/document/src/vespa/document/util/serializable.cpp
+++ b/document/src/vespa/document/util/serializable.cpp
@@ -12,7 +12,8 @@ IMPLEMENT_IDENTIFIABLE_ABSTRACT(Deserializable, Serializable);
VESPA_IMPLEMENT_EXCEPTION_SPINE(DeserializeException);
VESPA_IMPLEMENT_EXCEPTION_SPINE(SerializeException);
-std::unique_ptr<ByteBuffer> Serializable::serialize() const
+std::unique_ptr<ByteBuffer>
+Serializable::serialize() const
{
size_t len = getSerializedSize();
std::unique_ptr<ByteBuffer> retVal(new ByteBuffer(len));
diff --git a/document/src/vespa/document/util/serializable.h b/document/src/vespa/document/util/serializable.h
index 8818feceb9a..8039b3cd90b 100644
--- a/document/src/vespa/document/util/serializable.h
+++ b/document/src/vespa/document/util/serializable.h
@@ -12,12 +12,11 @@
#pragma once
+#include "bytebuffer.h"
+#include "identifiableid.h"
#include <vespa/vespalib/objects/cloneable.h>
#include <vespa/vespalib/objects/identifiable.h>
-#include <vespa/document/util/bytebuffer.h>
-#include <vespa/document/util/identifiableid.h>
-
namespace document {
class DocumentTypeRepo;