forked from PolymerLabs/arcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:PolymerLabs/arcs into r2p
Fixed lint errors
- Loading branch information
Showing
33 changed files
with
964 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2020 Google LLC. | ||
* | ||
* This code may only be used under the BSD style license found at | ||
* http://polymer.github.io/LICENSE.txt | ||
* | ||
* Code distributed by Google as part of this project is also subject to an additional IP rights | ||
* grant found at | ||
* http://polymer.github.io/PATENTS.txt | ||
*/ | ||
|
||
package arcs.android.crdt | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
import arcs.android.util.writeProto | ||
import arcs.core.storage.Reference | ||
import arcs.core.storage.StorageKeyParser | ||
|
||
/** Parcelable version of [Reference]. */ | ||
data class ParcelableReference(override val actual: Reference) : ParcelableReferencable { | ||
override fun writeToParcel(parcel: Parcel, flags: Int) { | ||
super.writeToParcel(parcel, flags) | ||
parcel.writeString(actual.id) | ||
parcel.writeString(actual.storageKey.toString()) | ||
actual.version?.let { | ||
parcel.writeProto(it.toProto()) | ||
} ?: { | ||
parcel.writeTypedObject(null, flags) | ||
}() | ||
} | ||
|
||
override fun describeContents(): Int = 0 | ||
|
||
/* Don't use this directly, instead use ParcelableReferencable. */ | ||
internal companion object CREATOR : Parcelable.Creator<ParcelableReference> { | ||
override fun createFromParcel(parcel: Parcel): ParcelableReference { | ||
val id = requireNotNull(parcel.readString()) { | ||
"Required id not found in parcel for ParcelableReference" | ||
} | ||
val storageKeyString = requireNotNull(parcel.readString()) { | ||
"Required storageKey not found in parcel for ParcelableReference" | ||
} | ||
val versionMap = parcel.readVersionMap()?.takeIf { it.isNotEmpty() } | ||
|
||
return ParcelableReference( | ||
Reference(id, StorageKeyParser.parse(storageKeyString), versionMap) | ||
) | ||
} | ||
|
||
override fun newArray(size: Int): Array<ParcelableReference?> = arrayOfNulls(size) | ||
} | ||
} | ||
|
||
/** Writes the [Reference] to the receiving [Parcel]. */ | ||
fun Parcel.writeReference(reference: Reference, flags: Int) = | ||
writeTypedObject(ParcelableReference(reference), flags) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2020 Google LLC. | ||
* | ||
* This code may only be used under the BSD style license found at | ||
* http://polymer.github.io/LICENSE.txt | ||
* | ||
* Code distributed by Google as part of this project is also subject to an additional IP rights | ||
* grant found at | ||
* http://polymer.github.io/PATENTS.txt | ||
*/ | ||
|
||
package arcs.core.data.proto | ||
|
||
import arcs.core.data.PrimitiveType | ||
|
||
/** | ||
* Converts a [PrimitiveTypeProto] protobuf instance into a native kotlin [PrimitiveType] instance. | ||
*/ | ||
fun PrimitiveTypeProto.decode(): PrimitiveType = | ||
when (this) { | ||
PrimitiveTypeProto.TEXT -> PrimitiveType.Text | ||
PrimitiveTypeProto.NUMBER -> PrimitiveType.Number | ||
PrimitiveTypeProto.BOOLEAN -> PrimitiveType.Boolean | ||
PrimitiveTypeProto.UNRECOGNIZED -> | ||
throw IllegalArgumentException("Unknown PrimitiveTypeProto value.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.