From af6976a907b0d2a9fadbb14d7258bab44f075364 Mon Sep 17 00:00:00 2001 From: zxu Date: Sat, 27 Jan 2018 17:53:27 -0500 Subject: normalize and port the rest of Firebase/Port code (#713) * normalize bits * normalize ordered_code --- Firestore/Source/Local/FSTLevelDBKey.mm | 37 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'Firestore/Source/Local/FSTLevelDBKey.mm') diff --git a/Firestore/Source/Local/FSTLevelDBKey.mm b/Firestore/Source/Local/FSTLevelDBKey.mm index 074d5c5..9850fff 100644 --- a/Firestore/Source/Local/FSTLevelDBKey.mm +++ b/Firestore/Source/Local/FSTLevelDBKey.mm @@ -18,13 +18,14 @@ #include -#include "Firestore/Port/ordered_code.h" #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTPath.h" +#include "Firestore/core/src/firebase/firestore/util/ordered_code.h" + NS_ASSUME_NONNULL_BEGIN -using Firestore::OrderedCode; +using firebase::firestore::util::OrderedCode; using Firestore::StringView; using leveldb::Slice; @@ -109,11 +110,11 @@ void WriteComponentLabel(std::string *dest, FSTComponentLabel label) { */ BOOL ReadComponentLabel(leveldb::Slice *contents, FSTComponentLabel *label) { int64_t rawResult = 0; - Slice tmp = *contents; + absl::string_view tmp(contents->data(), contents->size()); if (OrderedCode::ReadSignedNumIncreasing(&tmp, &rawResult)) { if (rawResult >= FSTComponentLabelTerminator && rawResult <= FSTComponentLabelUnknown) { *label = static_cast(rawResult); - *contents = tmp; + *contents = leveldb::Slice(tmp.data(), tmp.size()); return YES; } } @@ -128,9 +129,9 @@ BOOL ReadComponentLabel(leveldb::Slice *contents, FSTComponentLabel *label) { * * If the read is successful, returns YES and contents will be updated to the next unread byte. */ -BOOL ReadComponentLabelMatching(Slice *contents, FSTComponentLabel expectedLabel) { +BOOL ReadComponentLabelMatching(absl::string_view *contents, FSTComponentLabel expectedLabel) { int64_t rawResult = 0; - Slice tmp = *contents; + absl::string_view tmp = *contents; if (OrderedCode::ReadSignedNumIncreasing(&tmp, &rawResult)) { if (rawResult == expectedLabel) { *contents = tmp; @@ -152,10 +153,10 @@ BOOL ReadComponentLabelMatching(Slice *contents, FSTComponentLabel expectedLabel */ BOOL ReadInt32(Slice *contents, int32_t *result) { int64_t rawResult = 0; - Slice tmp = *contents; + absl::string_view tmp(contents->data(), contents->size()); if (OrderedCode::ReadSignedNumIncreasing(&tmp, &rawResult)) { if (rawResult >= INT32_MIN && rawResult <= INT32_MAX) { - *contents = tmp; + *contents = leveldb::Slice(tmp.data(), tmp.size()); *result = static_cast(rawResult); return YES; } @@ -180,10 +181,11 @@ void WriteLabeledInt32(std::string *dest, FSTComponentLabel label, int32_t value * value will be set to the decoded integer value. */ BOOL ReadLabeledInt32(Slice *contents, FSTComponentLabel expectedLabel, int32_t *value) { - Slice tmp = *contents; + absl::string_view tmp(contents->data(), contents->size()); if (ReadComponentLabelMatching(&tmp, expectedLabel)) { - if (ReadInt32(&tmp, value)) { - *contents = tmp; + Slice tmpSlice = leveldb::Slice(tmp.data(), tmp.size()); + if (ReadInt32(&tmpSlice, value)) { + *contents = tmpSlice; return YES; } } @@ -207,10 +209,10 @@ void WriteLabeledString(std::string *dest, FSTComponentLabel label, StringView v * value will be set to the decoded string value. */ BOOL ReadLabeledString(Slice *contents, FSTComponentLabel expectedLabel, std::string *value) { - Slice tmp = *contents; + absl::string_view tmp(contents->data(), contents->size()); if (ReadComponentLabelMatching(&tmp, expectedLabel)) { if (OrderedCode::ReadString(&tmp, value)) { - *contents = tmp; + *contents = leveldb::Slice(tmp.data(), tmp.size()); return YES; } } @@ -272,7 +274,7 @@ BOOL ReadDocumentKey(Slice *contents, FSTDocumentKey *__strong *result) { for (;;) { // Advance a temporary slice to avoid advancing contents into the next key component which may // not be a path segment. - Slice readPosition = completeSegments; + absl::string_view readPosition(completeSegments.data(), completeSegments.size()); if (!ReadComponentLabelMatching(&readPosition, FSTComponentLabelPathSegment)) { break; } @@ -284,7 +286,7 @@ BOOL ReadDocumentKey(Slice *contents, FSTDocumentKey *__strong *result) { [pathSegments addObject:pathSegment]; segment.clear(); - completeSegments = readPosition; + completeSegments = leveldb::Slice(readPosition.data(), readPosition.size()); } FSTResourcePath *path = [FSTResourcePath pathWithSegments:pathSegments]; @@ -304,7 +306,10 @@ inline void WriteTerminator(std::string *dest) { } inline BOOL ReadTerminator(Slice *contents) { - return ReadComponentLabelMatching(contents, FSTComponentLabelTerminator); + absl::string_view tmp(contents->data(), contents->size()); + BOOL result = ReadComponentLabelMatching(&tmp, FSTComponentLabelTerminator); + *contents = leveldb::Slice(tmp.data(), tmp.size()); + return result; } inline void WriteTableName(std::string *dest, const char *tableName) { -- cgit v1.2.3