Skip to content

Instantly share code, notes, and snippets.

@akyoto
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akyoto/e6b07e714c322f1c9405 to your computer and use it in GitHub Desktop.
Save akyoto/e6b07e714c322f1c9405 to your computer and use it in GitHub Desktop.
// GetKeysAndValues
IEnumerator GetKeysAndValues(Bucket bucket) {
var getKeysReq = bucket.GetKeys();
yield return getKeysReq.WaitUntilDone();
if(!getKeysReq.isSuccessful) {
Debug.LogError("Error querying keys for " + bucket.name);
yield break;
}
keysScrollPosition = Vector2.zero;
data = new Dictionary<string, DBValue>();
foreach(var key in getKeysReq.GetKeyEnumerable()) {
data[key] = null;
StartCoroutine(GetKeyValue(bucket, key));
}
currentBucket = bucket;
Debug.Log("Active bucket: " + bucket.name);
}
// GetKeyValue
IEnumerator GetKeyValue(Bucket bucket, string key) {
// Get the value for the key
var getReq = bucket.Get(key);
yield return getReq.WaitUntilDone();
if(getReq.isSuccessful) {
// Try to deserialize the data to a string. If this does not work, use the raw data.
var encoding = getReq.GetEncoding();
if(encoding == Encoding.Json) {
var tree = getReq.GetValue<JsonTree>();
data[key] = new DBValue {
text = tree.ToString(),
tree = tree,
encoding = encoding
};
} else {
data[key] = new DBValue {
text = getReq.GetValueRaw(),
tree = null,
encoding = encoding
};
}
} else {
Debug.LogError("Error querying value for key: " + key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment