summaryrefslogtreecommitdiff
path: root/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp
diff options
context:
space:
mode:
authorAndroid Build Role Account android-build-prod <android-build-team-robot@google.com>2018-12-15 23:06:51 +0000
committerAndroid Build Role Account android-build-prod <android-build-team-robot@google.com>2018-12-15 23:06:51 +0000
commit6ffda879f23648c8b432c94ef15ee3a8bf3545be (patch)
treec3cabbf31427472185daea8affa6e49368f9dabc /cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp
parentce9ab45c7fb9ca7468f7ab51e80c9747eafa8d0d (diff)
parent062f698bc713f2f57bb4f3a175f507f31a84e409 (diff)
Snap for 5183987 from 062f698bc713f2f57bb4f3a175f507f31a84e409 to q-keystone-qcom-release
Change-Id: I7548c5662184dd4e8dfafd29c767b8e4c074dd5d
Diffstat (limited to 'cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp')
-rw-r--r--cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp b/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp
new file mode 100644
index 000000000000..29969a23250b
--- /dev/null
+++ b/cmds/idmap2/libidmap2/BinaryStreamVisitor.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed 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 <algorithm>
+#include <cstring>
+#include <string>
+
+#include "android-base/macros.h"
+
+#include "idmap2/BinaryStreamVisitor.h"
+
+namespace android {
+namespace idmap2 {
+
+void BinaryStreamVisitor::Write16(uint16_t value) {
+ uint16_t x = htodl(value);
+ stream_.write(reinterpret_cast<char*>(&x), sizeof(uint16_t));
+}
+
+void BinaryStreamVisitor::Write32(uint32_t value) {
+ uint32_t x = htodl(value);
+ stream_.write(reinterpret_cast<char*>(&x), sizeof(uint32_t));
+}
+
+void BinaryStreamVisitor::WriteString(const StringPiece& value) {
+ char buf[kIdmapStringLength];
+ memset(buf, 0, sizeof(buf));
+ memcpy(buf, value.data(), std::min(value.size(), sizeof(buf)));
+ stream_.write(buf, sizeof(buf));
+}
+
+void BinaryStreamVisitor::visit(const Idmap& idmap ATTRIBUTE_UNUSED) {
+ // nothing to do
+}
+
+void BinaryStreamVisitor::visit(const IdmapHeader& header) {
+ Write32(header.GetMagic());
+ Write32(header.GetVersion());
+ Write32(header.GetTargetCrc());
+ Write32(header.GetOverlayCrc());
+ WriteString(header.GetTargetPath());
+ WriteString(header.GetOverlayPath());
+}
+
+void BinaryStreamVisitor::visit(const IdmapData& data ATTRIBUTE_UNUSED) {
+ // nothing to do
+}
+
+void BinaryStreamVisitor::visit(const IdmapData::Header& header) {
+ Write16(header.GetTargetPackageId());
+ Write16(header.GetTypeCount());
+}
+
+void BinaryStreamVisitor::visit(const IdmapData::TypeEntry& te) {
+ const uint16_t entryCount = te.GetEntryCount();
+
+ Write16(te.GetTargetTypeId());
+ Write16(te.GetOverlayTypeId());
+ Write16(entryCount);
+ Write16(te.GetEntryOffset());
+ for (uint16_t i = 0; i < entryCount; i++) {
+ EntryId entry_id = te.GetEntry(i);
+ Write32(entry_id != kNoEntry ? static_cast<uint32_t>(entry_id) : kPadding);
+ }
+}
+
+} // namespace idmap2
+} // namespace android