public override int GetHashCode() { int hash = 1; if (Schema.Length != 0) { hash ^= Schema.GetHashCode(); } if (Comment.Length != 0) { hash ^= Comment.GetHashCode(); } if (Language.Length != 0) { hash ^= Language.GetHashCode(); } if (ProtoPackage.Length != 0) { hash ^= ProtoPackage.GetHashCode(); } if (LibraryPackage.Length != 0) { hash ^= LibraryPackage.GetHashCode(); } hash ^= Services.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public ServiceDetails(ProtoCatalog catalog, string ns, ServiceDescriptor desc, ServiceConfig grpcServiceConfig, Service serviceConfig, ApiTransports transports) { Catalog = catalog; Namespace = ns; ProtoPackage = desc.File.Package; PackageVersion = ProtoPackage.Split('.').FirstOrDefault(part => ApiVersionPattern.IsMatch(part)); DocLines = desc.Declaration.DocLines().ToList(); SnippetsNamespace = $"{ns}.Snippets"; UnitTestsNamespace = $"{ns}.Tests"; // Must come early; used by `MethodDetails.Create()` MethodGrpcConfigsByName = grpcServiceConfig?.MethodConfig .SelectMany(conf => conf.Name.Select(name => (name, conf))) .Where(x => x.name.Service == desc.FullName) .ToImmutableDictionary(x => $"{x.name.Service}/{x.name.Method}", x => x.conf) ?? ImmutableDictionary <string, MethodConfig> .Empty; ServiceFullName = desc.FullName; ServiceName = desc.Name; DocumentationName = desc.Name; // TODO: There may be a more suitable name than this. ProtoTyp = Typ.Manual(ns, desc.Name); GrpcClientTyp = Typ.Nested(ProtoTyp, $"{desc.Name}Client"); SettingsTyp = Typ.Manual(ns, $"{desc.Name}Settings"); BuilderTyp = Typ.Manual(ns, $"{desc.Name}ClientBuilder"); ClientAbstractTyp = Typ.Manual(ns, $"{desc.Name}Client"); ClientImplTyp = Typ.Manual(ns, $"{desc.Name}ClientImpl"); DefaultHost = desc.GetExtension(ClientExtensions.DefaultHost) ?? ""; // We need to account for regional default endpoints like "us-east1-pubsub.googleapis.com" DefaultHostServiceName = DefaultHost .Split('.', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?.Split('-', StringSplitOptions.RemoveEmptyEntries).LastOrDefault(); DefaultPort = 443; // Hardcoded; this is not specifiable by proto annotation. var oauthScopes = desc.GetExtension(ClientExtensions.OauthScopes); DefaultScopes = string.IsNullOrEmpty(oauthScopes) ? Enumerable.Empty <string>() : oauthScopes.Split(',', ' '); Methods = desc.Methods.Select(x => MethodDetails.Create(this, x)).ToList(); ServiceSnippetsTyp = Typ.Manual(SnippetsNamespace, $"AllGenerated{desc.Name}ClientSnippets"); SnippetsTyp = Typ.Manual(SnippetsNamespace, $"Generated{desc.Name}ClientSnippets"); SnippetsClientName = $"{desc.Name.ToLowerCamelCase()}Client"; UnitTestsTyp = Typ.Manual(UnitTestsNamespace, $"Generated{desc.Name}ClientTest"); NonStandardLro = NonStandardLroDetails.ForService(desc); Mixins = serviceConfig?.Apis .Select(api => AvailableMixins.GetValueOrDefault(api.Name)) .Where(mixin => mixin is object) // Don't use mixins within the package that contains that mixin. .Where(mixin => mixin.GapicClientType.Namespace != ns) .ToList() ?? Enumerable.Empty <MixinDetails>(); Transports = transports; }
void TestProtobuf() { var login = new ReqLogin(); login.Nickname = "Jing"; var msg = new ProtoPackage(); msg.MsgId = 1; msg.MsgBody = login.ToByteString(); Dumper.Dump(msg); byte[] bytes = msg.ToByteArray(); var obj = ProtoPackage.Parser.ParseFrom(bytes); var obj1 = ReqLogin.Parser.ParseFrom(msg.MsgBody); Debug.Log(Log.C(Log.COLOR_PURPLE, obj1.Nickname)); }