summaryrefslogtreecommitdiffstats
path: root/chromeos/binder/transaction_data_reader.cc
diff options
context:
space:
mode:
authorhashimoto <hashimoto@chromium.org>2015-12-18 01:00:47 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-18 09:01:45 +0000
commit2ecd6d9b99fee1d960b66b02cf7f7f445a1f033c (patch)
tree67a1a9388b9e034620a35ff67ebdd17214266bec /chromeos/binder/transaction_data_reader.cc
parent731018c94f8d90ddccc70ec67a672b47cb7c5268 (diff)
downloadchromium_src-2ecd6d9b99fee1d960b66b02cf7f7f445a1f033c.zip
chromium_src-2ecd6d9b99fee1d960b66b02cf7f7f445a1f033c.tar.gz
chromium_src-2ecd6d9b99fee1d960b66b02cf7f7f445a1f033c.tar.bz2
Add TransactionDataReader
BUG=563282 Review URL: https://codereview.chromium.org/1534173002 Cr-Commit-Position: refs/heads/master@{#366060}
Diffstat (limited to 'chromeos/binder/transaction_data_reader.cc')
-rw-r--r--chromeos/binder/transaction_data_reader.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/chromeos/binder/transaction_data_reader.cc b/chromeos/binder/transaction_data_reader.cc
new file mode 100644
index 0000000..cf206ae
--- /dev/null
+++ b/chromeos/binder/transaction_data_reader.cc
@@ -0,0 +1,59 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/binder/transaction_data_reader.h"
+
+#include "chromeos/binder/transaction_data.h"
+
+namespace binder {
+
+namespace {
+
+// Adds appropriate padding to the given size to make it 4-byte aligned.
+size_t AddPadding(size_t n) {
+ return (n + 3) & (~3);
+}
+
+} // namespace
+
+TransactionDataReader::TransactionDataReader(const TransactionData& data)
+ : data_(data),
+ reader_(reinterpret_cast<const char*>(data.GetData()),
+ data.GetDataSize()) {}
+
+TransactionDataReader::~TransactionDataReader() {}
+
+bool TransactionDataReader::HasMoreData() const {
+ return reader_.HasMoreData();
+}
+
+bool TransactionDataReader::ReadData(void* buf, size_t n) {
+ return reader_.Read(buf, n) && reader_.Skip(AddPadding(n) - n);
+}
+
+bool TransactionDataReader::ReadInt32(int32* value) {
+ return ReadData(value, sizeof(*value));
+}
+
+bool TransactionDataReader::ReadUint32(uint32* value) {
+ return ReadData(value, sizeof(*value));
+}
+
+bool TransactionDataReader::ReadInt64(int64* value) {
+ return ReadData(value, sizeof(*value));
+}
+
+bool TransactionDataReader::ReadUint64(uint64* value) {
+ return ReadData(value, sizeof(*value));
+}
+
+bool TransactionDataReader::ReadFloat(float* value) {
+ return ReadData(value, sizeof(*value));
+}
+
+bool TransactionDataReader::ReadDouble(double* value) {
+ return ReadData(value, sizeof(*value));
+}
+
+} // namespace binder