Skip to content

Class PayloadSizeCalculator ​

Namespace: Momentum.Extensions.EventMarkdownGenerator.Services
Assembly: Momentum.Extensions.EventMarkdownGenerator.dll

Calculates estimated payload sizes for event properties based on type analysis and data annotation constraints (MaxLength, Range, StringLength). Subclass to define serialization-format-specific overhead (JSON, Binary, etc.).

csharp
public abstract class PayloadSizeCalculator

Inheritance ​

object ← PayloadSizeCalculator

Inherited Members ​

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors ​

PayloadSizeCalculator() ​

csharp
protected PayloadSizeCalculator()

Properties ​

FormatName ​

Display name of the serialization format (e.g., "JSON", "Binary").

csharp
public abstract string FormatName { get; }

Property Value ​

string

Methods ​

CalculatePropertySize(PropertyInfo, Type) ​

Calculates the estimated size in bytes for a property's serialized payload.

csharp
public PayloadSizeResult CalculatePropertySize(PropertyInfo property, Type propertyType)

Parameters ​

property PropertyInfo

The property to analyze for size constraints.

propertyType Type

The type of the property.

Returns ​

PayloadSizeResult

A result containing the estimated size, accuracy flag, and any warnings.

Create(string) ​

Creates a PayloadSizeCalculator for the specified serialization format.

csharp
public static PayloadSizeCalculator Create(string format)

Parameters ​

format string

Returns ​

PayloadSizeCalculator

GetCollectionOverhead() ​

Overhead bytes for collection wrappers (e.g., JSON [ ] adds 2 bytes).

csharp
protected abstract int GetCollectionOverhead()

Returns ​

int

GetElementSeparatorOverhead() ​

Overhead bytes per element separator (e.g., JSON comma: 1 byte).

csharp
protected abstract int GetElementSeparatorOverhead()

Returns ​

int

GetObjectOverhead() ​

Overhead bytes for object wrappers (e.g., JSON { } adds 2 bytes).

csharp
protected abstract int GetObjectOverhead()

Returns ​

int

GetPropertyOverhead(string) ​

Overhead bytes for a property entry including key and delimiters.

csharp
protected abstract int GetPropertyOverhead(string propertyName)

Parameters ​

propertyName string

Returns ​

int

GetStringValueOverhead() ​

Overhead bytes for a serialized string value (e.g., JSON quotes: 2 bytes).

csharp
protected abstract int GetStringValueOverhead()

Returns ​

int