/// <summary> /// Parses a <see cref="ByteString"/> into an instance of a <see cref="RecordKey"/> object. /// </summary> /// <param name="keyData">The <see cref="ByteString"/> to parse.</param> /// <returns>The parsed <see cref="RecordKey"/>.</returns> public static RecordKey Parse(ByteString keyData) { if (keyData == null) { throw new ArgumentNullException(nameof(keyData)); } byte[] key = keyData.ToByteArray(); string[] parts = Encoding.UTF8.GetString(key, 0, key.Length).Split(new[] { ':' }, 3); if (parts.Length != 3) { throw new ArgumentOutOfRangeException(nameof(keyData)); } RecordKey result = ParseRecord( parts[1], LedgerPath.Parse(parts[0]), parts[2]); // The byte representation of reencoded value must match the input if (!result.ToBinary().Equals(keyData)) { throw new ArgumentOutOfRangeException(nameof(keyData)); } return(result); }
public static async Task <Record> GetRecord(this IStorageEngine store, RecordKey key) { IReadOnlyList <Record> result = await store.GetRecords(new[] { key.ToBinary() }); return(result[0]); }