feat(batch1): add mapped proto scan helpers with boundary tests
This commit is contained in:
@@ -51,6 +51,12 @@ public static class ProtoWire
|
|||||||
return (num, typ, sizeTag + sizeValue, null);
|
return (num, typ, sizeTag + sizeValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compatibility mapped entrypoint for PortTracker: <c>protoScanField</c>.
|
||||||
|
/// </summary>
|
||||||
|
public static (int num, int typ, int size, Exception? err) ProtoScanField(ReadOnlySpan<byte> b)
|
||||||
|
=> ScanField(b);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a protobuf tag varint and returns field number, wire type, and bytes consumed.
|
/// Reads a protobuf tag varint and returns field number, wire type, and bytes consumed.
|
||||||
/// Mirrors <c>protoScanTag</c>.
|
/// Mirrors <c>protoScanTag</c>.
|
||||||
@@ -71,6 +77,12 @@ public static class ProtoWire
|
|||||||
return (num, typ, size, null);
|
return (num, typ, size, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compatibility mapped entrypoint for PortTracker: <c>protoScanTag</c>.
|
||||||
|
/// </summary>
|
||||||
|
public static (int num, int typ, int size, Exception? err) ProtoScanTag(ReadOnlySpan<byte> b)
|
||||||
|
=> ScanTag(b);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the byte count consumed by a field value with the given wire type.
|
/// Returns the byte count consumed by a field value with the given wire type.
|
||||||
/// Mirrors <c>protoScanFieldValue</c>.
|
/// Mirrors <c>protoScanFieldValue</c>.
|
||||||
@@ -98,6 +110,12 @@ public static class ProtoWire
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compatibility mapped entrypoint for PortTracker: <c>protoScanFieldValue</c>.
|
||||||
|
/// </summary>
|
||||||
|
public static (int size, Exception? err) ProtoScanFieldValue(int typ, ReadOnlySpan<byte> b)
|
||||||
|
=> ScanFieldValue(typ, b);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// Varint decode
|
// Varint decode
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
@@ -170,6 +188,12 @@ public static class ProtoWire
|
|||||||
return (0, 0, ErrOverflow);
|
return (0, 0, ErrOverflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compatibility mapped entrypoint for PortTracker: <c>protoScanVarint</c>.
|
||||||
|
/// </summary>
|
||||||
|
public static (ulong v, int size, Exception? err) ProtoScanVarint(ReadOnlySpan<byte> b)
|
||||||
|
=> ScanVarint(b);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// Length-delimited decode
|
// Length-delimited decode
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
@@ -190,6 +214,12 @@ public static class ProtoWire
|
|||||||
return (lenSize + (int)l, null);
|
return (lenSize + (int)l, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compatibility mapped entrypoint for PortTracker: <c>protoScanBytes</c>.
|
||||||
|
/// </summary>
|
||||||
|
public static (int size, Exception? err) ProtoScanBytes(ReadOnlySpan<byte> b)
|
||||||
|
=> ScanBytes(b);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// Varint encode
|
// Varint encode
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// Copyright 2012-2025 The NATS Authors
|
||||||
|
// Licensed under the Apache License, Version 2.0
|
||||||
|
|
||||||
|
using Shouldly;
|
||||||
|
using ZB.MOM.NatsNet.Server.Internal;
|
||||||
|
|
||||||
|
namespace ZB.MOM.NatsNet.Server.Tests.Internal;
|
||||||
|
|
||||||
|
public class ProtoWireTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void ProtoScanTag_ValidTag_ReturnsFieldTypeAndSize()
|
||||||
|
{
|
||||||
|
var (num, typ, size, err) = ProtoWire.ProtoScanTag([0x7A]); // field=15, type=2
|
||||||
|
|
||||||
|
err.ShouldBeNull();
|
||||||
|
num.ShouldBe(15);
|
||||||
|
typ.ShouldBe(2);
|
||||||
|
size.ShouldBe(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ProtoScanTag_InvalidFieldNumber_ReturnsError()
|
||||||
|
{
|
||||||
|
var (_, _, _, err) = ProtoWire.ProtoScanTag([0x02]); // field=0, type=2
|
||||||
|
|
||||||
|
err.ShouldNotBeNull();
|
||||||
|
err.Message.ShouldContain("invalid field number");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ProtoScanFieldValue_UnsupportedWireType_ReturnsError()
|
||||||
|
{
|
||||||
|
var (_, err) = ProtoWire.ProtoScanFieldValue(3, [0x01]);
|
||||||
|
|
||||||
|
err.ShouldNotBeNull();
|
||||||
|
err.Message.ShouldContain("unsupported type");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ProtoScanVarint_InsufficientData_ReturnsError()
|
||||||
|
{
|
||||||
|
var (_, _, err) = ProtoWire.ProtoScanVarint([0x80]);
|
||||||
|
|
||||||
|
err.ShouldNotBeNull();
|
||||||
|
err.Message.ShouldContain("insufficient data");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ProtoScanVarint_Overflow_ReturnsError()
|
||||||
|
{
|
||||||
|
var (_, _, err) = ProtoWire.ProtoScanVarint([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x02]);
|
||||||
|
|
||||||
|
err.ShouldNotBeNull();
|
||||||
|
err.Message.ShouldContain("too much data");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ProtoScanBytes_LengthDelimited_ReturnsLengthPrefixPlusPayloadSize()
|
||||||
|
{
|
||||||
|
var (size, err) = ProtoWire.ProtoScanBytes([0x03, (byte)'a', (byte)'b', (byte)'c']);
|
||||||
|
|
||||||
|
err.ShouldBeNull();
|
||||||
|
size.ShouldBe(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ProtoScanField_ValidLengthDelimited_ReturnsTotalFieldSize()
|
||||||
|
{
|
||||||
|
var (num, typ, size, err) = ProtoWire.ProtoScanField([0x0A, 0x03, (byte)'a', (byte)'b', (byte)'c']); // field=1,type=2
|
||||||
|
|
||||||
|
err.ShouldBeNull();
|
||||||
|
num.ShouldBe(1);
|
||||||
|
typ.ShouldBe(2);
|
||||||
|
size.ShouldBe(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
porting.db
BIN
porting.db
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
# NATS .NET Porting Status Report
|
# NATS .NET Porting Status Report
|
||||||
|
|
||||||
Generated: 2026-02-28 11:30:24 UTC
|
Generated: 2026-02-28 11:33:10 UTC
|
||||||
|
|
||||||
## Modules (12 total)
|
## Modules (12 total)
|
||||||
|
|
||||||
@@ -12,10 +12,10 @@ Generated: 2026-02-28 11:30:24 UTC
|
|||||||
|
|
||||||
| Status | Count |
|
| Status | Count |
|
||||||
|--------|-------|
|
|--------|-------|
|
||||||
| deferred | 2373 |
|
| deferred | 2368 |
|
||||||
| n_a | 24 |
|
| n_a | 24 |
|
||||||
| stub | 1 |
|
| stub | 1 |
|
||||||
| verified | 1275 |
|
| verified | 1280 |
|
||||||
|
|
||||||
## Unit Tests (3257 total)
|
## Unit Tests (3257 total)
|
||||||
|
|
||||||
@@ -34,4 +34,4 @@ Generated: 2026-02-28 11:30:24 UTC
|
|||||||
|
|
||||||
## Overall Progress
|
## Overall Progress
|
||||||
|
|
||||||
**2477/6942 items complete (35.7%)**
|
**2482/6942 items complete (35.8%)**
|
||||||
|
|||||||
37
reports/report_d8d71ea.md
Normal file
37
reports/report_d8d71ea.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# NATS .NET Porting Status Report
|
||||||
|
|
||||||
|
Generated: 2026-02-28 11:33:10 UTC
|
||||||
|
|
||||||
|
## Modules (12 total)
|
||||||
|
|
||||||
|
| Status | Count |
|
||||||
|
|--------|-------|
|
||||||
|
| verified | 12 |
|
||||||
|
|
||||||
|
## Features (3673 total)
|
||||||
|
|
||||||
|
| Status | Count |
|
||||||
|
|--------|-------|
|
||||||
|
| deferred | 2368 |
|
||||||
|
| n_a | 24 |
|
||||||
|
| stub | 1 |
|
||||||
|
| verified | 1280 |
|
||||||
|
|
||||||
|
## Unit Tests (3257 total)
|
||||||
|
|
||||||
|
| Status | Count |
|
||||||
|
|--------|-------|
|
||||||
|
| deferred | 2091 |
|
||||||
|
| n_a | 187 |
|
||||||
|
| verified | 979 |
|
||||||
|
|
||||||
|
## Library Mappings (36 total)
|
||||||
|
|
||||||
|
| Status | Count |
|
||||||
|
|--------|-------|
|
||||||
|
| mapped | 36 |
|
||||||
|
|
||||||
|
|
||||||
|
## Overall Progress
|
||||||
|
|
||||||
|
**2482/6942 items complete (35.8%)**
|
||||||
Reference in New Issue
Block a user