예제 #1
0
        /// <summary>
        ///     Initialize a new instance of the ProtobufSerializer class.
        /// </summary>
        public ProtobufSerializer(ISchemaRegistryClient schemaRegistryClient, ProtobufSerializerConfig config = null)
        {
            this.schemaRegistryClient = schemaRegistryClient;

            if (config == null)
            {
                this.referenceSubjectNameStrategy = ReferenceSubjectNameStrategy.ReferenceName.ToDelegate();
                return;
            }

            var nonProtobufConfig = config.Where(item => !item.Key.StartsWith("protobuf."));

            if (nonProtobufConfig.Count() > 0)
            {
                throw new ArgumentException($"ProtobufSerializer: unknown configuration parameter {nonProtobufConfig.First().Key}");
            }

            if (config.BufferBytes != null)
            {
                this.initialBufferSize = config.BufferBytes.Value;
            }
            if (config.AutoRegisterSchemas != null)
            {
                this.autoRegisterSchema = config.AutoRegisterSchemas.Value;
            }
            if (config.SubjectNameStrategy != null)
            {
                this.subjectNameStrategy = config.SubjectNameStrategy.Value.ToDelegate();
            }
            this.referenceSubjectNameStrategy = config.ReferenceSubjectNameStrategy == null
                ? ReferenceSubjectNameStrategy.ReferenceName.ToDelegate()
                : config.ReferenceSubjectNameStrategy.Value.ToDelegate();
        }
        /// <summary>
        ///     Initialize a new instance of the ProtobufSerializer class.
        /// </summary>
        public ProtobufSerializer(ISchemaRegistryClient schemaRegistryClient, ProtobufSerializerConfig config = null)
        {
            this.schemaRegistryClient = schemaRegistryClient;

            if (config == null)
            {
                this.referenceSubjectNameStrategy = ReferenceSubjectNameStrategy.ReferenceName.ToDelegate();
                return;
            }

            var nonProtobufConfig = config.Where(item => !item.Key.StartsWith("protobuf."));

            if (nonProtobufConfig.Count() > 0)
            {
                throw new ArgumentException($"ProtobufSerializer: unknown configuration parameter {nonProtobufConfig.First().Key}");
            }

            if (config.BufferBytes != null)
            {
                this.initialBufferSize = config.BufferBytes.Value;
            }
            if (config.AutoRegisterSchemas != null)
            {
                this.autoRegisterSchema = config.AutoRegisterSchemas.Value;
            }
            if (config.NormalizeSchemas != null)
            {
                this.normalizeSchemas = config.NormalizeSchemas.Value;
            }
            if (config.UseLatestVersion != null)
            {
                this.useLatestVersion = config.UseLatestVersion.Value;
            }
            if (config.SkipKnownTypes != null)
            {
                this.skipKnownTypes = config.SkipKnownTypes.Value;
            }
            if (config.UseDeprecatedFormat != null)
            {
                this.useDeprecatedFormat = config.UseDeprecatedFormat.Value;
            }
            if (config.SubjectNameStrategy != null)
            {
                this.subjectNameStrategy = config.SubjectNameStrategy.Value.ToDelegate();
            }
            this.referenceSubjectNameStrategy = config.ReferenceSubjectNameStrategy == null
                ? ReferenceSubjectNameStrategy.ReferenceName.ToDelegate()
                : config.ReferenceSubjectNameStrategy.Value.ToDelegate();

            if (this.useLatestVersion && this.autoRegisterSchema)
            {
                throw new ArgumentException($"ProtobufSerializer: cannot enable both use.latest.version and auto.register.schemas");
            }
        }
 private Confluent.SchemaRegistry.Serdes.ProtobufSerializerConfig GetSerializerConfig(ISchemaRegistryConfig config)
 {
     Confluent.SchemaRegistry.Serdes.ProtobufSerializerConfig c = new Confluent.SchemaRegistry.Serdes.ProtobufSerializerConfig();
     if (config.AutoRegisterSchemas.HasValue)
     {
         c.AutoRegisterSchemas = config.AutoRegisterSchemas;
     }
     if (config.SubjectNameStrategy.HasValue)
     {
         c.SubjectNameStrategy = (Confluent.SchemaRegistry.SubjectNameStrategy)config.SubjectNameStrategy.Value;
     }
     return(c);
 }