0ffd4bdbea
Comment/XML-doc changes only, no code logic: - strip project-tracking references (WP*, P*-*, row-NN, #NN, Task N) from comments, keeping the explanatory rationale - add missing summaries, <param>, <returns>, <typeparam> and <inheritdoc/> - replace misused <inheritdoc/> with real docs; where <inheritdoc/> was combined with useful remarks, move the rationale into // comments - drop stale replicationActor <param> on DeploymentManagerActor ctor Remaining 5 are false positives (CWE-1236 x2, failures-1, year-0001, M365). Build 0 errors / 0 warnings.
37 lines
2.0 KiB
C#
37 lines
2.0 KiB
C#
using Google.Protobuf;
|
|
using Google.Protobuf.Collections;
|
|
using Grpc.Core;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Grpc;
|
|
|
|
/// <summary>Bounds audit batches using complete protobuf row sizes, length/tag prefixes, and gRPC framing.</summary>
|
|
public static class AuditWireBudget
|
|
{
|
|
/// <summary>Five-byte gRPC frame plus two bytes reserved for a true MoreAvailable field.</summary>
|
|
public const int InitialBytes = 7;
|
|
|
|
/// <summary>
|
|
/// Appends one row to a repeated-message collection if it fits. A row larger than the
|
|
/// normal budget travels alone, up to the hard channel ceiling. Oversize rows are retained
|
|
/// locally and fail explicitly with their identity; they are never acknowledged or truncated.
|
|
/// </summary>
|
|
/// <typeparam name="T">The protobuf message type of the rows.</typeparam>
|
|
/// <param name="rows">The repeated field to append to.</param>
|
|
/// <param name="row">The row to append.</param>
|
|
/// <param name="wireBytes">The running wire size of the batch; increased by the row's size when appended.</param>
|
|
/// <param name="rowIdentity">Identity of the row, used in the error raised when it exceeds the hard ceiling.</param>
|
|
/// <returns><c>true</c> when the row was appended; <c>false</c> when it does not fit in the current batch.</returns>
|
|
public static bool TryAppend<T>(RepeatedField<T> rows, T row, ref int wireBytes, string rowIdentity)
|
|
where T : IMessage<T>
|
|
{
|
|
var rowBytes = 1L + CodedOutputStream.ComputeMessageSize(row);
|
|
if (rows.Count > 0 && wireBytes + rowBytes > GrpcMessageLimits.AuditBatchBytes) return false;
|
|
if (rowBytes + InitialBytes > GrpcMessageLimits.MaxMessageBytes)
|
|
throw new RpcException(new Status(StatusCode.ResourceExhausted,
|
|
$"Audit row {rowIdentity} requires {rowBytes + InitialBytes} wire bytes, exceeding {GrpcMessageLimits.MaxMessageBytes}; retained locally. Reduce its payload or raise coordinated peer limits before retrying."));
|
|
rows.Add(row);
|
|
wireBytes += (int)rowBytes;
|
|
return true;
|
|
}
|
|
}
|