-
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 pull request #174 from intelligentplant/feature/kvstore-refactor
Refactor key-value store and add Sqlite and file system implementations
- Loading branch information
Showing
39 changed files
with
2,193 additions
and
1,553 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
11 changes: 10 additions & 1 deletion
11
src/DataCore.Adapter.Abstractions/AbstractionsResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,109 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
|
||
namespace DataCore.Adapter.Services { | ||
|
||
/// <summary> | ||
/// Describes a key or a prefix in a <see cref="IKeyValueStore"/>. | ||
/// </summary> | ||
public struct KVKey : IEquatable<KVKey> { | ||
|
||
/// <summary> | ||
/// A <see cref="KVKey"/> that represents an empty prefix. | ||
/// </summary> | ||
public static KVKey Empty => default; | ||
|
||
/// <summary> | ||
/// The value of the key. | ||
/// </summary> | ||
public byte[] Value { get; } | ||
|
||
/// <summary> | ||
/// The length of the key, in bytes. | ||
/// </summary> | ||
public int Length => Value?.Length ?? 0; | ||
|
||
|
||
/// <summary> | ||
/// Creates a new <see cref="KVKey"/>. | ||
/// </summary> | ||
/// <param name="value"> | ||
/// The value of the key. | ||
/// </param> | ||
public KVKey(byte[]? value) { | ||
Value = value!; | ||
} | ||
|
||
|
||
/// <inheritdoc/> | ||
public override int GetHashCode() { | ||
#if NETSTANDARD2_0 || NET461 | ||
return HashGenerator.Combine(Value); | ||
#else | ||
return HashCode.Combine(Value); | ||
#endif | ||
} | ||
|
||
|
||
/// <inheritdoc/> | ||
public override bool Equals(object obj) { | ||
return obj is KVKey other | ||
? Equals(other) | ||
: false; | ||
} | ||
|
||
|
||
/// <inheritdoc/> | ||
public bool Equals(KVKey other) { | ||
if (Value == null && other.Value == null) { | ||
return true; | ||
} | ||
|
||
if (Value == null && other.Value != null) { | ||
return false; | ||
} | ||
|
||
if (Value != null && other.Value == null) { | ||
return false; | ||
} | ||
|
||
if (Value!.Length != other.Value!.Length) { | ||
return false; | ||
} | ||
|
||
for (var i = 0; i < Value.Length; i++) { | ||
if (Value[i] != other.Value[i]) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
|
||
public static bool operator ==(KVKey left, KVKey right) => left.Equals(right); | ||
public static bool operator !=(KVKey left, KVKey right) => !left.Equals(right); | ||
|
||
public static implicit operator KVKey(byte[] value) => new KVKey(value); | ||
public static implicit operator KVKey(string? value) => new KVKey(Encoding.UTF8.GetBytes(value ?? string.Empty)); | ||
public static implicit operator KVKey(DateTime value) => new KVKey(Encoding.UTF8.GetBytes(value.ToString("O", CultureInfo.InvariantCulture))); | ||
public static implicit operator KVKey(TimeSpan value) => new KVKey(Encoding.UTF8.GetBytes(value.ToString("C", CultureInfo.InvariantCulture))); | ||
public static implicit operator KVKey(byte value) => new KVKey(new[] { value }); | ||
public static implicit operator KVKey(bool value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator KVKey(char value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator KVKey(double value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator KVKey(float value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator KVKey(int value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator KVKey(long value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator KVKey(short value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator KVKey(ushort value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator KVKey(uint value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator KVKey(ulong value) => new KVKey(BitConverter.GetBytes(value)); | ||
public static implicit operator byte[](KVKey value) => value.Value; | ||
|
||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member | ||
|
||
} | ||
} |
Oops, something went wrong.