diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-10-24 06:40:07 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-10-24 06:40:07 +0300 |
| commit | adaddad79352c156303e9178a6f172a18af50cd2 (patch) | |
| tree | 0ff2a59c3007bc9c40b7b543a9a2afe32dbc3d45 /Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs | |
| parent | 2d803e9410cd383d8e66c300f86fe0f7374c81ea (diff) | |
| download | Tango-adaddad79352c156303e9178a6f172a18af50cd2.tar.gz Tango-adaddad79352c156303e9178a6f172a18af50cd2.zip | |
Refactored DataStore Proto.
Diffstat (limited to 'Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs b/Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs index 53745990e..3cf24bdd0 100644 --- a/Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs +++ b/Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs @@ -1,8 +1,14 @@ -using System; +using Google.Protobuf; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.ExtensionMethods; +using Tango.PMR; +using Tango.PMR.Common; namespace Tango.DataStore { @@ -53,6 +59,14 @@ namespace Tango.DataStore { return DataType.Bytes; } + else if (type == typeof(DataStoreProtoObject)) + { + return DataType.Proto; + } + else if (typeof(IMessage).IsAssignableFrom(type)) + { + return DataType.Proto; + } throw new NotSupportedException($"The specified type '{type.Name}' is not supported by the data store."); } @@ -63,26 +77,28 @@ namespace Tango.DataStore /// <param name="type">The type.</param> /// <returns></returns> /// <exception cref="System.NotSupportedException">The specified data type is not supported.</exception> - public static Type GetType(DataType type) - { - switch (type) - { - case DataType.Boolean: - return typeof(bool); - case DataType.Bytes: - return typeof(byte[]); - case DataType.Double: - return typeof(double); - case DataType.Float: - return typeof(float); - case DataType.Int32: - return typeof(Int32); - case DataType.String: - return typeof(String); - } + //public static Type GetType(DataType type) + //{ + // switch (type) + // { + // case DataType.Boolean: + // return typeof(bool); + // case DataType.Bytes: + // return typeof(byte[]); + // case DataType.Double: + // return typeof(double); + // case DataType.Float: + // return typeof(float); + // case DataType.Int32: + // return typeof(Int32); + // case DataType.String: + // return typeof(String); + // case DataType.Proto: + // return typeof(DataStoreProtoObject); + // } - throw new NotSupportedException("The specified data type is not supported."); - } + // throw new NotSupportedException("The specified data type is not supported."); + //} /// <summary> /// Formats the data store item as a string. @@ -91,11 +107,7 @@ namespace Tango.DataStore /// <returns></returns> public static String FormatDataStoreItem(IDataStoreItem item) { - if (item.Type != DataType.Bytes) - { - return $"{item.Key}: {item.Value}"; - } - else + if (item.Type == DataType.Bytes) { byte[] bytes = (byte[])item.Value; @@ -106,6 +118,14 @@ namespace Tango.DataStore } return hex.ToString(); } + else if (item.Type == DataType.Proto) + { + return (item.Value as DataStoreProtoObject).Message.ToJsonString(); + } + else + { + return $"{item.Key}: {item.Value}"; + } } } } |
