diff --git a/src/client/spark/mspark/MarketView/MarketViewVM.cs b/src/client/spark/mspark/MarketView/MarketViewVM.cs index ea2095896..704e6e473 100644 --- a/src/client/spark/mspark/MarketView/MarketViewVM.cs +++ b/src/client/spark/mspark/MarketView/MarketViewVM.cs @@ -115,7 +115,7 @@ namespace mbts.spark public const int Version = 1; public StartupData() { } public StartupData(Security[] securities, SortingCriteria[] sorting_criteria) { - if (securities != null) this.securities = securities.Select(s => s.ToByteArray()).ToArray(); + if (securities != null) this.securities = securities.Select(s => ((IImmutableMessage)s).ToByteArray()).ToArray(); this.sorting_criteria = sorting_criteria; } [ProtoMember(1)] diff --git a/src/client/spark/mspark/Shell/Fills/FillsVM.cs b/src/client/spark/mspark/Shell/Fills/FillsVM.cs index 4187d343f..602ec946b 100644 --- a/src/client/spark/mspark/Shell/Fills/FillsVM.cs +++ b/src/client/spark/mspark/Shell/Fills/FillsVM.cs @@ -128,7 +128,7 @@ namespace mbts.spark public const int Version = 1; public StartupData() { } public StartupData(IReadOnlyCollection securities, SortingCriteria[] sorting_criteria) { - if (securities != null) this.securities = securities.Select(s => s.ToByteArray()).ToArray(); + if (securities != null) this.securities = securities.Select(s => ((IImmutableMessage)s).ToByteArray()).ToArray(); this.sorting_criteria = sorting_criteria; } [ProtoMember(1)] diff --git a/src/client/spark/mspark/Shell/Securities/Synthetic/SyntheticEditorModel.cs b/src/client/spark/mspark/Shell/Securities/Synthetic/SyntheticEditorModel.cs index 13147fe37..7f9a7f666 100644 --- a/src/client/spark/mspark/Shell/Securities/Synthetic/SyntheticEditorModel.cs +++ b/src/client/spark/mspark/Shell/Securities/Synthetic/SyntheticEditorModel.cs @@ -32,7 +32,7 @@ namespace mbts.spark while (curr_secmap.Contains(id)) id--; synthetic.Id = id; var sec_strategy = new SyntheticExecutionStrategy { Security = synthetic, ExecutionStrategy = strategy }; - _bus.post(SparkTags.PersistCommandTag, new SparkBusData.PersistMessage(1, "SyntheticSecurity", String.Empty, sec_strategy.ToByteArray())); + _bus.post(SparkTags.PersistCommandTag, new SparkBusData.PersistMessage(1, "SyntheticSecurity", String.Empty, ((IImmutableMessage)sec_strategy).ToByteArray())); } else { // MODIFY } diff --git a/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesVM.cs b/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesVM.cs index d5564e1cf..d9744914d 100644 --- a/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesVM.cs +++ b/src/client/spark/mspark/Shell/TimeAndSales/TimeAndSalesVM.cs @@ -111,7 +111,7 @@ namespace mbts.spark public const int Version = 1; public StartupData() { } public StartupData(IReadOnlyCollection securities, SortingCriteria[] sorting_criteria) { - if (securities != null) this.securities = securities.Select(s => s.ToByteArray()).ToArray(); + if (securities != null) this.securities = securities.Select(s => ((IImmutableMessage)s).ToByteArray()).ToArray(); this.sorting_criteria = sorting_criteria; } [ProtoMember(1)] diff --git a/src/client/spark/sys/api/Test/ApiTests.cs b/src/client/spark/sys/api/Test/ApiTests.cs index d7e80b17a..d67fac92d 100644 --- a/src/client/spark/sys/api/Test/ApiTests.cs +++ b/src/client/spark/sys/api/Test/ApiTests.cs @@ -72,7 +72,7 @@ namespace mbts.api.Test { var h = _context.locate(); TableUpdate last_update = null; - using (var sub1 = h.subscribe_greetings().table().Subscribe(t => last_update = t)) { + using (var sub1 = h.subscribe_greetings().Table().Subscribe(t => last_update = t)) { var response = h.say_hello(new HelloRequest() { Name = "UnitTest 1" }); Assert.AreEqual("Hello UnitTest 1", response.Message); diff --git a/src/client/spark/sys/api/Test/HelloServiceServer.cs b/src/client/spark/sys/api/Test/HelloServiceServer.cs index c956fbf9b..d63762126 100644 --- a/src/client/spark/sys/api/Test/HelloServiceServer.cs +++ b/src/client/spark/sys/api/Test/HelloServiceServer.cs @@ -31,10 +31,10 @@ namespace bts.api.core var resp = await _shout.upper_async(new ShoutRequest() { Msg = msg }); // Yell so loud you can't hear the last message _gpub.publish( - added: new List { new HelloLog() { Myid = (++id).ToString(), Message = resp.result.MSG } }, + added: new List { new HelloLog() { Myid = (++id).ToString(), Message = resp.value.MSG } }, removed: new HashSet { (id - 1).ToString() }); switch (resp.success) { - case true: return new HelloResponse() { Message = resp.result.MSG }; + case true: return new HelloResponse() { Message = resp.value.MSG }; default: return new HelloResponse() { Message = "Sorry {0}. We cannot yell at you right now.".fmt(request.Name) }; } } diff --git a/src/client/spark/sys/persist/UISettings.cs b/src/client/spark/sys/persist/UISettings.cs index 564f9940d..242d12a87 100644 --- a/src/client/spark/sys/persist/UISettings.cs +++ b/src/client/spark/sys/persist/UISettings.cs @@ -50,9 +50,9 @@ namespace mbts.persist Ns = uns(ns), Key = { key } }); - check_error(ret.result.Result, ns, key, out bool empty); + check_error(ret.value.Result, ns, key, out bool empty); if (empty) return default(T); - return deserialize(ret.result.Record.Single().Value); + return deserialize(ret.value.Record.Single().Value); } private Google.Protobuf.ByteString serialize(T obj) { @@ -90,9 +90,9 @@ namespace mbts.persist new RetrieveAllRequest() { Ns = uns(ns) }); - check_error(results.result.Result, ns, "", out bool empty); + check_error(results.value.Result, ns, "", out bool empty); if (empty) return Enumerable.Empty>(); - return results.result.Record + return results.value.Record .Where(r => re.IsMatch(r.Key)) .Select(r => new PersistResult() { user = user(), diff --git a/src/client/spark/uicore/Settings/UserPersistFactory.cs b/src/client/spark/uicore/Settings/UserPersistFactory.cs index 31b756a80..1d0504b9e 100644 --- a/src/client/spark/uicore/Settings/UserPersistFactory.cs +++ b/src/client/spark/uicore/Settings/UserPersistFactory.cs @@ -26,7 +26,7 @@ namespace mbts.ui.settings async Task get_users(UserService login) { var users = await login.get_users_async(null); - if (users.success) return users.result.Users.Select(x => x.Login).ToArray(); + if (users.success) return users.value.Users.Select(x => x.Login).ToArray(); else return new string[0]; } diff --git a/src/client/spark/uicore/Shell/Login/LoginModel.cs b/src/client/spark/uicore/Shell/Login/LoginModel.cs index e9101b2eb..04ec1e89a 100644 --- a/src/client/spark/uicore/Shell/Login/LoginModel.cs +++ b/src/client/spark/uicore/Shell/Login/LoginModel.cs @@ -105,7 +105,7 @@ namespace mbts.ui.shell _enum_workspace = new PreloginWorkspaceEnumerator(persist); var response = await _logon.get_users_async(new GetUsersRequest()); if (response.success) { - UserNames = response.result.Users.Select(x => x.Login).ToArray(); + UserNames = response.value.Users.Select(x => x.Login).ToArray(); Array.Sort(UserNames); } else { @@ -127,13 +127,13 @@ namespace mbts.ui.shell Password = password ??"" }); if (response.success) { - if (response.result.IsValid) { + if (response.value.IsValid) { _workspace = workspace; set_authenticated_user(username); return (true, ""); } else { - return (false, response.result.Reason); + return (false, response.value.Reason); } } else { diff --git a/src/client/spark_api/api/Channels/QuickBusClientChannel.cs b/src/client/spark_api/api/Channels/QuickBusClientChannel.cs index 7570d645e..3d777658c 100644 --- a/src/client/spark_api/api/Channels/QuickBusClientChannel.cs +++ b/src/client/spark_api/api/Channels/QuickBusClientChannel.cs @@ -50,18 +50,18 @@ namespace bts.api.core { return tcs.Task; } - public unsafe override IObservable> subscribe(string method_and_qualifier, MessageParser parser) { + public unsafe override IObservable> subscribe(string method_and_qualifier, MessageParser parser, Func converter) { bool first_update = true; - var result = Observable.Create>(observer => { + var result = Observable.Create>(observer => { ApiNativeMethods.raw_subscription_callback cb = (event_type, changes, change_count, unused) => { if (event_type == ApiNativeMethods.EventType.TABLE_UPDATED) { - var added_items = new List(change_count); + var added_items = new List(change_count); var added_keys = new List(change_count); var removed_keys = new List(change_count); foreach (var change in changes) { if (change.type != ApiNativeMethods.ChangeType.REMOVE) { // create or change - added_items.Add(parser.ParseFrom(new UnmanagedMemoryStream(change.buffer, change.buffer_len))); + added_items.Add( converter( parser.ParseFrom(new UnmanagedMemoryStream(change.buffer, change.buffer_len)))); added_keys.Add(change.key); } if (change.type != ApiNativeMethods.ChangeType.CREATE) { @@ -69,11 +69,11 @@ namespace bts.api.core { removed_keys.Add(change.key); } } - observer.OnNext(new RawUpdate(added_items, added_keys, removed_keys)); + observer.OnNext(new RawUpdate(added_items, added_keys, removed_keys)); } else if (event_type == ApiNativeMethods.EventType.TABLE_CREATED) { if (!first_update) { - observer.OnNext(RawUpdate.Reset()); + observer.OnNext(RawUpdate.Reset()); } first_update = false; } diff --git a/src/client/spark_api/api/ClientChannel.cs b/src/client/spark_api/api/ClientChannel.cs index f727f6a0e..003c4ff5a 100644 --- a/src/client/spark_api/api/ClientChannel.cs +++ b/src/client/spark_api/api/ClientChannel.cs @@ -1,21 +1,21 @@ -using Google.Protobuf; -using System; -using System.Threading.Tasks; - -namespace bts.api.core { - internal abstract class ClientChannel : IDisposable +using Google.Protobuf; +using System; +using System.Threading.Tasks; + +namespace bts.api.core { + internal abstract class ClientChannel : IDisposable { readonly ServiceContext _context; public ClientChannel(ServiceContext context) { _context = context; - } - public abstract void Dispose(); - public abstract Task> send(int method_id, Request request) + } + public abstract void Dispose(); + public abstract Task> send(int method_id, Request request) where Request: IImmutableMessage where Response : class,IMessage,new(); - public abstract IObservable> subscribe(string method_and_qualifier, MessageParser parser) - where T : IMessage; - - public abstract bool is_sync_call_ok(); - } -} + public abstract IObservable> subscribe(string method_and_qualifier, MessageParser parser, Func converter=null) + where TParse : IMessage; + + public abstract bool is_sync_call_ok(); + } +} diff --git a/src/client/spark_api/api/Result.cs b/src/client/spark_api/api/Result.cs index 85aae5151..b77386675 100644 --- a/src/client/spark_api/api/Result.cs +++ b/src/client/spark_api/api/Result.cs @@ -3,44 +3,44 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; - -namespace bts.api.core -{ - - public struct Result - { - public Result(T v) { - _result = v; - _code = ApiError.Success; - } - public Result(ApiError code) { - System.Diagnostics.Debug.Assert(code != ApiError.Success); - _code = code; - _result = default(T); - } - - private string error_string(ApiError code) { - switch (code) { - case ApiError.Success: return "Success"; - case ApiError.NoServer: return "No server found."; - case ApiError.ServerDisconnect: return "Server disconnected."; - case ApiError.MissingMethod: return "Method not found."; - case ApiError.ServerFault: return "Server error."; - default: return "Unknown error"; - } - } - - readonly T _result; - readonly ApiError _code; - - public T result { - get { - if (success) return _result; - else throw new ApiException(error_message); - } - } - public bool success { get { return _code == ApiError.Success; } } - public ApiError code { get { return _code; } } - public string error_message { get { return error_string(_code); } } - } -} + +namespace bts.api.core +{ + + public struct Result + { + public Result(T v) { + _result = v; + _code = ApiError.Success; + } + public Result(ApiError code) { + System.Diagnostics.Debug.Assert(code != ApiError.Success); + _code = code; + _result = default(T); + } + + private string error_string(ApiError code) { + switch (code) { + case ApiError.Success: return "Success"; + case ApiError.NoServer: return "No server found."; + case ApiError.ServerDisconnect: return "Server disconnected."; + case ApiError.MissingMethod: return "Method not found."; + case ApiError.ServerFault: return "Server error."; + default: return "Unknown error"; + } + } + + readonly T _result; + readonly ApiError _code; + + public T value { + get { + if (success) return _result; + else throw new ApiException(error_message); + } + } + public bool success { get { return _code == ApiError.Success; } } + public ApiError code { get { return _code; } } + public string error_message { get { return error_string(_code); } } + } +} diff --git a/src/client/spark_api/api/Update.cs b/src/client/spark_api/api/Update.cs index c704708d2..8342dd17b 100644 --- a/src/client/spark_api/api/Update.cs +++ b/src/client/spark_api/api/Update.cs @@ -1,85 +1,85 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Reactive.Linq; - -namespace bts.api.core { - - public struct RawUpdate { - // RawUpdate uses List instead of IReadonlyList to avoid virtual dispatch on a type not likely to be see in a public api surface - public RawUpdate(List added_items, List added_keys, List removed_keys) : this() { - is_reset = false; - this.added_items = added_items; - this.added_keys = added_keys; - this.removed_keys = removed_keys; - } - - public static RawUpdate Reset() { - return new RawUpdate() { is_reset = true }; - } - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Reactive.Linq; - public bool is_reset; - public List added_items { get; private set; } - public List added_keys { get; private set; } - public List removed_keys { get; private set; } - } - - public class Update where TKey : IEquatable { - private Func _key; - public Update(IEnumerable all, IReadOnlyList added, IReadOnlyList removed, Func key_extractor) { - this.added = added; - this.removed = removed; - this.all = all; - _key = key_extractor; - } - - public IEnumerable all { get; private set; } - public IReadOnlyList added { get; private set; } - public IReadOnlyList removed { get; private set; } - - public TKey key(T t) { return _key(t); } - } - - public class TableUpdate where TKey : IEquatable { - - readonly Dictionary _state; - readonly IReadOnlyList _added; - readonly IReadOnlyList _removed; - - internal TableUpdate(Dictionary init, IReadOnlyList added, IReadOnlyList removed) { - _state = init; - _added = added; - _removed = removed; - } - - public IReadOnlyDictionary state { get { return _state; } } - public IReadOnlyList added { get { return _added; } } - public IReadOnlyList removed { get { return _removed; } } - - public TableUpdate update(Update update) { - var table = new TableUpdate(new Dictionary(_state), update.added, update.removed); - foreach (var i in update.removed) { - table._state.Remove(update.key(i)); - } - foreach (var item in update.added) { - table._state.Add(update.key(item), item); - } - return table; - } - } - - public static class ObservableUpdateExtensions { - public static IObservable> reconstitute(this IObservable> source, Func key_extractor) where TKey : IEquatable { - var state = new Dictionary(); - return source.Select(raw => { +namespace bts.api.core { + + public struct RawUpdate { + // RawUpdate uses List instead of IReadonlyList to avoid virtual dispatch on a type not likely to be see in a public api surface + public RawUpdate(List added_items, List added_keys, List removed_keys) : this() { + is_reset = false; + this.added_items = added_items; + this.added_keys = added_keys; + this.removed_keys = removed_keys; + } + + public static RawUpdate Reset() { + return new RawUpdate() { is_reset = true }; + } + + + public bool is_reset; + public List added_items { get; private set; } + public List added_keys { get; private set; } + public List removed_keys { get; private set; } + } + + public class Update where TKey : IEquatable { + private Func _key; + public Update(IReadOnlyCollection all, IReadOnlyList added, IReadOnlyList removed, Func key_extractor) { + this.added = added; + this.removed = removed; + this.all = all; + _key = key_extractor; + } + + public IReadOnlyCollection all { get; private set; } + public IReadOnlyList added { get; private set; } + public IReadOnlyList removed { get; private set; } + + public TKey key(T t) { return _key(t); } + } + + public class TableUpdate where TKey : IEquatable { + + readonly Dictionary _state; + readonly IReadOnlyList _added; + readonly IReadOnlyList _removed; + + internal TableUpdate(Dictionary init, IReadOnlyList added, IReadOnlyList removed) { + _state = init; + _added = added; + _removed = removed; + } + + public IReadOnlyDictionary state { get { return _state; } } + public IReadOnlyList added { get { return _added; } } + public IReadOnlyList removed { get { return _removed; } } + + public TableUpdate update(Update update) { + var table = new TableUpdate(new Dictionary(_state), update.added, update.removed); + foreach (var i in update.removed) { + table._state.Remove(update.key(i)); + } + foreach (var item in update.added) { + table._state.Add(update.key(item), item); + } + return table; + } + } + + public static class ObservableUpdateExtensions { + public static IObservable> reconstitute(this IObservable> source, Func key_extractor) where TKey : IEquatable { + var state = new Dictionary(); + return source.Select(raw => { if (raw.is_reset) { var removed = state.Values.ToList(); state.Clear(); return new Update(new T[0], new T[0], removed, key_extractor); - } + } else { var removed = new List(raw.removed_keys.Count); foreach (var r in raw.removed_keys) { @@ -93,14 +93,14 @@ namespace bts.api.core { state[raw.added_keys[x]] = raw.added_items[x]; } return new Update(state.Values, raw.added_items, removed, key_extractor); - } - }); - } - - public static IObservable> table(this IObservable> source) where TKey : IEquatable { - return source.Scan( - new TableUpdate(new Dictionary(), new List(), new List()), - (table, update) => table.update(update)); - } - } -} + } + }); + } + + public static IObservable> Table(this IObservable> source) where TKey : IEquatable { + return source.Scan( + new TableUpdate(new Dictionary(), new List(), new List()), + (table, update) => table.update(update)); + } + } +} diff --git a/src/client/spark_api/utils/IImmutableProto.cs b/src/client/spark_api/utils/IImmutableMessage.cs similarity index 94% rename from src/client/spark_api/utils/IImmutableProto.cs rename to src/client/spark_api/utils/IImmutableMessage.cs index 7764789ec..72d30f57e 100644 --- a/src/client/spark_api/utils/IImmutableProto.cs +++ b/src/client/spark_api/utils/IImmutableMessage.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace bts { +namespace bts.api { internal interface IImmutableMessage { MessageDescriptor Descriptor { get; } int CalculateSize(); diff --git a/src/lib/api/service_compiler/plugin.py b/src/lib/api/service_compiler/plugin.py index cc6360676..a91288c2a 100755 --- a/src/lib/api/service_compiler/plugin.py +++ b/src/lib/api/service_compiler/plugin.py @@ -77,11 +77,19 @@ EnumModel = namedtuple("EnumModel", "name values") def transform_enum(e): return EnumModel(e.name, []) -MessageModel = namedtuple("MessageModel", "name field nested_type nested_enum") +OneofModel = namedtuple("OneofModel", "name Name") +def transform_oneof(o, msg): + return OneofModel( + name = o.name, + Name = o.name[0].upper() + o.name[1:] + ) + +MessageModel = namedtuple("MessageModel", "name field oneof nested_type nested_enum") def transform_message(i): r = MessageModel( name = i.name, field = [transform_field(f,i) for f in i.field], + oneof = [transform_oneof(o,i) for o in i.oneof_decl], nested_type = [transform_message(m) for m in i.nested_type], nested_enum = [transform_enum(e) for e in i.enum_type], ) @@ -98,12 +106,11 @@ def transform_service(service, keymap): FileModel = namedtuple("FileModel", "name package namespace_csharp message_type service enum_type") def transform_file(p, keymap): - message_types = [transform_message(m) for m in p.message_type] return FileModel( name = p.name, package = p.package, namespace_csharp = p.package, - message_type = message_types, + message_type = [transform_message(m) for m in p.message_type], service = [transform_service(s, keymap) for s in p.service], enum_type = [transform_enum(e) for e in p.enum_type] ) @@ -206,7 +213,6 @@ def generate_insertions(params, request, response): def camel_case(item): if item.isupper() and not '_' in item: return item return item.title().replace('_', '') - return d def generate_code(request, response): diff --git a/src/lib/api/service_compiler/templates/c#/client.pb.cs b/src/lib/api/service_compiler/templates/c#/client.pb.cs index d1af51ae8..3a35cea45 100644 --- a/src/lib/api/service_compiler/templates/c#/client.pb.cs +++ b/src/lib/api/service_compiler/templates/c#/client.pb.cs @@ -20,20 +20,37 @@ public sealed class {{name}} : IApiClient, IDisposable { {{#if server_streaming}} // {{comment}} public IObservable> subscribe_{{name}}({{input_type_full}} qualifier=null) { - return _channel.subscribe<{{output_type_full}}>(ApiServer.format_qualifier("{{name}}",qualifier), {{output_type_full}}.Parser).reconstitute(key); + return _channel.subscribe<{{output_type_full}}, {{output_type_full}}>(ApiServer.format_qualifier("{{name}}",qualifier), {{output_type_full}}.Parser, a=>a).reconstitute(key); + } + internal IObservable> subscribei_{{name}}({{input_type_full}} qualifier=null) { + return _channel.subscribe<{{output_type_full}}, {{output_type_full}}Immutable>(ApiServer.format_qualifier("{{name}}",qualifier), {{output_type_full}}.Parser, a=>({{output_type_full}}Immutable)a).reconstitute(key); } private static {{key_type.cstype}} key({{output_type_full}} row) { return row.{{camel key_field}}; } + private static {{key_type.cstype}} key({{output_type_full}}Immutable row) { + return row.{{camel key_field}}; + } {{else}} // {{comment}} public Task> {{name}}_async({{input_type_full}} request) { return _channel.send<{{input_type_full}},{{output_type_full}}>({{@index}}, request); } + internal Task> {{name}}_async({{input_type_full}}Immutable request) { + return _channel.send<{{input_type_full}}Immutable,{{output_type_full}}>({{@index}}, request); + } // {{comment}} public {{output_type_full}} {{name}}({{input_type_full}} request) { if (_channel.is_sync_call_ok()) { - return {{name}}_async(request).Result.result; + return {{name}}_async(request).Result.value; + } + else { + throw new bts.api.core.ApiException("API blocking call cannot be made on this thread. Please use {{name}}_async instead."); + } + } + internal {{output_type_full}} {{name}}({{input_type_full}}Immutable request) { + if (_channel.is_sync_call_ok()) { + return {{name}}_async(request).Result.value; } else { throw new bts.api.core.ApiException("API blocking call cannot be made on this thread. Please use {{name}}_async instead."); diff --git a/src/lib/api/service_compiler/templates/c#/immutable.pb.cs b/src/lib/api/service_compiler/templates/c#/immutable.pb.cs index 45eb3ca7c..0fdc36732 100644 --- a/src/lib/api/service_compiler/templates/c#/immutable.pb.cs +++ b/src/lib/api/service_compiler/templates/c#/immutable.pb.cs @@ -8,14 +8,14 @@ using Google.Protobuf.WellKnownTypes; namespace {{package}} { {{#each message_type}} - partial class {{name}} : bts.IImmutableMessage { - MessageDescriptor bts.IImmutableMessage.Descriptor => {{name}}.Descriptor; + partial class {{name}} : bts.api.IImmutableMessage { + MessageDescriptor bts.api.IImmutableMessage.Descriptor => {{name}}.Descriptor; } - partial struct {{name}}Immutable : bts.IImmutableMessage { + partial struct {{name}}Immutable : bts.api.IImmutableMessage { readonly {{name}} _impl; public static MessageDescriptor Descriptor => {{name}}.Descriptor; - MessageDescriptor bts.IImmutableMessage.Descriptor => {{name}}.Descriptor; + MessageDescriptor bts.api.IImmutableMessage.Descriptor => {{name}}.Descriptor; public int CalculateSize() => _impl.CalculateSize(); public void WriteTo(CodedOutputStream output) => _impl.WriteTo(output); @@ -42,8 +42,12 @@ namespace {{package}} { public bool Equals({{name}}Immutable other) { return _impl.Equals(other._impl); } + partial void EqualsOverride(ref bool didrun, ref bool result, {{name}}Immutable other); public bool Equals({{name}}Immutable? other) { if (other == null) return false; + bool didrun = false, result = false; + EqualsOverride(ref didrun, ref result, other.Value); + if (didrun) return result; return _impl.Equals(other.Value._impl); } public override int GetHashCode() => _impl.GetHashCode(); @@ -68,6 +72,11 @@ namespace {{package}} { {{/if}} {{/each}} + + // oneof enums + {{#each oneof}} + public {{../name}}.{{Name}}OneofCase {{Name}}Case => _impl.{{Name}}Case; + {{/each}} public {{name}}Immutable with( // Arguments diff --git a/src/lib/sparkproto/SparkProtos.proto b/src/lib/sparkproto/SparkProtos.proto index e4da1bda7..5e4be4e30 100644 --- a/src/lib/sparkproto/SparkProtos.proto +++ b/src/lib/sparkproto/SparkProtos.proto @@ -29,7 +29,7 @@ message Order { } TimeInForce time_in_force = 50; uint64 timestamp = 60; - oneof algo_order_type { + oneof AlgoOrderType { MarketOrder market_order = 100; LimitOrder limit_order = 110; StopMarketOrder stop_market_order = 120; @@ -144,7 +144,7 @@ message BTSShootTillHitOrder /// Only support a limit or market as Retry's /// We can make Retry a general parameter for /// every order - oneof native_order_type + oneof NativeOrderType { MarketOrder market_order = 10; LimitOrder limit_order = 20; @@ -171,7 +171,7 @@ message BTSWithATickParameters message BTSWithATickOrder { BTSWithATickParameters order_parameters = 10; - oneof native_order_type + oneof NativeOrderType { LimitOrder limit_order = 20; } @@ -202,7 +202,7 @@ message BTSTimedWindowParameters message BTSTimedWindowOrder { BTSTimedWindowParameters order_parameters = 10; - oneof native_order_type + oneof NativeOrderType { MarketOrder market_order = 20; LimitOrder limit_order = 30; @@ -245,12 +245,12 @@ When the market penetrates the trigger price, a limit order is sent "payup" tick message BTSStopOrder { PriceTrigger price_trigger = 10; - oneof native_trigger_order_type + oneof NativeTriggerOrderType { MarketOrder market_order = 20; LimitOrder limit_order = 30; } - oneof trigger_order_price + oneof TriggerOrderPrice { PriceOffset payup = 40; double price = 50; @@ -269,12 +269,12 @@ Opposite of BTS Stop (Both in terms of where the order is placed, and how it tra message BTSIfTouchedOrder { PriceTrigger price_trigger = 10; - oneof native_trigger_order_type + oneof NativeTriggerOrderType { MarketOrder market_order = 20; LimitOrder limit_order = 30; } - oneof order_price + oneof OrderPrice { PriceOffset payup = 40; double price = 50; @@ -293,7 +293,7 @@ previous has been filled. message BTSIcebergOrder { QuantityMeasure display_quantity = 10; - oneof child_order_offset + oneof ChildOrderOffset { PriceOffset market_offset = 20; double diff_from_last_fill = 30; @@ -312,7 +312,7 @@ message BTSTimeSliceOrder { double interval = 10; QuantityMeasure display_quantity = 20; - oneof child_order_type + oneof ChildOrderType { MarketOrder market_order = 30; LimitOrder limit_order = 40; @@ -320,7 +320,7 @@ message BTSTimeSliceOrder PriceOffset child_order_offset = 50; /// the earlier order can either be left, or its /// price moved toward the inside market by payup_ticks - oneof left_over_action + oneof LeftOverAction { bool leave = 60; double payup_ticks = 70; @@ -343,12 +343,12 @@ ii. If the stop order is trigerred, the Limit order is cancelled message BTSOCOOrder { PriceTrigger price_trigger = 10; - oneof native_trigger_order_type + oneof NativeTriggerOrderType { MarketOrder market_order = 20; LimitOrder limit_order = 30; } - oneof order_price + oneof OrderPrice { PriceOffset payup = 40; double price = 50;