Files
riojoy/src/RioJoy.Core/Protocol/RioPacket.cs
T
CydandClaude Fable 5 3b2af7b79a Phase 8A (1/2): de-Span the serial layer, swap JSON to Newtonsoft
Prepares RioJoy.Core for the net40 (Windows XP) target, which has no
System.Memory, ValueTask, or System.Text.Json:
- IRioTransport and the whole protocol/framing layer now use byte[] +
  Task (RioPacket.Payload, PacketParser/Builder, RioChecksum, replies,
  AnalogReport, RioHidReport). At 9600 baud Span bought nothing; the
  SerialPortTransport bridge copies disappear entirely.
- ConfigStore/OverlayTemplateStore switch to Newtonsoft 13 with the
  same conventions (indented, PascalCase, string enums, null-skipping);
  verified against the real STJ-written config.json and regions.json
  (load + round-trip). System.Memory and System.Text.Json packages
  dropped.

275 tests green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 20:36:19 -05:00

38 lines
1.3 KiB
C#

namespace RioJoy.Core.Protocol;
/// <summary>
/// A fully-framed RIO packet: a command plus its fixed-length payload (the
/// 7-bit data bytes between the command byte and the checksum). The checksum
/// itself is not stored — it is validated/derived at the framing boundary.
/// </summary>
public readonly struct RioPacket
{
/// <summary>The command byte.</summary>
public RioCommand Command { get; }
/// <summary>
/// The payload bytes (high bit always clear; treat as read-only). Length
/// matches <see cref="RioCommandTable.PayloadLength(RioCommand)"/>.
/// </summary>
public byte[] Payload { get; }
public RioPacket(RioCommand command, byte[] payload)
{
if (payload is null) throw new ArgumentNullException(nameof(payload));
int expected = RioCommandTable.PayloadLength(command);
if (payload.Length != expected)
throw new ArgumentException(
$"{command} expects a {expected}-byte payload, got {payload.Length}.",
nameof(payload));
Command = command;
Payload = payload;
}
public override string ToString()
{
var hex = BitConverter.ToString(Payload).Replace("-", string.Empty);
return Payload.Length == 0 ? Command.ToString() : $"{Command} [{hex}]";
}
}