Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BF9F9181A5 for ; Tue, 3 Nov 2015 10:10:36 +0000 (UTC) Received: (qmail 42377 invoked by uid 500); 3 Nov 2015 10:10:36 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 42342 invoked by uid 500); 3 Nov 2015 10:10:36 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 42333 invoked by uid 99); 3 Nov 2015 10:10:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Nov 2015 10:10:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 78995E0991; Tue, 3 Nov 2015 10:10:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: ignite git commit: IGNITE-1814: CPP part. Date: Tue, 3 Nov 2015 10:10:36 +0000 (UTC) Repository: ignite Updated Branches: refs/heads/ignite-1814 014a9d1e0 -> f36e559de IGNITE-1814: CPP part. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f36e559d Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f36e559d Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f36e559d Branch: refs/heads/ignite-1814 Commit: f36e559de7610983542448685943170bf9116b79 Parents: 014a9d1 Author: vozerov-gridgain Authored: Tue Nov 3 13:09:21 2015 +0300 Committer: vozerov-gridgain Committed: Tue Nov 3 13:09:21 2015 +0300 ---------------------------------------------------------------------- .gitignore | 7 + .../src/portable_reader_writer_test.cpp | 251 +++++++++++++++---- .../ignite/impl/interop/interop_input_stream.h | 16 ++ .../ignite/impl/interop/interop_output_stream.h | 8 + .../ignite/impl/portable/portable_common.h | 6 + .../ignite/impl/portable/portable_reader_impl.h | 29 ++- .../ignite/impl/portable/portable_schema.h | 26 +- .../src/impl/interop/interop_input_stream.cpp | 20 ++ .../src/impl/interop/interop_output_stream.cpp | 7 + .../src/impl/portable/portable_reader_impl.cpp | 45 +++- .../core/src/impl/portable/portable_schema.cpp | 53 +++- .../src/impl/portable/portable_writer_impl.cpp | 21 +- 12 files changed, 423 insertions(+), 66 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 3da8e4d..22e3cc6 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,10 @@ target pom-installed.xml git-patch-prop-local.sh /slurp.sh +*.vcxproj.user +Apache.Ignite.sdf +ignite.sdf +ignite.opensdf +**/cpp/**/vs/x64/ +**/cpp/**/vs/Win32/ +**/dotnet/**/obj/ http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp b/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp index baeb9e7..3ec5a15 100644 --- a/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp +++ b/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp @@ -68,9 +68,9 @@ void CheckPrimitive(T val) in.Synchronize(); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8; + int32_t footerEnd = footerBegin + 5; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); try @@ -148,9 +148,9 @@ void CheckPrimitiveArray(T dflt, T val1, T val2) in.Synchronize(); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8; + int32_t footerEnd = footerBegin + 5; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -181,9 +181,9 @@ void CheckPrimitiveArray(T dflt, T val1, T val2) in.Synchronize(); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8; + int32_t footerEnd = footerBegin + 5; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -218,9 +218,9 @@ void CheckPrimitiveArray(T dflt, T val1, T val2) in.Synchronize(); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8; + int32_t footerEnd = footerBegin + 5; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -258,9 +258,9 @@ void CheckPrimitiveArray(T dflt, T val1, T val2) in.Synchronize(); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8; + int32_t footerEnd = footerBegin + 5; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -510,9 +510,9 @@ void CheckCollectionEmpty(CollectionType* colType) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -600,9 +600,9 @@ void CheckCollection(CollectionType* colType) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -677,9 +677,9 @@ void CheckCollectionIterators(CollectionType* colType) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -753,9 +753,9 @@ void CheckMapEmpty(MapType* mapType) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -846,9 +846,9 @@ void CheckMap(MapType* mapType) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1028,9 +1028,9 @@ BOOST_AUTO_TEST_CASE(TestGuidNull) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8; + int32_t footerEnd = footerBegin + 5; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1113,9 +1113,9 @@ BOOST_AUTO_TEST_CASE(TestString) { InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 5; + int32_t footerEnd = footerBegin + 5 * 5; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1191,9 +1191,9 @@ BOOST_AUTO_TEST_CASE(TestStringArrayNull) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1308,9 +1308,9 @@ BOOST_AUTO_TEST_CASE(TestStringArrayEmpty) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1435,9 +1435,9 @@ BOOST_AUTO_TEST_CASE(TestStringArray) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1549,14 +1549,15 @@ BOOST_AUTO_TEST_CASE(TestObject) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 3; + int32_t footerEnd = footerBegin + 5 * 3; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); PortableInner readVal1 = reader.ReadObject("field1"); + BOOST_REQUIRE(writeVal1.GetValue() == readVal1.GetValue()); PortableInner readVal2 = reader.ReadObject("field2"); @@ -1592,9 +1593,9 @@ BOOST_AUTO_TEST_CASE(TestNestedObject) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 3; + int32_t footerEnd = footerBegin + 5 * 3; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1634,9 +1635,9 @@ BOOST_AUTO_TEST_CASE(TestArrayNull) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1710,9 +1711,9 @@ BOOST_AUTO_TEST_CASE(TestArrayEmpty) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1794,9 +1795,9 @@ BOOST_AUTO_TEST_CASE(TestArray) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1855,9 +1856,9 @@ BOOST_AUTO_TEST_CASE(TestCollectionNull) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -1941,9 +1942,9 @@ BOOST_AUTO_TEST_CASE(TestMapNull) InteropInputStream in(&mem); int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); - int32_t footerEnd = footerBegin + 8 * 2; + int32_t footerEnd = footerBegin + 5 * 2; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -2034,7 +2035,7 @@ BOOST_AUTO_TEST_CASE(TestRawMode) int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); int32_t footerEnd = footerBegin; - PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, footerBegin, footerBegin, footerEnd); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, footerBegin, footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); in.Position(IGNITE_DFLT_HDR_LEN); @@ -2111,7 +2112,7 @@ BOOST_AUTO_TEST_CASE(TestFieldSeek) PortableReaderImpl readerImpl(&in, &idRslvr, pos, usrType, typeId, hashCode, len, rawOff, - footerBegin, footerEnd); + footerBegin, footerEnd, OFFSET_TYPE_1_BYTE); PortableReader reader(&readerImpl); @@ -2211,4 +2212,162 @@ BOOST_AUTO_TEST_CASE(TestFieldSeek) BOOST_REQUIRE(mapReader.IsNull()); } +BOOST_AUTO_TEST_CASE(TestSchemaOffset2ByteFields) +{ + const int fieldsNum = 64; + + TemplatedPortableIdResolver idRslvr; + + InteropUnpooledMemory mem(4096); + + InteropOutputStream out(&mem); + PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL, 0); + PortableWriter writer(&writerImpl); + + out.Position(IGNITE_DFLT_HDR_LEN); + + for (int i = 0; i < fieldsNum; ++i) + { + std::stringstream tmp; + tmp << "field" << i; + + writer.WriteInt32(tmp.str().c_str(), i * 10); + } + + writerImpl.PostWrite(); + + out.Synchronize(); + + InteropInputStream in(&mem); + + int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); + int32_t footerEnd = footerBegin + 6 * fieldsNum; + + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_2_BYTE); + PortableReader reader(&readerImpl); + + in.Position(IGNITE_DFLT_HDR_LEN); + + for (int i = 0; i < fieldsNum; ++i) + { + std::stringstream tmp; + tmp << "field" << i; + + BOOST_REQUIRE(reader.ReadInt32(tmp.str().c_str()) == i * 10); + } +} + +BOOST_AUTO_TEST_CASE(TestSchemaOffset4ByteFields) +{ + const int fieldsNum = 0x10000 / 4; + + TemplatedPortableIdResolver idRslvr; + + InteropUnpooledMemory mem(1024 * 1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL, 0); + PortableWriter writer(&writerImpl); + + out.Position(IGNITE_DFLT_HDR_LEN); + + for (int i = 0; i < fieldsNum; ++i) + { + std::stringstream tmp; + tmp << "field" << i; + + writer.WriteInt32(tmp.str().c_str(), i * 10); + } + + writerImpl.PostWrite(); + + out.Synchronize(); + + InteropInputStream in(&mem); + + int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); + int32_t footerEnd = footerBegin + 8 * fieldsNum; + + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_4_BYTE); + PortableReader reader(&readerImpl); + + in.Position(IGNITE_DFLT_HDR_LEN); + + for (int i = 0; i < fieldsNum; ++i) + { + std::stringstream tmp; + tmp << "field" << i; + + BOOST_REQUIRE(reader.ReadInt32(tmp.str().c_str()) == i * 10); + } +} + +BOOST_AUTO_TEST_CASE(TestSchemaOffset2ByteArray) +{ + TemplatedPortableIdResolver idRslvr; + + InteropUnpooledMemory mem(4096); + + InteropOutputStream out(&mem); + PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL, 0); + PortableWriter writer(&writerImpl); + + out.Position(IGNITE_DFLT_HDR_LEN); + + int8_t dummyArray[256] = {}; + + writer.WriteInt8Array("field1", dummyArray, sizeof(dummyArray)); + writer.WriteInt32("field2", 42); + + writerImpl.PostWrite(); + + out.Synchronize(); + + InteropInputStream in(&mem); + + int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); + int32_t footerEnd = footerBegin + 6 * 2; + + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_2_BYTE); + PortableReader reader(&readerImpl); + + in.Position(IGNITE_DFLT_HDR_LEN); + + BOOST_REQUIRE(reader.ReadInt32("field2") == 42); +} + +BOOST_AUTO_TEST_CASE(TestSchemaOffset4ByteArray) +{ + TemplatedPortableIdResolver idRslvr; + + InteropUnpooledMemory mem(1024 * 1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL, 0); + PortableWriter writer(&writerImpl); + + out.Position(IGNITE_DFLT_HDR_LEN); + + int8_t dummyArray[0x10000] = {}; + + writer.WriteInt8Array("field1", dummyArray, sizeof(dummyArray)); + writer.WriteInt32("field2", 42); + + writerImpl.PostWrite(); + + out.Synchronize(); + + InteropInputStream in(&mem); + + int32_t footerBegin = in.ReadInt32(IGNITE_OFFSET_SCHEMA_OR_RAW_OFF); + int32_t footerEnd = footerBegin + 8 * 2; + + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 100, 100, footerBegin, footerEnd, OFFSET_TYPE_4_BYTE); + PortableReader reader(&readerImpl); + + in.Position(IGNITE_DFLT_HDR_LEN); + + BOOST_REQUIRE(reader.ReadInt32("field2") == 42); +} + BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/include/ignite/impl/interop/interop_input_stream.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/interop/interop_input_stream.h b/modules/platforms/cpp/core/include/ignite/impl/interop/interop_input_stream.h index f23cec6..6842990 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/interop/interop_input_stream.h +++ b/modules/platforms/cpp/core/include/ignite/impl/interop/interop_input_stream.h @@ -44,6 +44,14 @@ namespace ignite * @return Value. */ int8_t ReadInt8(); + + /** + * Read signed 8-byte int at the given position. + * + * @param pos Position. + * @return Value. + */ + int32_t ReadInt8(int32_t pos); /** * Read signed 8-byte int array. @@ -76,6 +84,14 @@ namespace ignite int16_t ReadInt16(); /** + * Read signed 16-byte int at the given position. + * + * @param pos Position. + * @return Value. + */ + int32_t ReadInt16(int32_t pos); + + /** * Read signed 16-byte int array. * * @param res Allocated array. http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/include/ignite/impl/interop/interop_output_stream.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/interop/interop_output_stream.h b/modules/platforms/cpp/core/include/ignite/impl/interop/interop_output_stream.h index 211ac6d..0814c01 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/interop/interop_output_stream.h +++ b/modules/platforms/cpp/core/include/ignite/impl/interop/interop_output_stream.h @@ -83,6 +83,14 @@ namespace ignite void WriteInt16(const int16_t val); /** + * Write signed 16-byte integer at the given position. + * + * @param pos Position. + * @param val Value. + */ + void WriteInt16(const int32_t pos, const int16_t val); + + /** * Write signed 16-byte integer array. * * @param val Value. http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/include/ignite/impl/portable/portable_common.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_common.h b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_common.h index c6dad50..f08c49b 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_common.h +++ b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_common.h @@ -169,6 +169,12 @@ namespace ignite /** Raw only flag. */ const int16_t IGNITE_PORTABLE_FLAG_RAW_ONLY = 0x0002; + + /** Flag indicating that schema field offset is one byte long. */ + const int16_t IGNITE_PORTABLE_FLAG_OFFSET_1_BYTE = 0x0004; + + /** Flag indicating that schema field offset is two byte long. */ + const int16_t IGNITE_PORTABLE_FLAG_OFFSET_2_BYTE = 0x0008; } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h index fe25c87..4762fff 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h +++ b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h @@ -59,7 +59,7 @@ namespace ignite */ PortableReaderImpl(interop::InteropInputStream* stream, PortableIdResolver* idRslvr, int32_t pos, bool usrType, int32_t typeId, int32_t hashCode, int32_t len, int32_t rawOff, - int32_t footerBegin, int32_t footerEnd); + int32_t footerBegin, int32_t footerEnd, PortableOffsetType schemaType); /** * Constructor used to construct light-weight reader allowing only raw operations @@ -788,7 +788,27 @@ namespace ignite else footerBegin = schemaOrRawOff; - int32_t trailingBytes = (len - footerBegin) % 8; + PortableOffsetType schemaType; + int32_t trailingBytes; + + if (flags & IGNITE_PORTABLE_FLAG_OFFSET_1_BYTE) + { + schemaType = OFFSET_TYPE_1_BYTE; + + trailingBytes = (len - footerBegin) % 5; + } + else if (flags & IGNITE_PORTABLE_FLAG_OFFSET_2_BYTE) + { + schemaType = OFFSET_TYPE_2_BYTE; + + trailingBytes = (len - footerBegin) % 6; + } + else + { + schemaType = OFFSET_TYPE_4_BYTE; + + trailingBytes = (len - footerBegin) % 8; + } int32_t footerEnd = len - trailingBytes; @@ -806,7 +826,7 @@ namespace ignite TemplatedPortableIdResolver idRslvr(type); PortableReaderImpl readerImpl(stream, &idRslvr, pos, usrType, typeId, hashCode, len, rawOff, - footerBegin, footerEnd); + footerBegin, footerEnd, schemaType); ignite::portable::PortableReader reader(&readerImpl); T val = type.Read(reader); @@ -887,6 +907,9 @@ namespace ignite /** Footer ending position. */ int32_t footerEnd; + /** Object schema type. */ + PortableOffsetType schemaType; + IGNITE_NO_COPY_ASSIGNMENT(PortableReaderImpl) /** http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/include/ignite/impl/portable/portable_schema.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_schema.h b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_schema.h index 1795fd1..4919e2a 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_schema.h +++ b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_schema.h @@ -34,6 +34,21 @@ namespace ignite class PortableWriterImpl; /** + * Schema size variants. + */ + enum PortableOffsetType + { + /** Means all field offsets can be fit in one byte. */ + OFFSET_TYPE_1_BYTE, + + /** Means all field offsets can be fit in two bytes. */ + OFFSET_TYPE_2_BYTE, + + /** Means field offsets should be stored in four bytes. */ + OFFSET_TYPE_4_BYTE + }; + + /** * Portable schema. */ class IGNITE_IMPORT_EXPORT PortableSchema @@ -86,10 +101,17 @@ namespace ignite */ void Clear(); + /** + * Get type of schema. + * + * @return Type of schema. + */ + PortableOffsetType GetType() const; + private: /** - * Single schema field info. - */ + * Single schema field info. + */ struct PortableSchemaFieldInfo { int32_t id; http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/src/impl/interop/interop_input_stream.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/interop/interop_input_stream.cpp b/modules/platforms/cpp/core/src/impl/interop/interop_input_stream.cpp index 02e894c..fed7871 100644 --- a/modules/platforms/cpp/core/src/impl/interop/interop_input_stream.cpp +++ b/modules/platforms/cpp/core/src/impl/interop/interop_input_stream.cpp @@ -69,6 +69,16 @@ namespace ignite IGNITE_INTEROP_IN_READ(int8_t, 1); } + int32_t InteropInputStream::ReadInt8(int32_t pos) + { + int delta = pos + 1 - this->pos; + + if (delta > 0) + EnsureEnoughData(delta); + + return *reinterpret_cast(data + pos); + } + void InteropInputStream::ReadInt8Array(int8_t* const res, const int32_t len) { IGNITE_INTEROP_IN_READ_ARRAY(len, 0); @@ -90,6 +100,16 @@ namespace ignite IGNITE_INTEROP_IN_READ(int16_t, 2); } + int32_t InteropInputStream::ReadInt16(int32_t pos) + { + int delta = pos + 2 - this->pos; + + if (delta > 0) + EnsureEnoughData(delta); + + return *reinterpret_cast(data + pos); + } + void InteropInputStream::ReadInt16Array(int16_t* const res, const int32_t len) { IGNITE_INTEROP_IN_READ_ARRAY(len, 1); http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/src/impl/interop/interop_output_stream.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/interop/interop_output_stream.cpp b/modules/platforms/cpp/core/src/impl/interop/interop_output_stream.cpp index 1fd400b..acfd3ec 100644 --- a/modules/platforms/cpp/core/src/impl/interop/interop_output_stream.cpp +++ b/modules/platforms/cpp/core/src/impl/interop/interop_output_stream.cpp @@ -96,6 +96,13 @@ namespace ignite IGNITE_INTEROP_OUT_WRITE(val, int16_t, 2); } + void InteropOutputStream::WriteInt16(const int32_t pos, const int16_t val) + { + EnsureCapacity(pos + 2); + + *reinterpret_cast(data + pos) = val; + } + void InteropOutputStream::WriteInt16Array(const int16_t* val, const int32_t len) { IGNITE_INTEROP_OUT_WRITE_ARRAY(val, len << 1); http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp index 96378e0..fd2cc18 100644 --- a/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp +++ b/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp @@ -36,10 +36,10 @@ namespace ignite { PortableReaderImpl::PortableReaderImpl(InteropInputStream* stream, PortableIdResolver* idRslvr, int32_t pos, bool usrType, int32_t typeId, int32_t hashCode, int32_t len, int32_t rawOff, - int32_t footerBegin, int32_t footerEnd) : + int32_t footerBegin, int32_t footerEnd, PortableOffsetType schemaType) : stream(stream), idRslvr(idRslvr), pos(pos), usrType(usrType), typeId(typeId), hashCode(hashCode), len(len), rawOff(rawOff), rawMode(false), elemIdGen(0), elemId(0), - elemCnt(-1), elemRead(0), footerBegin(footerBegin), footerEnd(footerEnd) + elemCnt(-1), elemRead(0), footerBegin(footerBegin), footerEnd(footerEnd), schemaType(schemaType) { // No-op. } @@ -47,7 +47,7 @@ namespace ignite PortableReaderImpl::PortableReaderImpl(InteropInputStream* stream) : stream(stream), idRslvr(NULL), pos(0), usrType(false), typeId(0), hashCode(0), len(0), rawOff(0), rawMode(true), elemIdGen(0), elemId(0), elemCnt(-1), elemRead(0), footerBegin(-1), - footerEnd(-1) + footerEnd(-1), schemaType(OFFSET_TYPE_4_BYTE) { // No-op. } @@ -648,12 +648,43 @@ namespace ignite stream->Position(footerBegin); - for (int32_t schemaPos = footerBegin; schemaPos < footerEnd; schemaPos += 8) + switch (schemaType) { - int32_t currentFieldId = stream->ReadInt32(schemaPos); + case OFFSET_TYPE_1_BYTE: + { + for (int32_t schemaPos = footerBegin; schemaPos < footerEnd; schemaPos += 5) + { + int32_t currentFieldId = stream->ReadInt32(schemaPos); + + if (fieldId == currentFieldId) + return static_cast(stream->ReadInt8(schemaPos + 4)) + pos; + } + break; + } + + case OFFSET_TYPE_2_BYTE: + { + for (int32_t schemaPos = footerBegin; schemaPos < footerEnd; schemaPos += 6) + { + int32_t currentFieldId = stream->ReadInt32(schemaPos); - if (fieldId == currentFieldId) - return stream->ReadInt32(schemaPos + 4) + pos; + if (fieldId == currentFieldId) + return static_cast(stream->ReadInt16(schemaPos + 4)) + pos; + } + break; + } + + case OFFSET_TYPE_4_BYTE: + { + for (int32_t schemaPos = footerBegin; schemaPos < footerEnd; schemaPos += 8) + { + int32_t currentFieldId = stream->ReadInt32(schemaPos); + + if (fieldId == currentFieldId) + return stream->ReadInt32(schemaPos + 4) + pos; + } + break; + } } return -1; http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/src/impl/portable/portable_schema.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_schema.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_schema.cpp index 57c23a7..448cf02 100644 --- a/modules/platforms/cpp/core/src/impl/portable/portable_schema.cpp +++ b/modules/platforms/cpp/core/src/impl/portable/portable_schema.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#include + #include "ignite/impl/portable/portable_schema.h" #include "ignite/impl/portable/portable_writer_impl.h" @@ -66,10 +68,43 @@ namespace ignite void PortableSchema::Write(interop::InteropOutputStream& out) const { - for (FieldContainer::const_iterator i = fieldsInfo->begin(); i != fieldsInfo->end(); ++i) + switch (GetType()) { - out.WriteInt32(i->id); - out.WriteInt32(i->offset); + case OFFSET_TYPE_1_BYTE: + { + for (FieldContainer::const_iterator i = fieldsInfo->begin(); i != fieldsInfo->end(); ++i) + { + out.WriteInt32(i->id); + out.WriteInt8(static_cast(i->offset)); + } + break; + } + + case OFFSET_TYPE_2_BYTE: + { + for (FieldContainer::const_iterator i = fieldsInfo->begin(); i != fieldsInfo->end(); ++i) + { + out.WriteInt32(i->id); + out.WriteInt16(static_cast(i->offset)); + } + break; + } + + case OFFSET_TYPE_4_BYTE: + { + for (FieldContainer::const_iterator i = fieldsInfo->begin(); i != fieldsInfo->end(); ++i) + { + out.WriteInt32(i->id); + out.WriteInt32(i->offset); + } + break; + } + + default: + { + assert(false); + break; + } } } @@ -83,6 +118,18 @@ namespace ignite id = 0; fieldsInfo->clear(); } + + PortableOffsetType PortableSchema::GetType() const + { + int32_t maxOffset = fieldsInfo->back().offset; + + if (maxOffset < 0x100) + return OFFSET_TYPE_1_BYTE; + else if (maxOffset < 0x10000) + return OFFSET_TYPE_2_BYTE; + + return OFFSET_TYPE_4_BYTE; + } } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/f36e559d/modules/platforms/cpp/core/src/impl/portable/portable_writer_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_writer_impl.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_writer_impl.cpp index 4b65b4b..2dac125 100644 --- a/modules/platforms/cpp/core/src/impl/portable/portable_writer_impl.cpp +++ b/modules/platforms/cpp/core/src/impl/portable/portable_writer_impl.cpp @@ -567,13 +567,12 @@ namespace ignite { int32_t lenWithoutSchema = stream->Position() - start; + int32_t nonRawLen = rawPos == -1 ? lenWithoutSchema : rawPos - start; + if (schema.Empty()) { - InteropStreamPositionGuard guard(*stream); - - stream->Position(start + IGNITE_OFFSET_FLAGS); - stream->WriteInt16(IGNITE_PORTABLE_FLAG_USER_OBJECT | IGNITE_PORTABLE_FLAG_RAW_ONLY); - + stream->WriteInt16(start + IGNITE_OFFSET_FLAGS, IGNITE_PORTABLE_FLAG_USER_OBJECT | + IGNITE_PORTABLE_FLAG_RAW_ONLY); stream->WriteInt32(start + IGNITE_OFFSET_LEN, lenWithoutSchema); stream->WriteInt32(start + IGNITE_OFFSET_SCHEMA_ID, 0); stream->WriteInt32(start + IGNITE_OFFSET_SCHEMA_OR_RAW_OFF, GetRawPosition() - start); @@ -581,6 +580,7 @@ namespace ignite else { int32_t schemaId = schema.GetId(); + PortableOffsetType schemaType = schema.GetType(); WriteAndClearSchema(); @@ -589,6 +589,17 @@ namespace ignite int32_t length = stream->Position() - start; + if (schemaType == OFFSET_TYPE_1_BYTE) + { + stream->WriteInt16(start + IGNITE_OFFSET_FLAGS, + IGNITE_PORTABLE_FLAG_USER_OBJECT | IGNITE_PORTABLE_FLAG_OFFSET_1_BYTE); + } + else if (schemaType == OFFSET_TYPE_2_BYTE) + { + stream->WriteInt16(start + IGNITE_OFFSET_FLAGS, + IGNITE_PORTABLE_FLAG_USER_OBJECT | IGNITE_PORTABLE_FLAG_OFFSET_2_BYTE); + } + stream->WriteInt32(start + IGNITE_OFFSET_LEN, length); stream->WriteInt32(start + IGNITE_OFFSET_SCHEMA_ID, schemaId); stream->WriteInt32(start + IGNITE_OFFSET_SCHEMA_OR_RAW_OFF, lenWithoutSchema);