diff --git a/src/ntcore/ProtobufTopic.cs b/src/ntcore/ProtobufTopic.cs index 0c7ee8bc..148b4ce5 100644 --- a/src/ntcore/ProtobufTopic.cs +++ b/src/ntcore/ProtobufTopic.cs @@ -7,7 +7,7 @@ namespace NetworkTables; public sealed class ProtobufTopic : Topic, IEquatable?>, IEqualityOperators?, ProtobufTopic?, bool> where T : IProtobufSerializable { - public IGenericProtobuf Proto { get; } = T.ProtoGeneric; + public IGenericProtobuf Proto { get; } = T.Proto; private ProtobufTopic(Topic topic) : base(topic.Instance, topic.Handle) { diff --git a/src/wpimath/Geometry/Pose2d.cs b/src/wpimath/Geometry/Pose2d.cs index 3cbe9b5c..15d555c2 100644 --- a/src/wpimath/Geometry/Pose2d.cs +++ b/src/wpimath/Geometry/Pose2d.cs @@ -58,7 +58,7 @@ public partial class Pose2dJsonContext : JsonSerializerContext { } -public readonly struct Pose2d : IStructSerializable, IProtobufSerializable, +public readonly struct Pose2d : IStructSerializable, IProtobufSerializable, IMultiplyOperators, IAdditionOperators, ISubtractionOperators, @@ -69,7 +69,6 @@ public partial class Pose2dJsonContext : JsonSerializerContext { public static IStruct Struct { get; } = new Pose2dStruct(); public static IProtobuf Proto { get; } = new Pose2dProto(); - static IGenericProtobuf IProtobufSerializable.ProtoGeneric => Proto; [JsonInclude] [JsonPropertyName("translation")] diff --git a/src/wpimath/Geometry/Quaternion.cs b/src/wpimath/Geometry/Quaternion.cs index 6adef4ca..795331a6 100644 --- a/src/wpimath/Geometry/Quaternion.cs +++ b/src/wpimath/Geometry/Quaternion.cs @@ -77,7 +77,6 @@ public partial class QuaternionJsonContext : JsonSerializerContext { public static IStruct Struct { get; } = new QuaternionStruct(); public static IProtobuf Proto { get; } = new QuaternionProto(); - static IGenericProtobuf IProtobufSerializable.ProtoGeneric => Proto; [JsonInclude] public double W { get; init; } diff --git a/src/wpimath/Geometry/Rotation2d.cs b/src/wpimath/Geometry/Rotation2d.cs index a6fe0a95..847fc587 100644 --- a/src/wpimath/Geometry/Rotation2d.cs +++ b/src/wpimath/Geometry/Rotation2d.cs @@ -68,7 +68,6 @@ public partial class Rotation2dJsonContext : JsonSerializerContext { public static IStruct Struct { get; } = new Rotation2dStruct(); public static IProtobuf Proto { get; } = new Rotation2dProto(); - static IGenericProtobuf IProtobufSerializable.ProtoGeneric => Proto; public Rotation2d(Angle angle) { diff --git a/src/wpimath/Geometry/Rotation3d.cs b/src/wpimath/Geometry/Rotation3d.cs index 70300401..b73e3df4 100644 --- a/src/wpimath/Geometry/Rotation3d.cs +++ b/src/wpimath/Geometry/Rotation3d.cs @@ -72,7 +72,6 @@ public partial class Rotation3dJsonContext : JsonSerializerContext { public static IStruct Struct { get; } = new Rotation3dStruct(); public static IProtobuf Proto { get; } = new Rotation3dProto(); - static IGenericProtobuf IProtobufSerializable.ProtoGeneric => Proto; [JsonInclude] [JsonPropertyName("quaternion")] diff --git a/src/wpimath/Geometry/Transform2d.cs b/src/wpimath/Geometry/Transform2d.cs index 45d3b9f9..e34e6dbe 100644 --- a/src/wpimath/Geometry/Transform2d.cs +++ b/src/wpimath/Geometry/Transform2d.cs @@ -71,7 +71,6 @@ public partial class Transform2dJsonContext : JsonSerializerContext { public static IStruct Struct { get; } = new Transform2dStruct(); public static IProtobuf Proto { get; } = new Transform2dProto(); - static IGenericProtobuf IProtobufSerializable.ProtoGeneric => Proto; [JsonInclude] [JsonPropertyName("translation")] diff --git a/src/wpimath/Geometry/Translation2d.cs b/src/wpimath/Geometry/Translation2d.cs index 6a434e80..aa707757 100644 --- a/src/wpimath/Geometry/Translation2d.cs +++ b/src/wpimath/Geometry/Translation2d.cs @@ -58,7 +58,7 @@ public partial class Translation2dJsonContext : JsonSerializerContext { } -public readonly struct Translation2d : IStructSerializable, IProtobufSerializable, +public readonly struct Translation2d : IStructSerializable, IProtobufSerializable, IAdditionOperators, ISubtractionOperators, IUnaryNegationOperators, @@ -71,7 +71,6 @@ public partial class Translation2dJsonContext : JsonSerializerContext { public static IStruct Struct { get; } = new Translation2dStruct(); public static IProtobuf Proto { get; } = new Translation2dProto(); - static IGenericProtobuf IProtobufSerializable.ProtoGeneric => Proto; [JsonIgnore] public Length X { get; } diff --git a/src/wpimath/Geometry/Twist2d.cs b/src/wpimath/Geometry/Twist2d.cs index c191dcdc..6c474c9d 100644 --- a/src/wpimath/Geometry/Twist2d.cs +++ b/src/wpimath/Geometry/Twist2d.cs @@ -71,7 +71,6 @@ public partial class Twist2dJsonContext : JsonSerializerContext { public static IStruct Struct { get; } = new Twist2dStruct(); public static IProtobuf Proto { get; } = new Twist2dProto(); - static IGenericProtobuf IProtobufSerializable.ProtoGeneric => Proto; [JsonIgnore] public Length Dx { get; init; } diff --git a/src/wpimath/Geometry/Twist3d.cs b/src/wpimath/Geometry/Twist3d.cs index b095c1e1..3823a7b3 100644 --- a/src/wpimath/Geometry/Twist3d.cs +++ b/src/wpimath/Geometry/Twist3d.cs @@ -83,7 +83,6 @@ public partial class Twist3dJsonContext : JsonSerializerContext { public static IStruct Struct { get; } = new Twist3dStruct(); public static IProtobuf Proto { get; } = new Twist3dProto(); - static IGenericProtobuf IProtobufSerializable.ProtoGeneric => Proto; [JsonIgnore] public Length Dx { get; init; } diff --git a/src/wpiutil/IWPISerializable.cs b/src/wpiutil/IWPISerializable.cs index cf2892b1..102e1e5b 100644 --- a/src/wpiutil/IWPISerializable.cs +++ b/src/wpiutil/IWPISerializable.cs @@ -3,4 +3,4 @@ namespace WPIUtil; /// /// Marker interface to indicate a class is serializable using WPI serialization methods. /// -public interface IWPISerializable { } +public interface IWPISerializable where T : IWPISerializable { } diff --git a/src/wpiutil/Logging/ProtobufLogEntry.cs b/src/wpiutil/Logging/ProtobufLogEntry.cs index 0409b597..a242bc60 100644 --- a/src/wpiutil/Logging/ProtobufLogEntry.cs +++ b/src/wpiutil/Logging/ProtobufLogEntry.cs @@ -7,9 +7,9 @@ public sealed class ProtobufLogEntry : DataLogEntry where T : IProtobufSerial private readonly ProtobufBuffer m_storage = new(); private readonly object m_lockObject = new(); - public ProtobufLogEntry(DataLog log, string name, string metadata = "", long timestamp = 0) : base(log, name, T.ProtoGeneric.TypeString, metadata, timestamp) + public ProtobufLogEntry(DataLog log, string name, string metadata = "", long timestamp = 0) : base(log, name, T.Proto.TypeString, metadata, timestamp) { - log.AddSchema(T.ProtoGeneric, timestamp); + log.AddSchema(T.Proto, timestamp); } public void Append(T value, long timestamp = 0) diff --git a/src/wpiutil/Serialization/Protobuf/IProtobufSerializable.cs b/src/wpiutil/Serialization/Protobuf/IProtobufSerializable.cs index 71167d08..c0321d9e 100644 --- a/src/wpiutil/Serialization/Protobuf/IProtobufSerializable.cs +++ b/src/wpiutil/Serialization/Protobuf/IProtobufSerializable.cs @@ -3,11 +3,16 @@ namespace WPIUtil.Serialization.Protobuf; public interface IProtobufSerializable : IWPISerializable + where T : IProtobufSerializable { - public static abstract IGenericProtobuf ProtoGeneric { get; } + public static abstract IGenericProtobuf Proto { get; } } -public interface IProtobufSerializable : IProtobufSerializable where TProto : IMessage +public interface IProtobufSerializable : IProtobufSerializable + where T : IProtobufSerializable + where TProto : IMessage { - public static abstract IProtobuf Proto { get; } + public static new abstract IProtobuf Proto { get; } + + static IGenericProtobuf IProtobufSerializable.Proto => T.Proto; } diff --git a/src/wpiutil/Serialization/Protobuf/ProtobufBuffer.cs b/src/wpiutil/Serialization/Protobuf/ProtobufBuffer.cs index 3fed477a..09b32804 100644 --- a/src/wpiutil/Serialization/Protobuf/ProtobufBuffer.cs +++ b/src/wpiutil/Serialization/Protobuf/ProtobufBuffer.cs @@ -6,7 +6,7 @@ public struct ProtobufBuffer where T : IProtobufSerializable { public ProtobufBuffer() { - Proto = T.ProtoGeneric; + Proto = T.Proto; m_msg = Proto.GenericCreateMessage(); } diff --git a/src/wpiutil/Serialization/Struct/StructSerializable.cs b/src/wpiutil/Serialization/Struct/StructSerializable.cs index 4e7eeee2..dc8511a8 100644 --- a/src/wpiutil/Serialization/Struct/StructSerializable.cs +++ b/src/wpiutil/Serialization/Struct/StructSerializable.cs @@ -1,6 +1,7 @@ namespace WPIUtil.Serialization.Struct; public interface IStructSerializable : IWPISerializable + where T : IStructSerializable { public static abstract IStruct Struct { get; } } diff --git a/test/wpimath.test/GenericHelpers.cs b/test/wpimath.test/GenericHelpers.cs index 6ee0d389..f1581575 100644 --- a/test/wpimath.test/GenericHelpers.cs +++ b/test/wpimath.test/GenericHelpers.cs @@ -16,9 +16,9 @@ public static T StructRoundTrip(T start) where T : IStructSerializable public static T ProtoRoundTrip(T start) where T : IProtobufSerializable { - var proto = T.ProtoGeneric.GenericCreateMessage(); - T.ProtoGeneric.GenericPack(proto, start); - return T.ProtoGeneric.GenericUnpack(proto); + var proto = T.Proto.GenericCreateMessage(); + T.Proto.GenericPack(proto, start); + return T.Proto.GenericUnpack(proto); } public static T ProtoTypedRoundTrip(T start) where T : IProtobufSerializable where U : IMessage