From 5ee0787024cc446a21008ff5710dec19c6afc834 Mon Sep 17 00:00:00 2001 From: Yi Jin Date: Mon, 5 Mar 2018 18:18:27 -0800 Subject: Use uint64_t instead of long long as API type for consistent reason. Bug: 74118023 Test: manual Change-Id: Icd5f506c76d3a008a79cb6c9d2061962ca7fdd40 --- .../include/android/util/ProtoOutputStream.h | 8 +++---- libs/protoutil/src/ProtoOutputStream.cpp | 26 +++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'libs') diff --git a/libs/protoutil/include/android/util/ProtoOutputStream.h b/libs/protoutil/include/android/util/ProtoOutputStream.h index 52830d397772..43ac1ec387a4 100644 --- a/libs/protoutil/include/android/util/ProtoOutputStream.h +++ b/libs/protoutil/include/android/util/ProtoOutputStream.h @@ -25,7 +25,7 @@ namespace android { namespace util { /** - * Position of the field type in a (long long) fieldId. + * Position of the field type in a 64-bits fieldId. */ const uint64_t FIELD_TYPE_SHIFT = 32; @@ -106,8 +106,8 @@ public: * Returns a token of this write session. * Must call end(token) when finish write this sub-message. */ - long long start(uint64_t fieldId); - void end(long long token); + uint64_t start(uint64_t fieldId); + void end(uint64_t token); /** * Returns how many bytes are buffered in ProtoOutputStream. @@ -139,7 +139,7 @@ private: bool mCompact; int mDepth; int mObjectId; - long long mExpectedObjectToken; + uint64_t mExpectedObjectToken; inline void writeDoubleImpl(uint32_t id, double val); inline void writeFloatImpl(uint32_t id, float val); diff --git a/libs/protoutil/src/ProtoOutputStream.cpp b/libs/protoutil/src/ProtoOutputStream.cpp index 9d9ffec4c588..a040bd223e94 100644 --- a/libs/protoutil/src/ProtoOutputStream.cpp +++ b/libs/protoutil/src/ProtoOutputStream.cpp @@ -28,7 +28,7 @@ ProtoOutputStream::ProtoOutputStream() mCompact(false), mDepth(0), mObjectId(0), - mExpectedObjectToken(0LL) + mExpectedObjectToken(0ULL) { } @@ -45,7 +45,7 @@ ProtoOutputStream::clear() mCompact = false; mDepth = 0; mObjectId = 0; - mExpectedObjectToken = 0LL; + mExpectedObjectToken = 0ULL; } bool @@ -222,37 +222,37 @@ ProtoOutputStream::write(uint64_t fieldId, const char* val, size_t size) * because of the overflow, and only the tokens are compared. * Bits 0-31 - offset of the first size field in the buffer. */ -long long +uint64_t makeToken(int tagSize, bool repeated, int depth, int objectId, int sizePos) { - return ((0x07L & (long long)tagSize) << 61) + return ((0x07L & (uint64_t)tagSize) << 61) | (repeated ? (1LL << 60) : 0) - | (0x01ffL & (long long)depth) << 51 - | (0x07ffffL & (long long)objectId) << 32 - | (0x0ffffffffL & (long long)sizePos); + | (0x01ffL & (uint64_t)depth) << 51 + | (0x07ffffL & (uint64_t)objectId) << 32 + | (0x0ffffffffL & (uint64_t)sizePos); } /** * Get the encoded tag size from the token. */ -static int getTagSizeFromToken(long long token) { +static int getTagSizeFromToken(uint64_t token) { return (int)(0x7 & (token >> 61)); } /** * Get the nesting depth of startObject calls from the token. */ -static int getDepthFromToken(long long token) { +static int getDepthFromToken(uint64_t token) { return (int)(0x01ff & (token >> 51)); } /** * Get the location of the childRawSize (the first 32 bit size field) in this object. */ -static int getSizePosFromToken(long long token) { +static int getSizePosFromToken(uint64_t token) { return (int)token; } -long long +uint64_t ProtoOutputStream::start(uint64_t fieldId) { if ((fieldId & FIELD_TYPE_MASK) != FIELD_TYPE_MESSAGE) { @@ -275,10 +275,10 @@ ProtoOutputStream::start(uint64_t fieldId) } void -ProtoOutputStream::end(long long token) +ProtoOutputStream::end(uint64_t token) { if (token != mExpectedObjectToken) { - ALOGE("Unexpected token: 0x%llx, should be 0x%llx", token, mExpectedObjectToken); + ALOGE("Unexpected token: 0x%llx, should be 0x%llx", (long long)token, (long long)mExpectedObjectToken); return; } -- cgit v1.2.3-59-g8ed1b