// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using Regorus.Internal; #nullable enable namespace Regorus { /// /// Mutable, single-threaded builder for . /// Load alias data, then call to freeze the registry. /// public unsafe sealed class AliasRegistryBuilder : SafeHandleWrapper { /// /// Create an empty alias registry builder. /// public AliasRegistryBuilder() : base(RegorusAliasRegistryBuilderHandle.Create(), nameof(AliasRegistryBuilder)) { } /// /// Load control-plane alias data (array of ProviderAliases) from a JSON string. /// public void LoadJson(string json) { Utf8Marshaller.WithUtf8(json, jsonPtr => { UseHandle(builderPtr => { ResultHelpers.GetStringResult(API.regorus_alias_registry_builder_load_json( (RegorusAliasRegistryBuilder*)builderPtr, (byte*)jsonPtr)); }); }); } /// /// Load a data-plane policy manifest from a JSON string. /// public void LoadManifest(string json) { Utf8Marshaller.WithUtf8(json, jsonPtr => { UseHandle(builderPtr => { ResultHelpers.GetStringResult(API.regorus_alias_registry_builder_load_manifest( (RegorusAliasRegistryBuilder*)builderPtr, (byte*)jsonPtr)); }); }); } /// /// Freeze the builder into an immutable, thread-safe alias registry. /// public AliasRegistry Build() { return UseHandle(builderPtr => { var registryPtr = ResultHelpers.GetPointerResult( API.regorus_alias_registry_builder_build((RegorusAliasRegistryBuilder*)builderPtr)); return new AliasRegistry(RegorusAliasRegistryHandle.FromPointer(registryPtr)); }); } } }