http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/modules/platforms/cpp/core/src/impl/cache/query/query_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/cache/query/query_impl.cpp b/modules/platforms/cpp/core/src/impl/cache/query/query_impl.cpp index 786779b..a5fc494 100644 --- a/modules/platforms/cpp/core/src/impl/cache/query/query_impl.cpp +++ b/modules/platforms/cpp/core/src/impl/cache/query/query_impl.cpp @@ -21,7 +21,7 @@ using namespace ignite::common::concurrent; using namespace ignite::common::java; using namespace ignite::impl::interop; -using namespace ignite::impl::portable; +using namespace ignite::impl::binary; namespace ignite { @@ -100,7 +100,7 @@ namespace ignite { InteropInputStream in(inMem.Get()); - portable::PortableReaderImpl reader(&in); + binary::BinaryReaderImpl reader(&in); op.ProcessOutput(reader); @@ -183,7 +183,7 @@ namespace ignite InteropInputStream in(inMem.Get()); - portable::PortableReaderImpl reader(&in); + binary::BinaryReaderImpl reader(&in); op.ProcessOutput(reader); }
http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/modules/platforms/cpp/core/src/impl/ignite_environment.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/ignite_environment.cpp b/modules/platforms/cpp/core/src/impl/ignite_environment.cpp index 0263956..013a139 100644 --- a/modules/platforms/cpp/core/src/impl/ignite_environment.cpp +++ b/modules/platforms/cpp/core/src/impl/ignite_environment.cpp @@ -15,15 +15,15 @@ * limitations under the License. */ -#include "ignite/impl/portable/portable_reader_impl.h" +#include "ignite/impl/binary/binary_reader_impl.h" #include "ignite/impl/ignite_environment.h" -#include "ignite/portable/portable.h" +#include "ignite/binary/binary.h" using namespace ignite::common::concurrent; using namespace ignite::common::java; using namespace ignite::impl::interop; -using namespace ignite::impl::portable; -using namespace ignite::portable; +using namespace ignite::impl::binary; +using namespace ignite::binary; namespace ignite { @@ -56,7 +56,7 @@ namespace ignite } IgniteEnvironment::IgniteEnvironment() : ctx(SharedPointer<JniContext>()), latch(new SingleLatch), name(NULL), - metaMgr(new PortableMetadataManager()) + metaMgr(new BinaryTypeManager()) { // No-op. } @@ -136,7 +136,7 @@ namespace ignite } } - PortableMetadataManager* IgniteEnvironment::GetMetadataManager() + BinaryTypeManager* IgniteEnvironment::GetTypeManager() { return metaMgr; } @@ -146,7 +146,7 @@ namespace ignite InteropExternalMemory mem(reinterpret_cast<int8_t*>(memPtr)); InteropInputStream stream(&mem); - PortableReaderImpl reader(&stream); + BinaryReaderImpl reader(&stream); int32_t nameLen = reader.ReadString(NULL, 0); http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/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 fed7871..7bdda0b 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 @@ -43,13 +43,13 @@ namespace ignite { namespace interop { - union PortableInt32Float + union BinaryInt32Float { int32_t i; float f; }; - union PortableInt64Double + union BinaryInt64Double { int64_t i; double d; @@ -157,7 +157,7 @@ namespace ignite float InteropInputStream::ReadFloat() { - PortableInt32Float u; + BinaryInt32Float u; u.i = ReadInt32(); @@ -171,7 +171,7 @@ namespace ignite double InteropInputStream::ReadDouble() { - PortableInt64Double u; + BinaryInt64Double u; u.i = ReadInt64(); http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/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 acfd3ec..a69a624 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 @@ -42,13 +42,13 @@ namespace ignite { namespace interop { - union PortableFloatInt32 + union BinaryFloatInt32 { float f; int32_t i; }; - union PortableDoubleInt64 + union BinaryDoubleInt64 { double d; int64_t i; @@ -147,7 +147,7 @@ namespace ignite void InteropOutputStream::WriteFloat(const float val) { - PortableFloatInt32 u; + BinaryFloatInt32 u; u.f = val; @@ -162,7 +162,7 @@ namespace ignite void InteropOutputStream::WriteDouble(const double val) { - PortableDoubleInt64 u; + BinaryDoubleInt64 u; u.d = val; http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/modules/platforms/cpp/core/src/impl/portable/portable_metadata_handler.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_handler.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_metadata_handler.cpp deleted file mode 100644 index 5ca91dc..0000000 --- a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_handler.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/portable/portable_metadata_handler.h" - -using namespace ignite::common::concurrent; - -namespace ignite -{ - namespace impl - { - namespace portable - { - PortableMetadataHandler::PortableMetadataHandler(SPSnap snap) : snap(snap), fieldIds(NULL), fields(NULL) - { - // No-op. - } - - PortableMetadataHandler::~PortableMetadataHandler() - { - if (fieldIds) - delete fieldIds; - - if (fields) - delete fields; - } - - void PortableMetadataHandler::OnFieldWritten(int32_t fieldId, std::string fieldName, int32_t fieldTypeId) - { - if (!snap.Get() || !snap.Get()->ContainsFieldId(fieldId)) - { - if (!HasDifference()) - { - fieldIds = new std::set<int32_t>(); - fields = new std::map<std::string, int32_t>(); - } - - fieldIds->insert(fieldId); - (*fields)[fieldName] = fieldTypeId; - } - } - - SPSnap PortableMetadataHandler::GetSnapshot() - { - return snap; - } - - bool PortableMetadataHandler::HasDifference() - { - return fieldIds ? true : false; - } - - std::set<int32_t>* PortableMetadataHandler::GetFieldIds() - { - return fieldIds; - } - - std::map<std::string, int32_t>* PortableMetadataHandler::GetFields() - { - return fields; - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/modules/platforms/cpp/core/src/impl/portable/portable_metadata_manager.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_manager.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_metadata_manager.cpp deleted file mode 100644 index 63e92a9..0000000 --- a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_manager.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <ignite/common/concurrent.h> - -#include "ignite/impl/portable/portable_metadata_manager.h" - -using namespace ignite::common::concurrent; - -namespace ignite -{ - namespace impl - { - namespace portable - { - PortableMetadataManager::PortableMetadataManager() : - snapshots(SharedPointer<std::map<int32_t, SPSnap>>(new std::map<int32_t, SPSnap>)), - pending(new std::vector<SPSnap>()), - cs(new CriticalSection()), - pendingVer(0), ver(0) - { - // No-op. - } - - PortableMetadataManager::~PortableMetadataManager() - { - pending->erase(pending->begin(), pending->end()); - - delete pending; - delete cs; - } - - SharedPointer<PortableMetadataHandler> PortableMetadataManager::GetHandler(int32_t typeId) - { - SharedPointer<std::map<int32_t, SPSnap>> snapshots0 = snapshots; - - SPSnap snapshot = (*snapshots0.Get())[typeId]; - - return SharedPointer<PortableMetadataHandler>(new PortableMetadataHandler(snapshot)); - } - - void PortableMetadataManager::SubmitHandler(std::string typeName, int32_t typeId, - PortableMetadataHandler* hnd) - { - Snap* snap = hnd->GetSnapshot().Get(); - - // If this is the very first write of a class or difference exists, - // we need to enqueue it for write. - if (!snap || hnd->HasDifference()) - { - std::set<int32_t>* newFieldIds = new std::set<int32_t>(); - std::map<std::string, int32_t>* newFields = new std::map<std::string, int32_t>(); - - CopyFields(snap, newFieldIds, newFields); - - if (hnd->HasDifference()) - { - std::set<int32_t>* diffFieldIds = hnd->GetFieldIds(); - std::map<std::string, int32_t>* diffFields = hnd->GetFields(); - - for (std::set<int32_t>::iterator it = diffFieldIds->begin(); it != diffFieldIds->end(); ++it) - newFieldIds->insert(*it); - - for (std::map<std::string, int32_t>::iterator it = diffFields->begin(); it != diffFields->end(); ++it) - (*newFields)[it->first] = it->second; - } - - Snap* diffSnap = new Snap(typeName, typeId, newFieldIds, newFields); - - cs->Enter(); - - pending->push_back(SPSnap(diffSnap)); - - pendingVer++; - - cs->Leave(); - } - } - - int32_t PortableMetadataManager::GetVersion() - { - Memory::Fence(); - - return ver; - } - - bool PortableMetadataManager::IsUpdatedSince(int32_t oldVer) - { - Memory::Fence(); - - return pendingVer > oldVer; - } - - bool PortableMetadataManager::ProcessPendingUpdates(PortableMetadataUpdater* updater, IgniteError* err) - { - bool success = true; // Optimistically assume that all will be fine. - - cs->Enter(); - - for (std::vector<SPSnap>::iterator it = pending->begin(); it != pending->end(); ++it) - { - Snap* pendingSnap = (*it).Get(); - - if (updater->Update(pendingSnap, err)) - { - // Perform copy-on-write update of snapshot collection. - std::map<int32_t, SPSnap>* newSnapshots = new std::map<int32_t, SPSnap>(); - - bool snapshotFound = false; - - for (std::map<int32_t, SPSnap>::iterator snapIt = snapshots.Get()->begin(); - snapIt != snapshots.Get()->end(); ++snapIt) - { - int32_t curTypeId = snapIt->first; - Snap* curSnap = snapIt->second.Get(); - - if (pendingSnap->GetTypeId() == curTypeId) - { - // Have to create snapshot with updated fields. - std::set<int32_t>* newFieldIds = new std::set<int32_t>(); - std::map<std::string, int32_t>* newFields = new std::map<std::string, int32_t>(); - - // Add old fields. - CopyFields(curSnap, newFieldIds, newFields); - - // Add new fields. - CopyFields(pendingSnap, newFieldIds, newFields); - - // Create new snapshot. - Snap* newSnap = new Snap(pendingSnap->GetTypeName(), pendingSnap->GetTypeId(), - newFieldIds, newFields); - - (*newSnapshots)[curTypeId] = SPSnap(newSnap); - - snapshotFound = true; - } - else - (*newSnapshots)[curTypeId] = snapIt->second; // Just transfer exising snapshot. - } - - // Handle situation when completely new snapshot is found. - if (!snapshotFound) - (*newSnapshots)[pendingSnap->GetTypeId()] = *it; - - snapshots = SharedPointer<std::map<int32_t, SPSnap>>(newSnapshots); - } - else - { - // Stop as we cannot move further. - success = false; - - break; - } - } - - if (success) - { - pending->erase(pending->begin(), pending->end()); - - ver = pendingVer; - } - - cs->Leave(); - - return success; - } - - void PortableMetadataManager::CopyFields(Snap* snap, std::set<int32_t>* fieldIds, - std::map<std::string, int32_t>* fields) - { - if (snap && snap->HasFields()) - { - std::set<int32_t>* snapFieldIds = snap->GetFieldIds(); - std::map<std::string, int32_t>* snapFields = snap->GetFields(); - - for (std::set<int32_t>::iterator oldIt = snapFieldIds->begin(); - oldIt != snapFieldIds->end(); ++oldIt) - fieldIds->insert(*oldIt); - - for (std::map<std::string, int32_t>::iterator newFieldsIt = snapFields->begin(); - newFieldsIt != snapFields->end(); ++newFieldsIt) - (*fields)[newFieldsIt->first] = newFieldsIt->second; - } - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/modules/platforms/cpp/core/src/impl/portable/portable_metadata_snapshot.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_snapshot.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_metadata_snapshot.cpp deleted file mode 100644 index 6ce5ab5..0000000 --- a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_snapshot.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/portable/portable_metadata_snapshot.h" - -namespace ignite -{ - namespace impl - { - namespace portable - { - PortableMetadataSnapshot::PortableMetadataSnapshot(std::string typeName, int32_t typeId, - std::set<int32_t>* fieldIds, std::map<std::string, int32_t>* fields) : - typeName(typeName), typeId(typeId), fieldIds(fieldIds), fields(fields) - { - // No-op. - } - - PortableMetadataSnapshot::~PortableMetadataSnapshot() - { - delete fieldIds; - delete fields; - } - - bool PortableMetadataSnapshot::ContainsFieldId(int32_t fieldId) - { - return fieldIds && fieldIds->count(fieldId) == 1; - } - - std::string PortableMetadataSnapshot::GetTypeName() - { - return typeName; - } - - int32_t PortableMetadataSnapshot::GetTypeId() - { - return typeId; - } - - bool PortableMetadataSnapshot::HasFields() - { - return !fieldIds->empty(); - } - - std::set<int32_t>* PortableMetadataSnapshot::GetFieldIds() - { - return fieldIds; - } - - std::map<std::string, int32_t>* PortableMetadataSnapshot::GetFields() - { - return fields; - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/modules/platforms/cpp/core/src/impl/portable/portable_metadata_updater.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_updater.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_metadata_updater.cpp deleted file mode 100644 index 81c96d7..0000000 --- a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_updater.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/portable/portable_metadata_updater.h" - -namespace ignite -{ - namespace impl - { - namespace portable - { - PortableMetadataUpdater::~PortableMetadataUpdater() - { - // No-op. - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/modules/platforms/cpp/core/src/impl/portable/portable_metadata_updater_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_updater_impl.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_metadata_updater_impl.cpp deleted file mode 100644 index 07a1758..0000000 --- a/modules/platforms/cpp/core/src/impl/portable/portable_metadata_updater_impl.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/portable/portable_metadata_updater_impl.h" -#include "ignite/impl/interop/interop_output_stream.h" -#include "ignite/impl/portable/portable_writer_impl.h" -#include "ignite/portable/portable_raw_writer.h" - -using namespace ignite::common::concurrent; -using namespace ignite::common::java; -using namespace ignite::impl; -using namespace ignite::impl::interop; -using namespace ignite::portable; - -namespace ignite -{ - namespace impl - { - namespace portable - { - /** Operation: Clear. */ - const int32_t OP_METADATA = -1; - - PortableMetadataUpdaterImpl::PortableMetadataUpdaterImpl(SharedPointer<IgniteEnvironment> env, - jobject javaRef) : env(env), javaRef(javaRef) - { - // No-op. - } - - PortableMetadataUpdaterImpl::~PortableMetadataUpdaterImpl() - { - // No-op. - } - - bool PortableMetadataUpdaterImpl::Update(Snap* snap, IgniteError* err) - { - JniErrorInfo jniErr; - - SharedPointer<InteropMemory> mem = env.Get()->AllocateMemory(); - - InteropOutputStream out(mem.Get()); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - // We always pass only one meta at a time in current implementation for simplicity. - rawWriter.WriteInt32(1); - - rawWriter.WriteInt32(snap->GetTypeId()); - rawWriter.WriteString(snap->GetTypeName()); - rawWriter.WriteString(NULL); // Affinity key is not supported for now. - - if (snap->HasFields()) - { - std::map<std::string, int32_t>* fields = snap->GetFields(); - - rawWriter.WriteInt32(static_cast<int32_t>(fields->size())); - - for (std::map<std::string, int32_t>::iterator it = fields->begin(); it != fields->end(); ++it) - { - rawWriter.WriteString(it->first); - rawWriter.WriteInt32(it->second); - } - } - else - rawWriter.WriteInt32(0); - - out.Synchronize(); - - long long res = env.Get()->Context()->TargetInStreamOutLong(javaRef, OP_METADATA, mem.Get()->PointerLong(), &jniErr); - - IgniteError::SetError(jniErr.code, jniErr.errCls, jniErr.errMsg, err); - - if (jniErr.code == IGNITE_JNI_ERR_SUCCESS) - return res == 1; - else - return false; - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/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 deleted file mode 100644 index 37e8a22..0000000 --- a/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp +++ /dev/null @@ -1,760 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/interop/interop.h" -#include "ignite/impl/portable/portable_common.h" -#include "ignite/impl/portable/portable_id_resolver.h" -#include "ignite/impl/portable/portable_reader_impl.h" -#include "ignite/impl/portable/portable_utils.h" -#include "ignite/portable/portable_type.h" -#include "ignite/ignite_error.h" -#include "ignite/impl/interop/interop_stream_position_guard.h" - -using namespace ignite::impl::interop; -using namespace ignite::impl::portable; -using namespace ignite::portable; - -namespace ignite -{ - namespace impl - { - namespace portable - { - 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, 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), schemaType(schemaType) - { - // No-op. - } - - 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), schemaType(OFFSET_TYPE_4_BYTE) - { - // No-op. - } - - int8_t PortableReaderImpl::ReadInt8() - { - return ReadRaw<int8_t>(PortableUtils::ReadInt8); - } - - int32_t PortableReaderImpl::ReadInt8Array(int8_t* res, const int32_t len) - { - return ReadRawArray<int8_t>(res, len, PortableUtils::ReadInt8Array, IGNITE_TYPE_ARRAY_BYTE); - } - - int8_t PortableReaderImpl::ReadInt8(const char* fieldName) - { - return Read(fieldName, PortableUtils::ReadInt8, IGNITE_TYPE_BYTE, static_cast<int8_t>(0)); - } - - int32_t PortableReaderImpl::ReadInt8Array(const char* fieldName, int8_t* res, const int32_t len) - { - return ReadArray<int8_t>(fieldName, res, len,PortableUtils::ReadInt8Array, IGNITE_TYPE_ARRAY_BYTE); - } - - bool PortableReaderImpl::ReadBool() - { - return ReadRaw<bool>(PortableUtils::ReadBool); - } - - int32_t PortableReaderImpl::ReadBoolArray(bool* res, const int32_t len) - { - return ReadRawArray<bool>(res, len, PortableUtils::ReadBoolArray, IGNITE_TYPE_ARRAY_BOOL); - } - - bool PortableReaderImpl::ReadBool(const char* fieldName) - { - return Read(fieldName, PortableUtils::ReadBool, IGNITE_TYPE_BOOL, static_cast<bool>(0)); - } - - int32_t PortableReaderImpl::ReadBoolArray(const char* fieldName, bool* res, const int32_t len) - { - return ReadArray<bool>(fieldName, res, len,PortableUtils::ReadBoolArray, IGNITE_TYPE_ARRAY_BOOL); - } - - int16_t PortableReaderImpl::ReadInt16() - { - return ReadRaw<int16_t>(PortableUtils::ReadInt16); - } - - int32_t PortableReaderImpl::ReadInt16Array(int16_t* res, const int32_t len) - { - return ReadRawArray<int16_t>(res, len, PortableUtils::ReadInt16Array, IGNITE_TYPE_ARRAY_SHORT); - } - - int16_t PortableReaderImpl::ReadInt16(const char* fieldName) - { - return Read(fieldName, PortableUtils::ReadInt16, IGNITE_TYPE_SHORT, static_cast<int16_t>(0)); - } - - int32_t PortableReaderImpl::ReadInt16Array(const char* fieldName, int16_t* res, const int32_t len) - { - return ReadArray<int16_t>(fieldName, res, len, PortableUtils::ReadInt16Array, IGNITE_TYPE_ARRAY_SHORT); - } - - uint16_t PortableReaderImpl::ReadUInt16() - { - return ReadRaw<uint16_t>(PortableUtils::ReadUInt16); - } - - int32_t PortableReaderImpl::ReadUInt16Array(uint16_t* res, const int32_t len) - { - return ReadRawArray<uint16_t>(res, len, PortableUtils::ReadUInt16Array, IGNITE_TYPE_ARRAY_CHAR); - } - - uint16_t PortableReaderImpl::ReadUInt16(const char* fieldName) - { - return Read(fieldName, PortableUtils::ReadUInt16, IGNITE_TYPE_CHAR, static_cast<uint16_t>(0)); - } - - int32_t PortableReaderImpl::ReadUInt16Array(const char* fieldName, uint16_t* res, const int32_t len) - { - return ReadArray<uint16_t>(fieldName, res, len,PortableUtils::ReadUInt16Array, IGNITE_TYPE_ARRAY_CHAR); - } - - int32_t PortableReaderImpl::ReadInt32() - { - return ReadRaw<int32_t>(PortableUtils::ReadInt32); - } - - int32_t PortableReaderImpl::ReadInt32Array(int32_t* res, const int32_t len) - { - return ReadRawArray<int32_t>(res, len, PortableUtils::ReadInt32Array, IGNITE_TYPE_ARRAY_INT); - } - - int32_t PortableReaderImpl::ReadInt32(const char* fieldName) - { - return Read(fieldName, PortableUtils::ReadInt32, IGNITE_TYPE_INT, static_cast<int32_t>(0)); - } - - int32_t PortableReaderImpl::ReadInt32Array(const char* fieldName, int32_t* res, const int32_t len) - { - return ReadArray<int32_t>(fieldName, res, len,PortableUtils::ReadInt32Array, IGNITE_TYPE_ARRAY_INT); - } - - int64_t PortableReaderImpl::ReadInt64() - { - return ReadRaw<int64_t>(PortableUtils::ReadInt64); - } - - int32_t PortableReaderImpl::ReadInt64Array(int64_t* res, const int32_t len) - { - return ReadRawArray<int64_t>(res, len, PortableUtils::ReadInt64Array, IGNITE_TYPE_ARRAY_LONG); - } - - int64_t PortableReaderImpl::ReadInt64(const char* fieldName) - { - return Read(fieldName, PortableUtils::ReadInt64, IGNITE_TYPE_LONG, static_cast<int64_t>(0)); - } - - int32_t PortableReaderImpl::ReadInt64Array(const char* fieldName, int64_t* res, const int32_t len) - { - return ReadArray<int64_t>(fieldName, res, len,PortableUtils::ReadInt64Array, IGNITE_TYPE_ARRAY_LONG); - } - - float PortableReaderImpl::ReadFloat() - { - return ReadRaw<float>(PortableUtils::ReadFloat); - } - - int32_t PortableReaderImpl::ReadFloatArray(float* res, const int32_t len) - { - return ReadRawArray<float>(res, len, PortableUtils::ReadFloatArray, IGNITE_TYPE_ARRAY_FLOAT); - } - - float PortableReaderImpl::ReadFloat(const char* fieldName) - { - return Read(fieldName, PortableUtils::ReadFloat, IGNITE_TYPE_FLOAT, static_cast<float>(0)); - } - - int32_t PortableReaderImpl::ReadFloatArray(const char* fieldName, float* res, const int32_t len) - { - return ReadArray<float>(fieldName, res, len,PortableUtils::ReadFloatArray, IGNITE_TYPE_ARRAY_FLOAT); - } - - double PortableReaderImpl::ReadDouble() - { - return ReadRaw<double>(PortableUtils::ReadDouble); - } - - int32_t PortableReaderImpl::ReadDoubleArray(double* res, const int32_t len) - { - return ReadRawArray<double>(res, len, PortableUtils::ReadDoubleArray, IGNITE_TYPE_ARRAY_DOUBLE); - } - - double PortableReaderImpl::ReadDouble(const char* fieldName) - { - return Read(fieldName, PortableUtils::ReadDouble, IGNITE_TYPE_DOUBLE, static_cast<double>(0)); - } - - int32_t PortableReaderImpl::ReadDoubleArray(const char* fieldName, double* res, const int32_t len) - { - return ReadArray<double>(fieldName, res, len,PortableUtils::ReadDoubleArray, IGNITE_TYPE_ARRAY_DOUBLE); - } - - Guid PortableReaderImpl::ReadGuid() - { - CheckRawMode(true); - CheckSingleMode(true); - - return ReadNullable(stream, PortableUtils::ReadGuid, IGNITE_TYPE_UUID); - } - - int32_t PortableReaderImpl::ReadGuidArray(Guid* res, const int32_t len) - { - CheckRawMode(true); - CheckSingleMode(true); - - return ReadArrayInternal<Guid>(res, len, stream, ReadGuidArrayInternal, IGNITE_TYPE_ARRAY_UUID); - } - - Guid PortableReaderImpl::ReadGuid(const char* fieldName) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return Guid(); - - stream->Position(fieldPos); - - return ReadNullable(stream, PortableUtils::ReadGuid, IGNITE_TYPE_UUID); - } - - int32_t PortableReaderImpl::ReadGuidArray(const char* fieldName, Guid* res, const int32_t len) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return -1; - - stream->Position(fieldPos); - - int32_t realLen = ReadArrayInternal<Guid>(res, len, stream, ReadGuidArrayInternal, IGNITE_TYPE_ARRAY_UUID); - - return realLen; - } - - void PortableReaderImpl::ReadGuidArrayInternal(InteropInputStream* stream, Guid* res, const int32_t len) - { - for (int i = 0; i < len; i++) - *(res + i) = ReadNullable<Guid>(stream, PortableUtils::ReadGuid, IGNITE_TYPE_UUID); - } - - int32_t PortableReaderImpl::ReadString(char* res, const int32_t len) - { - CheckRawMode(true); - CheckSingleMode(true); - - return ReadStringInternal(res, len); - } - - int32_t PortableReaderImpl::ReadString(const char* fieldName, char* res, const int32_t len) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return -1; - - stream->Position(fieldPos); - - int32_t realLen = ReadStringInternal(res, len); - - return realLen; - } - - int32_t PortableReaderImpl::ReadStringArray(int32_t* size) - { - return StartContainerSession(true, IGNITE_TYPE_ARRAY_STRING, size); - } - - int32_t PortableReaderImpl::ReadStringArray(const char* fieldName, int32_t* size) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - { - *size = -1; - - return ++elemIdGen; - } - - stream->Position(fieldPos); - - return StartContainerSession(false, IGNITE_TYPE_ARRAY_STRING, size); - } - - int32_t PortableReaderImpl::ReadStringElement(int32_t id, char* res, const int32_t len) - { - CheckSession(id); - - int32_t posBefore = stream->Position(); - - int32_t realLen = ReadStringInternal(res, len); - - int32_t posAfter = stream->Position(); - - if (posAfter > posBefore && ++elemRead == elemCnt) { - elemId = 0; - elemCnt = -1; - elemRead = 0; - } - - return realLen; - } - - int32_t PortableReaderImpl::ReadStringInternal(char* res, const int32_t len) - { - int8_t hdr = stream->ReadInt8(); - - if (hdr == IGNITE_TYPE_STRING) { - int32_t realLen = stream->ReadInt32(); - - if (res && len >= realLen) { - for (int i = 0; i < realLen; i++) - *(res + i) = static_cast<char>(stream->ReadInt8()); - - if (len > realLen) - *(res + realLen) = 0; // Set NULL terminator if possible. - } - else - stream->Position(stream->Position() - 4 - 1); - - return realLen; - } - else if (hdr != IGNITE_HDR_NULL) - ThrowOnInvalidHeader(IGNITE_TYPE_ARRAY, hdr); - - return -1; - } - - int32_t PortableReaderImpl::ReadArray(int32_t* size) - { - return StartContainerSession(true, IGNITE_TYPE_ARRAY, size); - } - - int32_t PortableReaderImpl::ReadArray(const char* fieldName, int32_t* size) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - { - *size = -1; - - return ++elemIdGen; - } - - stream->Position(fieldPos); - - return StartContainerSession(false, IGNITE_TYPE_ARRAY, size); - } - - int32_t PortableReaderImpl::ReadCollection(CollectionType* typ, int32_t* size) - { - int32_t id = StartContainerSession(true, IGNITE_TYPE_COLLECTION, size); - - if (*size == -1) - *typ = IGNITE_COLLECTION_UNDEFINED; - else - *typ = static_cast<CollectionType>(stream->ReadInt8()); - - return id; - } - - int32_t PortableReaderImpl::ReadCollection(const char* fieldName, CollectionType* typ, int32_t* size) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - { - *typ = IGNITE_COLLECTION_UNDEFINED; - *size = -1; - - return ++elemIdGen; - } - - stream->Position(fieldPos); - - int32_t id = StartContainerSession(false, IGNITE_TYPE_COLLECTION, size); - - if (*size == -1) - *typ = IGNITE_COLLECTION_UNDEFINED; - else - *typ = static_cast<CollectionType>(stream->ReadInt8()); - - return id; - } - - int32_t PortableReaderImpl::ReadMap(MapType* typ, int32_t* size) - { - int32_t id = StartContainerSession(true, IGNITE_TYPE_MAP, size); - - if (*size == -1) - *typ = IGNITE_MAP_UNDEFINED; - else - *typ = static_cast<MapType>(stream->ReadInt8()); - - return id; - } - - int32_t PortableReaderImpl::ReadMap(const char* fieldName, MapType* typ, int32_t* size) - { - CheckRawMode(false); - CheckSingleMode(true); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - { - *typ = IGNITE_MAP_UNDEFINED; - *size = -1; - - return ++elemIdGen; - } - - stream->Position(fieldPos); - - int32_t id = StartContainerSession(false, IGNITE_TYPE_MAP, size); - - if (*size == -1) - *typ = IGNITE_MAP_UNDEFINED; - else - *typ = static_cast<MapType>(stream->ReadInt8()); - - return id; - } - - CollectionType PortableReaderImpl::ReadCollectionTypeUnprotected() - { - int32_t size = ReadCollectionSizeUnprotected(); - if (size == -1) - return IGNITE_COLLECTION_UNDEFINED; - - CollectionType typ = static_cast<CollectionType>(stream->ReadInt8()); - - return typ; - } - - CollectionType PortableReaderImpl::ReadCollectionType() - { - InteropStreamPositionGuard<InteropInputStream> positionGuard(*stream); - - return ReadCollectionTypeUnprotected(); - } - - CollectionType PortableReaderImpl::ReadCollectionType(const char* fieldName) - { - CheckRawMode(false); - CheckSingleMode(true); - - InteropStreamPositionGuard<InteropInputStream> positionGuard(*stream); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return IGNITE_COLLECTION_UNDEFINED; - - stream->Position(fieldPos); - - return ReadCollectionTypeUnprotected(); - } - - int32_t PortableReaderImpl::ReadCollectionSizeUnprotected() - { - int8_t hdr = stream->ReadInt8(); - - if (hdr != IGNITE_TYPE_COLLECTION) - { - if (hdr != IGNITE_HDR_NULL) - ThrowOnInvalidHeader(IGNITE_TYPE_COLLECTION, hdr); - - return -1; - } - - int32_t size = stream->ReadInt32(); - - return size; - } - - int32_t PortableReaderImpl::ReadCollectionSize() - { - InteropStreamPositionGuard<InteropInputStream> positionGuard(*stream); - - return ReadCollectionSizeUnprotected(); - } - - int32_t PortableReaderImpl::ReadCollectionSize(const char* fieldName) - { - CheckRawMode(false); - CheckSingleMode(true); - - InteropStreamPositionGuard<InteropInputStream> positionGuard(*stream); - - int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); - int32_t fieldPos = FindField(fieldId); - - if (fieldPos <= 0) - return -1; - - stream->Position(fieldPos); - - return ReadCollectionSizeUnprotected(); - } - - bool PortableReaderImpl::HasNextElement(int32_t id) const - { - return elemId == id && elemRead < elemCnt; - } - - void PortableReaderImpl::SetRawMode() - { - CheckRawMode(false); - CheckSingleMode(true); - - stream->Position(pos + rawOff); - rawMode = true; - } - - template <> - int8_t PortableReaderImpl::ReadTopObject<int8_t>() - { - return ReadTopObject0(IGNITE_TYPE_BYTE, PortableUtils::ReadInt8, static_cast<int8_t>(0)); - } - - template <> - bool PortableReaderImpl::ReadTopObject<bool>() - { - return ReadTopObject0(IGNITE_TYPE_BOOL, PortableUtils::ReadBool, static_cast<bool>(0)); - } - - template <> - int16_t PortableReaderImpl::ReadTopObject<int16_t>() - { - return ReadTopObject0(IGNITE_TYPE_SHORT, PortableUtils::ReadInt16, static_cast<int16_t>(0)); - } - - template <> - uint16_t PortableReaderImpl::ReadTopObject<uint16_t>() - { - return ReadTopObject0(IGNITE_TYPE_CHAR, PortableUtils::ReadUInt16, static_cast<uint16_t>(0)); - } - - template <> - int32_t PortableReaderImpl::ReadTopObject<int32_t>() - { - return ReadTopObject0(IGNITE_TYPE_INT, PortableUtils::ReadInt32, static_cast<int32_t>(0)); - } - - template <> - int64_t PortableReaderImpl::ReadTopObject<int64_t>() - { - return ReadTopObject0(IGNITE_TYPE_LONG, PortableUtils::ReadInt64, static_cast<int64_t>(0)); - } - - template <> - float PortableReaderImpl::ReadTopObject<float>() - { - return ReadTopObject0(IGNITE_TYPE_FLOAT, PortableUtils::ReadFloat, static_cast<float>(0)); - } - - template <> - double PortableReaderImpl::ReadTopObject<double>() - { - return ReadTopObject0(IGNITE_TYPE_DOUBLE, PortableUtils::ReadDouble, static_cast<double>(0)); - } - - template <> - Guid PortableReaderImpl::ReadTopObject<Guid>() - { - int8_t typeId = stream->ReadInt8(); - - if (typeId == IGNITE_TYPE_UUID) - return PortableUtils::ReadGuid(stream); - else if (typeId == IGNITE_HDR_NULL) - return Guid(); - else { - int32_t pos = stream->Position() - 1; - - IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_PORTABLE, "Invalid header", "position", pos, "expected", IGNITE_TYPE_UUID, "actual", typeId) - } - } - - InteropInputStream* PortableReaderImpl::GetStream() - { - return stream; - } - - int32_t PortableReaderImpl::FindField(const int32_t fieldId) - { - InteropStreamPositionGuard<InteropInputStream> streamGuard(*stream); - - stream->Position(footerBegin); - - switch (schemaType) - { - 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<uint8_t>(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 static_cast<uint16_t>(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; - } - - void PortableReaderImpl::CheckRawMode(bool expected) const - { - if (expected && !rawMode) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation can be performed only in raw mode.") - } - else if (!expected && rawMode) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation cannot be performed in raw mode.") - } - } - - void PortableReaderImpl::CheckSingleMode(bool expected) const - { - if (expected && elemId != 0) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation cannot be performed when container is being read."); - } - else if (!expected && elemId == 0) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Operation can be performed only when container is being read."); - } - } - - int32_t PortableReaderImpl::StartContainerSession(bool expRawMode, int8_t expHdr, int32_t* size) - { - CheckRawMode(expRawMode); - CheckSingleMode(true); - - int8_t hdr = stream->ReadInt8(); - - if (hdr == expHdr) - { - int32_t cnt = stream->ReadInt32(); - - if (cnt != 0) - { - elemId = ++elemIdGen; - elemCnt = cnt; - elemRead = 0; - - *size = cnt; - - return elemId; - } - else - { - *size = 0; - - return ++elemIdGen; - } - } - else if (hdr == IGNITE_HDR_NULL) { - *size = -1; - - return ++elemIdGen; - } - else { - ThrowOnInvalidHeader(expHdr, hdr); - - return 0; - } - } - - void PortableReaderImpl::CheckSession(int32_t expSes) const - { - if (elemId != expSes) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_PORTABLE, "Containter read session has been finished or is not started yet."); - } - } - - void PortableReaderImpl::ThrowOnInvalidHeader(int32_t pos, int8_t expHdr, int8_t hdr) - { - IGNITE_ERROR_FORMATTED_3(IgniteError::IGNITE_ERR_PORTABLE, "Invalid header", "position", pos, "expected", expHdr, "actual", hdr) - } - - void PortableReaderImpl::ThrowOnInvalidHeader(int8_t expHdr, int8_t hdr) const - { - int32_t pos = stream->Position() - 1; - - ThrowOnInvalidHeader(pos, expHdr, hdr); - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/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 deleted file mode 100644 index 448cf02..0000000 --- a/modules/platforms/cpp/core/src/impl/portable/portable_schema.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include <cassert> - -#include "ignite/impl/portable/portable_schema.h" -#include "ignite/impl/portable/portable_writer_impl.h" - -/** FNV1 hash offset basis. */ -enum { FNV1_OFFSET_BASIS = 0x811C9DC5 }; - -/** FNV1 hash prime. */ -enum { FNV1_PRIME = 0x01000193 }; - -namespace ignite -{ - namespace impl - { - namespace portable - { - PortableSchema::PortableSchema(): id(0), fieldsInfo(new FieldContainer()) - { - // No-op. - } - - PortableSchema::~PortableSchema() - { - delete fieldsInfo; - } - - void PortableSchema::AddField(int32_t fieldId, int32_t offset) - { - if (!id) - { - // Initialize offset when the first field is written. - id = FNV1_OFFSET_BASIS; - } - - // Advance schema hash. - int32_t idAccumulator = id ^ (fieldId & 0xFF); - idAccumulator *= FNV1_PRIME; - idAccumulator ^= (fieldId >> 8) & 0xFF; - idAccumulator *= FNV1_PRIME; - idAccumulator ^= (fieldId >> 16) & 0xFF; - idAccumulator *= FNV1_PRIME; - idAccumulator ^= (fieldId >> 24) & 0xFF; - idAccumulator *= FNV1_PRIME; - - id = idAccumulator; - - PortableSchemaFieldInfo info = { fieldId, offset }; - fieldsInfo->push_back(info); - } - - void PortableSchema::Write(interop::InteropOutputStream& out) const - { - switch (GetType()) - { - case OFFSET_TYPE_1_BYTE: - { - for (FieldContainer::const_iterator i = fieldsInfo->begin(); i != fieldsInfo->end(); ++i) - { - out.WriteInt32(i->id); - out.WriteInt8(static_cast<int8_t>(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<int16_t>(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; - } - } - } - - bool PortableSchema::Empty() const - { - return fieldsInfo->empty(); - } - - void PortableSchema::Clear() - { - 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/303d79eb/modules/platforms/cpp/core/src/impl/portable/portable_utils.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_utils.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_utils.cpp deleted file mode 100644 index f65abd0..0000000 --- a/modules/platforms/cpp/core/src/impl/portable/portable_utils.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ignite/impl/interop/interop.h" -#include "ignite/impl/portable/portable_utils.h" - -using namespace ignite::impl::interop; -using namespace ignite::impl::portable; - -namespace ignite -{ - namespace impl - { - namespace portable - { - int8_t PortableUtils::ReadInt8(InteropInputStream* stream) - { - return stream->ReadInt8(); - } - - void PortableUtils::WriteInt8(InteropOutputStream* stream, int8_t val) - { - stream->WriteInt8(val); - } - - void PortableUtils::ReadInt8Array(InteropInputStream* stream, int8_t* res, const int32_t len) - { - stream->ReadInt8Array(res, len); - } - - void PortableUtils::WriteInt8Array(InteropOutputStream* stream, const int8_t* val, const int32_t len) - { - stream->WriteInt8Array(val, len); - } - - bool PortableUtils::ReadBool(InteropInputStream* stream) - { - return stream->ReadBool(); - } - - void PortableUtils::WriteBool(InteropOutputStream* stream, bool val) - { - stream->WriteBool(val); - } - - void PortableUtils::ReadBoolArray(InteropInputStream* stream, bool* res, const int32_t len) - { - stream->ReadBoolArray(res, len); - } - - void PortableUtils::WriteBoolArray(InteropOutputStream* stream, const bool* val, const int32_t len) - { - stream->WriteBoolArray(val, len); - } - - int16_t PortableUtils::ReadInt16(InteropInputStream* stream) - { - return stream->ReadInt16(); - } - - void PortableUtils::WriteInt16(InteropOutputStream* stream, int16_t val) - { - stream->WriteInt16(val); - } - - void PortableUtils::ReadInt16Array(InteropInputStream* stream, int16_t* res, const int32_t len) - { - stream->ReadInt16Array(res, len); - } - - void PortableUtils::WriteInt16Array(InteropOutputStream* stream, const int16_t* val, const int32_t len) - { - stream->WriteInt16Array(val, len); - } - - uint16_t PortableUtils::ReadUInt16(InteropInputStream* stream) - { - return stream->ReadUInt16(); - } - - void PortableUtils::WriteUInt16(InteropOutputStream* stream, uint16_t val) - { - stream->WriteUInt16(val); - } - - void PortableUtils::ReadUInt16Array(InteropInputStream* stream, uint16_t* res, const int32_t len) - { - stream->ReadUInt16Array(res, len); - } - - void PortableUtils::WriteUInt16Array(InteropOutputStream* stream, const uint16_t* val, const int32_t len) - { - stream->WriteUInt16Array(val, len); - } - - int32_t PortableUtils::ReadInt32(InteropInputStream* stream) - { - return stream->ReadInt32(); - } - - void PortableUtils::WriteInt32(InteropOutputStream* stream, int32_t val) - { - stream->WriteInt32(val); - } - - void PortableUtils::ReadInt32Array(InteropInputStream* stream, int32_t* res, const int32_t len) - { - stream->ReadInt32Array(res, len); - } - - void PortableUtils::WriteInt32Array(InteropOutputStream* stream, const int32_t* val, const int32_t len) - { - stream->WriteInt32Array(val, len); - } - - int64_t PortableUtils::ReadInt64(InteropInputStream* stream) - { - return stream->ReadInt64(); - } - - void PortableUtils::WriteInt64(InteropOutputStream* stream, int64_t val) - { - stream->WriteInt64(val); - } - - void PortableUtils::ReadInt64Array(InteropInputStream* stream, int64_t* res, const int32_t len) - { - stream->ReadInt64Array(res, len); - } - - void PortableUtils::WriteInt64Array(InteropOutputStream* stream, const int64_t* val, const int32_t len) - { - stream->WriteInt64Array(val, len); - } - - float PortableUtils::ReadFloat(InteropInputStream* stream) - { - return stream->ReadFloat(); - } - - void PortableUtils::WriteFloat(InteropOutputStream* stream, float val) - { - stream->WriteFloat(val); - } - - void PortableUtils::ReadFloatArray(InteropInputStream* stream, float* res, const int32_t len) - { - stream->ReadFloatArray(res, len); - } - - void PortableUtils::WriteFloatArray(InteropOutputStream* stream, const float* val, const int32_t len) - { - stream->WriteFloatArray(val, len); - } - - double PortableUtils::ReadDouble(InteropInputStream* stream) - { - return stream->ReadDouble(); - } - - void PortableUtils::WriteDouble(InteropOutputStream* stream, double val) - { - stream->WriteDouble(val); - } - - void PortableUtils::ReadDoubleArray(InteropInputStream* stream, double* res, const int32_t len) - { - stream->ReadDoubleArray(res, len); - } - - void PortableUtils::WriteDoubleArray(InteropOutputStream* stream, const double* val, const int32_t len) - { - stream->WriteDoubleArray(val, len); - } - - Guid PortableUtils::ReadGuid(interop::InteropInputStream* stream) - { - int64_t most = stream->ReadInt64(); - int64_t least = stream->ReadInt64(); - - return Guid(most, least); - } - - void PortableUtils::WriteGuid(interop::InteropOutputStream* stream, const Guid val) - { - stream->WriteInt64(val.GetMostSignificantBits()); - stream->WriteInt64(val.GetLeastSignificantBits()); - } - - void PortableUtils::WriteString(interop::InteropOutputStream* stream, const char* val, const int32_t len) - { - stream->WriteInt32(len); - stream->WriteInt8Array(reinterpret_cast<const int8_t*>(val), len); - } - } - } -} \ No newline at end of file
