Files
lmxopcua/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/ProjectedProofSize.cs
T

24 lines
1.6 KiB
C#

using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
namespace ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
/// <summary>Conservative retained size of one detached projected proof, including both metadata views.</summary>
internal static class ProjectedProofSize
{
internal static long Estimate(ProjectedNodeProof proof) => checked(1024L + Text(proof.LocalIdentifier) +
Metadata(proof.Metadata) + Metadata(proof.OriginMetadata) + View(proof.Subject.View) +
Text(proof.Subject.Scope.ClusterId) + Strings(proof.Subject.Scope.Segments) +
Strings(proof.Subject.LocalAncestry) + Serving(proof.Subject.Serving) + Serving(proof.Lease.Serving));
private static long Text(string? value) => checked(32L + 2L * (value?.Length ?? 0));
private static long Strings(IReadOnlyList<string> values) => checked(64L + 8L * values.Count + values.Sum(Text));
private static long View(DataView view) => checked(128L + Text(view.Subject) + Text(view.MappingId) +
Text(view.Address.OriginClusterId) + Text(view.Address.NamespaceUri) +
Text(view.Address.IdentifierKind) + Text(view.Address.Identifier));
private static long Serving(ServingIdentity? serving) => serving is null ? 0 : checked(128L +
Text(serving.NodeId) + Text(serving.Incarnation) + Text(serving.Role));
private static long Metadata(DataMetadata value) => checked(256L + View(value.View) +
Text(value.BrowseName) + Text(value.NodeKind) + Text(value.StableSourceId) + Text(value.EngineeringUnits) +
64L + 4L * value.Dimensions.Count + Serving(value.Serving));
}