Skip to content

Basic packet span length check #4

@bcronje

Description

@bcronje

With the new SizeField and other dynamic length methods, do you think its worth adding a very basic auto generated span length check property for the entire packet? Something like the following could be a nice to have little feature, especially when packets have dynamic length fields:

public bool HasValidSpanLength () => _span.Length <= GetTotalSize();

Or maybe even a generated TryParsePacket static method, where you want to create a packet over an existing packet buffer:

public static bool TryParse(Span<byte> packetData, out MyPacketSpan packet)
{
  var myPacket = new MyPacketSpan(packetData);
  if (myPacket.HasValidSpanLength())
  {
    packet = myPacket;
    return true;
  }
  packet = null;
  return false;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions