From cbcbd91aff8bd9a7468008dce7fd264d7107fe1f Mon Sep 17 00:00:00 2001 From: Thad House Date: Thu, 18 Jan 2024 23:40:24 -0800 Subject: [PATCH] Add Struct and StructArray --- src/ntcore/Generated/BooleanArrayEntryImpl.cs | 10 +- src/ntcore/Generated/BooleanArrayPublisher.cs | 4 +- src/ntcore/Generated/BooleanEntryImpl.cs | 7 +- src/ntcore/Generated/BooleanPublisher.cs | 2 +- src/ntcore/Generated/DoubleArrayEntryImpl.cs | 10 +- src/ntcore/Generated/DoubleArrayPublisher.cs | 4 +- src/ntcore/Generated/DoubleEntryImpl.cs | 7 +- src/ntcore/Generated/DoublePublisher.cs | 2 +- src/ntcore/Generated/FloatArrayEntryImpl.cs | 10 +- src/ntcore/Generated/FloatArrayPublisher.cs | 4 +- src/ntcore/Generated/FloatEntryImpl.cs | 7 +- src/ntcore/Generated/FloatPublisher.cs | 2 +- src/ntcore/Generated/GenericEntryImpl.cs | 67 ++++---- src/ntcore/Generated/GenericPublisher.cs | 22 +-- src/ntcore/Generated/IntegerArrayEntryImpl.cs | 10 +- src/ntcore/Generated/IntegerArrayPublisher.cs | 4 +- src/ntcore/Generated/IntegerEntryImpl.cs | 7 +- src/ntcore/Generated/IntegerPublisher.cs | 2 +- src/ntcore/Generated/NetworkTableInstance.cs | 2 + src/ntcore/Generated/NetworkTableValue.cs | 22 +-- src/ntcore/Generated/RawEntryImpl.cs | 10 +- src/ntcore/Generated/RawPublisher.cs | 4 +- src/ntcore/Generated/RefNetworkTableValue.cs | 22 +-- src/ntcore/Generated/StringArrayEntryImpl.cs | 10 +- src/ntcore/Generated/StringArrayPublisher.cs | 4 +- src/ntcore/Generated/StringEntryImpl.cs | 7 +- src/ntcore/Generated/StringPublisher.cs | 2 +- src/ntcore/GenericEntryImpl.cs | 22 +-- src/ntcore/GenericPublisher.cs | 2 +- src/ntcore/NetworkTableInstance.cs | 6 + src/ntcore/NetworkTableValue.cs | 22 +-- src/ntcore/ProtobufEntryImpl.cs | 27 ++- src/ntcore/ProtobufPublisher.cs | 2 +- src/ntcore/StructArrayEntry.cs | 8 + src/ntcore/StructArrayEntryImpl.cs | 159 ++++++++++++++++++ src/ntcore/StructArrayPublisher.cs | 15 ++ src/ntcore/StructArraySubscriber.cs | 23 +++ src/ntcore/StructArrayTopic.cs | 68 ++++++-- src/ntcore/StructEntry.cs | 8 + src/ntcore/StructEntryImpl.cs | 157 +++++++++++++++++ src/ntcore/StructPublisher.cs | 14 ++ src/ntcore/StructSubscriber.cs | 22 +++ src/ntcore/StructTopic.cs | 77 +++++++++ .../Serialization/Struct/StructBuffer.cs | 17 ++ 44 files changed, 744 insertions(+), 169 deletions(-) create mode 100644 src/ntcore/StructArrayEntry.cs create mode 100644 src/ntcore/StructArrayEntryImpl.cs create mode 100644 src/ntcore/StructArrayPublisher.cs create mode 100644 src/ntcore/StructArraySubscriber.cs create mode 100644 src/ntcore/StructEntry.cs create mode 100644 src/ntcore/StructEntryImpl.cs create mode 100644 src/ntcore/StructPublisher.cs create mode 100644 src/ntcore/StructSubscriber.cs create mode 100644 src/ntcore/StructTopic.cs diff --git a/src/ntcore/Generated/BooleanArrayEntryImpl.cs b/src/ntcore/Generated/BooleanArrayEntryImpl.cs index 6dbb6451..2c665984 100644 --- a/src/ntcore/Generated/BooleanArrayEntryImpl.cs +++ b/src/ntcore/Generated/BooleanArrayEntryImpl.cs @@ -91,19 +91,19 @@ public bool[][] ReadQueueValues() } - public void Set(params bool[] value) + public void Set(bool[] value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeBooleanArray(0, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeBooleanArray(value.AsSpan(), 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, params bool[] value) + public void Set(bool[] value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeBooleanArray(time, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeBooleanArray(value.AsSpan(), time); NtCore.SetEntryValue(Handle, ntValue); } - public void SetDefault(params bool[] value) + public void SetDefault(bool[] value) { RefNetworkTableValue ntValue = RefNetworkTableValue.MakeBooleanArray(value.AsSpan()); NtCore.SetDefaultEntryValue(Handle, ntValue); diff --git a/src/ntcore/Generated/BooleanArrayPublisher.cs b/src/ntcore/Generated/BooleanArrayPublisher.cs index 610092eb..b6cf9efe 100644 --- a/src/ntcore/Generated/BooleanArrayPublisher.cs +++ b/src/ntcore/Generated/BooleanArrayPublisher.cs @@ -31,7 +31,7 @@ public interface IBooleanArrayPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, params bool[] value); + void Set(bool[] value, long time); /** * Publish a default value. @@ -40,5 +40,5 @@ public interface IBooleanArrayPublisher : IPublisher * * @param value value */ - void SetDefault(params bool[] value); + void SetDefault(bool[] value); } diff --git a/src/ntcore/Generated/BooleanEntryImpl.cs b/src/ntcore/Generated/BooleanEntryImpl.cs index fa07e462..dc1d94fc 100644 --- a/src/ntcore/Generated/BooleanEntryImpl.cs +++ b/src/ntcore/Generated/BooleanEntryImpl.cs @@ -4,6 +4,7 @@ // THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY +using System; using NetworkTables.Handles; using NetworkTables.Natives; @@ -92,13 +93,13 @@ public bool[] ReadQueueValues() public void Set(bool value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeBoolean(0, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeBoolean(value, 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, bool value) + public void Set(bool value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeBoolean(time, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeBoolean(value, time); NtCore.SetEntryValue(Handle, ntValue); } diff --git a/src/ntcore/Generated/BooleanPublisher.cs b/src/ntcore/Generated/BooleanPublisher.cs index 3897979c..affa5fd4 100644 --- a/src/ntcore/Generated/BooleanPublisher.cs +++ b/src/ntcore/Generated/BooleanPublisher.cs @@ -31,7 +31,7 @@ public interface IBooleanPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, bool value); + void Set(bool value, long time); /** * Publish a default value. diff --git a/src/ntcore/Generated/DoubleArrayEntryImpl.cs b/src/ntcore/Generated/DoubleArrayEntryImpl.cs index a50ec04d..2addc7f5 100644 --- a/src/ntcore/Generated/DoubleArrayEntryImpl.cs +++ b/src/ntcore/Generated/DoubleArrayEntryImpl.cs @@ -91,19 +91,19 @@ public double[][] ReadQueueValues() } - public void Set(params double[] value) + public void Set(double[] value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeDoubleArray(0, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeDoubleArray(value.AsSpan(), 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, params double[] value) + public void Set(double[] value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeDoubleArray(time, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeDoubleArray(value.AsSpan(), time); NtCore.SetEntryValue(Handle, ntValue); } - public void SetDefault(params double[] value) + public void SetDefault(double[] value) { RefNetworkTableValue ntValue = RefNetworkTableValue.MakeDoubleArray(value.AsSpan()); NtCore.SetDefaultEntryValue(Handle, ntValue); diff --git a/src/ntcore/Generated/DoubleArrayPublisher.cs b/src/ntcore/Generated/DoubleArrayPublisher.cs index 59e282b5..bec34aff 100644 --- a/src/ntcore/Generated/DoubleArrayPublisher.cs +++ b/src/ntcore/Generated/DoubleArrayPublisher.cs @@ -31,7 +31,7 @@ public interface IDoubleArrayPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, params double[] value); + void Set(double[] value, long time); /** * Publish a default value. @@ -40,5 +40,5 @@ public interface IDoubleArrayPublisher : IPublisher * * @param value value */ - void SetDefault(params double[] value); + void SetDefault(double[] value); } diff --git a/src/ntcore/Generated/DoubleEntryImpl.cs b/src/ntcore/Generated/DoubleEntryImpl.cs index 388bf6b6..8b59dc57 100644 --- a/src/ntcore/Generated/DoubleEntryImpl.cs +++ b/src/ntcore/Generated/DoubleEntryImpl.cs @@ -4,6 +4,7 @@ // THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY +using System; using NetworkTables.Handles; using NetworkTables.Natives; @@ -92,13 +93,13 @@ public double[] ReadQueueValues() public void Set(double value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeDouble(0, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeDouble(value, 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, double value) + public void Set(double value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeDouble(time, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeDouble(value, time); NtCore.SetEntryValue(Handle, ntValue); } diff --git a/src/ntcore/Generated/DoublePublisher.cs b/src/ntcore/Generated/DoublePublisher.cs index 9ab2d688..0753c732 100644 --- a/src/ntcore/Generated/DoublePublisher.cs +++ b/src/ntcore/Generated/DoublePublisher.cs @@ -31,7 +31,7 @@ public interface IDoublePublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, double value); + void Set(double value, long time); /** * Publish a default value. diff --git a/src/ntcore/Generated/FloatArrayEntryImpl.cs b/src/ntcore/Generated/FloatArrayEntryImpl.cs index abae745c..d2791f12 100644 --- a/src/ntcore/Generated/FloatArrayEntryImpl.cs +++ b/src/ntcore/Generated/FloatArrayEntryImpl.cs @@ -91,19 +91,19 @@ public float[][] ReadQueueValues() } - public void Set(params float[] value) + public void Set(float[] value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeFloatArray(0, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeFloatArray(value.AsSpan(), 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, params float[] value) + public void Set(float[] value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeFloatArray(time, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeFloatArray(value.AsSpan(), time); NtCore.SetEntryValue(Handle, ntValue); } - public void SetDefault(params float[] value) + public void SetDefault(float[] value) { RefNetworkTableValue ntValue = RefNetworkTableValue.MakeFloatArray(value.AsSpan()); NtCore.SetDefaultEntryValue(Handle, ntValue); diff --git a/src/ntcore/Generated/FloatArrayPublisher.cs b/src/ntcore/Generated/FloatArrayPublisher.cs index 0a9dd0e9..a3c9bb82 100644 --- a/src/ntcore/Generated/FloatArrayPublisher.cs +++ b/src/ntcore/Generated/FloatArrayPublisher.cs @@ -31,7 +31,7 @@ public interface IFloatArrayPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, params float[] value); + void Set(float[] value, long time); /** * Publish a default value. @@ -40,5 +40,5 @@ public interface IFloatArrayPublisher : IPublisher * * @param value value */ - void SetDefault(params float[] value); + void SetDefault(float[] value); } diff --git a/src/ntcore/Generated/FloatEntryImpl.cs b/src/ntcore/Generated/FloatEntryImpl.cs index 2b42aebf..b4003363 100644 --- a/src/ntcore/Generated/FloatEntryImpl.cs +++ b/src/ntcore/Generated/FloatEntryImpl.cs @@ -4,6 +4,7 @@ // THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY +using System; using NetworkTables.Handles; using NetworkTables.Natives; @@ -92,13 +93,13 @@ public float[] ReadQueueValues() public void Set(float value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeFloat(0, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeFloat(value, 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, float value) + public void Set(float value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeFloat(time, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeFloat(value, time); NtCore.SetEntryValue(Handle, ntValue); } diff --git a/src/ntcore/Generated/FloatPublisher.cs b/src/ntcore/Generated/FloatPublisher.cs index a8515014..997827f5 100644 --- a/src/ntcore/Generated/FloatPublisher.cs +++ b/src/ntcore/Generated/FloatPublisher.cs @@ -31,7 +31,7 @@ public interface IFloatPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, float value); + void Set(float value, long time); /** * Publish a default value. diff --git a/src/ntcore/Generated/GenericEntryImpl.cs b/src/ntcore/Generated/GenericEntryImpl.cs index 5dd1e8ce..742608ae 100644 --- a/src/ntcore/Generated/GenericEntryImpl.cs +++ b/src/ntcore/Generated/GenericEntryImpl.cs @@ -4,6 +4,7 @@ // THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY +using System; using NetworkTables.Natives; namespace NetworkTables; @@ -39,12 +40,12 @@ public bool GetBoolean(bool defaultValue) public bool SetBoolean(bool value) { - return SetBoolean(0, value); + return SetBoolean(value, 0); } - public bool SetBoolean(long time, bool value) + public bool SetBoolean(bool value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeBoolean(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeBoolean(value, time)); } /** @@ -86,12 +87,12 @@ public long GetInteger(long defaultValue) public bool SetInteger(long value) { - return SetInteger(0, value); + return SetInteger(value, 0); } - public bool SetInteger(long time, long value) + public bool SetInteger(long value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeInteger(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeInteger(value, time)); } /** @@ -133,12 +134,12 @@ public float GetFloat(float defaultValue) public bool SetFloat(float value) { - return SetFloat(0, value); + return SetFloat(value, 0); } - public bool SetFloat(long time, float value) + public bool SetFloat(float value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeFloat(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeFloat(value, time)); } /** @@ -180,12 +181,12 @@ public double GetDouble(double defaultValue) public bool SetDouble(double value) { - return SetDouble(0, value); + return SetDouble(value, 0); } - public bool SetDouble(long time, double value) + public bool SetDouble(double value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeDouble(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeDouble(value, time)); } /** @@ -227,12 +228,12 @@ public string GetString(string defaultValue) public bool SetString(string value) { - return SetString(0, value); + return SetString(value, 0); } - public bool SetString(long time, string value) + public bool SetString(string value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeString(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeString(value, time)); } /** @@ -274,12 +275,12 @@ public byte[] GetRaw(byte[] defaultValue) public bool SetRaw(byte[] value) { - return SetRaw(0, value); + return SetRaw(value, 0); } - public bool SetRaw(long time, byte[] value) + public bool SetRaw(byte[] value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeRaw(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeRaw(value, time)); } /** @@ -321,12 +322,12 @@ public bool[] GetBooleanArray(bool[] defaultValue) public bool SetBooleanArray(bool[] value) { - return SetBooleanArray(0, value); + return SetBooleanArray(value, 0); } - public bool SetBooleanArray(long time, bool[] value) + public bool SetBooleanArray(bool[] value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeBooleanArray(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeBooleanArray(value, time)); } /** @@ -368,12 +369,12 @@ public long[] GetIntegerArray(long[] defaultValue) public bool SetIntegerArray(long[] value) { - return SetIntegerArray(0, value); + return SetIntegerArray(value, 0); } - public bool SetIntegerArray(long time, long[] value) + public bool SetIntegerArray(long[] value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeIntegerArray(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeIntegerArray(value, time)); } /** @@ -415,12 +416,12 @@ public float[] GetFloatArray(float[] defaultValue) public bool SetFloatArray(float[] value) { - return SetFloatArray(0, value); + return SetFloatArray(value, 0); } - public bool SetFloatArray(long time, float[] value) + public bool SetFloatArray(float[] value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeFloatArray(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeFloatArray(value, time)); } /** @@ -462,12 +463,12 @@ public double[] GetDoubleArray(double[] defaultValue) public bool SetDoubleArray(double[] value) { - return SetDoubleArray(0, value); + return SetDoubleArray(value, 0); } - public bool SetDoubleArray(long time, double[] value) + public bool SetDoubleArray(double[] value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeDoubleArray(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeDoubleArray(value, time)); } /** @@ -509,12 +510,12 @@ public string[] GetStringArray(string[] defaultValue) public bool SetStringArray(string[] value) { - return SetStringArray(0, value); + return SetStringArray(value, 0); } - public bool SetStringArray(long time, string[] value) + public bool SetStringArray(string[] value, long time) { - return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeStringArray(time, value)); + return NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeStringArray(value, time)); } /** diff --git a/src/ntcore/Generated/GenericPublisher.cs b/src/ntcore/Generated/GenericPublisher.cs index 4deb0ab4..ad5813e5 100644 --- a/src/ntcore/Generated/GenericPublisher.cs +++ b/src/ntcore/Generated/GenericPublisher.cs @@ -17,7 +17,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetBoolean(long time, bool value); + bool SetBoolean(bool value, long time); bool SetBoolean(bool value); @@ -36,7 +36,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetInteger(long time, long value); + bool SetInteger(long value, long time); bool SetInteger(long value); @@ -55,7 +55,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetFloat(long time, float value); + bool SetFloat(float value, long time); bool SetFloat(float value); @@ -74,7 +74,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetDouble(long time, double value); + bool SetDouble(double value, long time); bool SetDouble(double value); @@ -93,7 +93,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetString(long time, string value); + bool SetString(string value, long time); bool SetString(string value); @@ -112,7 +112,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetRaw(long time, byte[] value); + bool SetRaw(byte[] value, long time); bool SetRaw(byte[] value); @@ -131,7 +131,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetBooleanArray(long time, bool[] value); + bool SetBooleanArray(bool[] value, long time); bool SetBooleanArray(bool[] value); @@ -150,7 +150,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetIntegerArray(long time, long[] value); + bool SetIntegerArray(long[] value, long time); bool SetIntegerArray(long[] value); @@ -169,7 +169,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetFloatArray(long time, float[] value); + bool SetFloatArray(float[] value, long time); bool SetFloatArray(float[] value); @@ -188,7 +188,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetDoubleArray(long time, double[] value); + bool SetDoubleArray(double[] value, long time); bool SetDoubleArray(double[] value); @@ -207,7 +207,7 @@ public partial interface IGenericPublisher * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ - bool SetStringArray(long time, string[] value); + bool SetStringArray(string[] value, long time); bool SetStringArray(string[] value); diff --git a/src/ntcore/Generated/IntegerArrayEntryImpl.cs b/src/ntcore/Generated/IntegerArrayEntryImpl.cs index 47d545db..1984bbd5 100644 --- a/src/ntcore/Generated/IntegerArrayEntryImpl.cs +++ b/src/ntcore/Generated/IntegerArrayEntryImpl.cs @@ -91,19 +91,19 @@ public long[][] ReadQueueValues() } - public void Set(params long[] value) + public void Set(long[] value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeIntegerArray(0, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeIntegerArray(value.AsSpan(), 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, params long[] value) + public void Set(long[] value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeIntegerArray(time, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeIntegerArray(value.AsSpan(), time); NtCore.SetEntryValue(Handle, ntValue); } - public void SetDefault(params long[] value) + public void SetDefault(long[] value) { RefNetworkTableValue ntValue = RefNetworkTableValue.MakeIntegerArray(value.AsSpan()); NtCore.SetDefaultEntryValue(Handle, ntValue); diff --git a/src/ntcore/Generated/IntegerArrayPublisher.cs b/src/ntcore/Generated/IntegerArrayPublisher.cs index b4a2a559..8b1454ed 100644 --- a/src/ntcore/Generated/IntegerArrayPublisher.cs +++ b/src/ntcore/Generated/IntegerArrayPublisher.cs @@ -31,7 +31,7 @@ public interface IIntegerArrayPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, params long[] value); + void Set(long[] value, long time); /** * Publish a default value. @@ -40,5 +40,5 @@ public interface IIntegerArrayPublisher : IPublisher * * @param value value */ - void SetDefault(params long[] value); + void SetDefault(long[] value); } diff --git a/src/ntcore/Generated/IntegerEntryImpl.cs b/src/ntcore/Generated/IntegerEntryImpl.cs index 12680d60..70a22524 100644 --- a/src/ntcore/Generated/IntegerEntryImpl.cs +++ b/src/ntcore/Generated/IntegerEntryImpl.cs @@ -4,6 +4,7 @@ // THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY +using System; using NetworkTables.Handles; using NetworkTables.Natives; @@ -92,13 +93,13 @@ public long[] ReadQueueValues() public void Set(long value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeInteger(0, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeInteger(value, 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, long value) + public void Set(long value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeInteger(time, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeInteger(value, time); NtCore.SetEntryValue(Handle, ntValue); } diff --git a/src/ntcore/Generated/IntegerPublisher.cs b/src/ntcore/Generated/IntegerPublisher.cs index c72a03cf..e2556ce1 100644 --- a/src/ntcore/Generated/IntegerPublisher.cs +++ b/src/ntcore/Generated/IntegerPublisher.cs @@ -31,7 +31,7 @@ public interface IIntegerPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, long value); + void Set(long value, long time); /** * Publish a default value. diff --git a/src/ntcore/Generated/NetworkTableInstance.cs b/src/ntcore/Generated/NetworkTableInstance.cs index f39a454b..690a6e4e 100644 --- a/src/ntcore/Generated/NetworkTableInstance.cs +++ b/src/ntcore/Generated/NetworkTableInstance.cs @@ -4,6 +4,8 @@ // THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY +using NetworkTables.Handles; + namespace NetworkTables; /** diff --git a/src/ntcore/Generated/NetworkTableValue.cs b/src/ntcore/Generated/NetworkTableValue.cs index 1e609497..56da8430 100644 --- a/src/ntcore/Generated/NetworkTableValue.cs +++ b/src/ntcore/Generated/NetworkTableValue.cs @@ -280,7 +280,7 @@ public static NetworkTableValue MakeBoolean(bool value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeBoolean(long time, bool value) + public static NetworkTableValue MakeBoolean(bool value, long time) { return new NetworkTableValue(NetworkTableType.Boolean, value, time); } @@ -304,7 +304,7 @@ public static NetworkTableValue MakeInteger(long value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeInteger(long time, long value) + public static NetworkTableValue MakeInteger(long value, long time) { return new NetworkTableValue(NetworkTableType.Integer, value, time); } @@ -328,7 +328,7 @@ public static NetworkTableValue MakeFloat(float value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeFloat(long time, float value) + public static NetworkTableValue MakeFloat(float value, long time) { return new NetworkTableValue(NetworkTableType.Float, value, time); } @@ -352,7 +352,7 @@ public static NetworkTableValue MakeDouble(double value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeDouble(long time, double value) + public static NetworkTableValue MakeDouble(double value, long time) { return new NetworkTableValue(NetworkTableType.Double, value, time); } @@ -376,7 +376,7 @@ public static NetworkTableValue MakeString(string value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeString(long time, string value) + public static NetworkTableValue MakeString(string value, long time) { return new NetworkTableValue(NetworkTableType.String, value, time); } @@ -400,7 +400,7 @@ public static NetworkTableValue MakeRaw(params byte[] value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeRaw(long time, params byte[] value) + public static NetworkTableValue MakeRaw(byte[] value, long time) { return new NetworkTableValue(NetworkTableType.Raw, value, time); } @@ -424,7 +424,7 @@ public static NetworkTableValue MakeBooleanArray(params bool[] value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeBooleanArray(long time, params bool[] value) + public static NetworkTableValue MakeBooleanArray(bool[] value, long time) { return new NetworkTableValue(NetworkTableType.BooleanArray, value, time); } @@ -448,7 +448,7 @@ public static NetworkTableValue MakeIntegerArray(params long[] value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeIntegerArray(long time, params long[] value) + public static NetworkTableValue MakeIntegerArray(long[] value, long time) { return new NetworkTableValue(NetworkTableType.IntegerArray, value, time); } @@ -472,7 +472,7 @@ public static NetworkTableValue MakeFloatArray(params float[] value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeFloatArray(long time, params float[] value) + public static NetworkTableValue MakeFloatArray(float[] value, long time) { return new NetworkTableValue(NetworkTableType.FloatArray, value, time); } @@ -496,7 +496,7 @@ public static NetworkTableValue MakeDoubleArray(params double[] value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeDoubleArray(long time, params double[] value) + public static NetworkTableValue MakeDoubleArray(double[] value, long time) { return new NetworkTableValue(NetworkTableType.DoubleArray, value, time); } @@ -520,7 +520,7 @@ public static NetworkTableValue MakeStringArray(params string[] value) * @param time the creation time to use (instead of the current time) * @return The entry value */ - public static NetworkTableValue MakeStringArray(long time, params string[] value) + public static NetworkTableValue MakeStringArray(string[] value, long time) { return new NetworkTableValue(NetworkTableType.StringArray, value, time); } diff --git a/src/ntcore/Generated/RawEntryImpl.cs b/src/ntcore/Generated/RawEntryImpl.cs index 4201b7a9..9b3ff203 100644 --- a/src/ntcore/Generated/RawEntryImpl.cs +++ b/src/ntcore/Generated/RawEntryImpl.cs @@ -91,19 +91,19 @@ public byte[][] ReadQueueValues() } - public void Set(params byte[] value) + public void Set(byte[] value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeRaw(0, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeRaw(value.AsSpan(), 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, params byte[] value) + public void Set(byte[] value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeRaw(time, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeRaw(value.AsSpan(), time); NtCore.SetEntryValue(Handle, ntValue); } - public void SetDefault(params byte[] value) + public void SetDefault(byte[] value) { RefNetworkTableValue ntValue = RefNetworkTableValue.MakeRaw(value.AsSpan()); NtCore.SetDefaultEntryValue(Handle, ntValue); diff --git a/src/ntcore/Generated/RawPublisher.cs b/src/ntcore/Generated/RawPublisher.cs index 334735e9..d5f57b4f 100644 --- a/src/ntcore/Generated/RawPublisher.cs +++ b/src/ntcore/Generated/RawPublisher.cs @@ -31,7 +31,7 @@ public interface IRawPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, params byte[] value); + void Set(byte[] value, long time); /** * Publish a default value. @@ -40,5 +40,5 @@ public interface IRawPublisher : IPublisher * * @param value value */ - void SetDefault(params byte[] value); + void SetDefault(byte[] value); } diff --git a/src/ntcore/Generated/RefNetworkTableValue.cs b/src/ntcore/Generated/RefNetworkTableValue.cs index 404d821c..ffff1369 100644 --- a/src/ntcore/Generated/RefNetworkTableValue.cs +++ b/src/ntcore/Generated/RefNetworkTableValue.cs @@ -31,7 +31,7 @@ public static RefNetworkTableValue MakeBoolean(bool value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeBoolean(long time, bool value) + public static RefNetworkTableValue MakeBoolean(bool value, long time) { return new RefNetworkTableValue(value, time); } @@ -55,7 +55,7 @@ public static RefNetworkTableValue MakeInteger(long value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeInteger(long time, long value) + public static RefNetworkTableValue MakeInteger(long value, long time) { return new RefNetworkTableValue(value, time); } @@ -79,7 +79,7 @@ public static RefNetworkTableValue MakeFloat(float value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeFloat(long time, float value) + public static RefNetworkTableValue MakeFloat(float value, long time) { return new RefNetworkTableValue(value, time); } @@ -103,7 +103,7 @@ public static RefNetworkTableValue MakeDouble(double value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeDouble(long time, double value) + public static RefNetworkTableValue MakeDouble(double value, long time) { return new RefNetworkTableValue(value, time); } @@ -129,7 +129,7 @@ public static RefNetworkTableValue MakeString(string value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeString(long time, string value) + public static RefNetworkTableValue MakeString(string value, long time) { return new RefNetworkTableValue(value, time); } @@ -156,7 +156,7 @@ public static RefNetworkTableValue MakeRaw(ReadOnlySpan value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeRaw(long time, ReadOnlySpan value) + public static RefNetworkTableValue MakeRaw(ReadOnlySpan value, long time) { return new RefNetworkTableValue(value, time); } @@ -183,7 +183,7 @@ public static RefNetworkTableValue MakeBooleanArray(ReadOnlySpan value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeBooleanArray(long time, ReadOnlySpan value) + public static RefNetworkTableValue MakeBooleanArray(ReadOnlySpan value, long time) { return new RefNetworkTableValue(value, time); } @@ -210,7 +210,7 @@ public static RefNetworkTableValue MakeIntegerArray(ReadOnlySpan value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeIntegerArray(long time, ReadOnlySpan value) + public static RefNetworkTableValue MakeIntegerArray(ReadOnlySpan value, long time) { return new RefNetworkTableValue(value, time); } @@ -237,7 +237,7 @@ public static RefNetworkTableValue MakeFloatArray(ReadOnlySpan value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeFloatArray(long time, ReadOnlySpan value) + public static RefNetworkTableValue MakeFloatArray(ReadOnlySpan value, long time) { return new RefNetworkTableValue(value, time); } @@ -264,7 +264,7 @@ public static RefNetworkTableValue MakeDoubleArray(ReadOnlySpan value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeDoubleArray(long time, ReadOnlySpan value) + public static RefNetworkTableValue MakeDoubleArray(ReadOnlySpan value, long time) { return new RefNetworkTableValue(value, time); } @@ -291,7 +291,7 @@ public static RefNetworkTableValue MakeStringArray(ReadOnlySpan value) return new RefNetworkTableValue(value); } - public static RefNetworkTableValue MakeStringArray(long time, ReadOnlySpan value) + public static RefNetworkTableValue MakeStringArray(ReadOnlySpan value, long time) { return new RefNetworkTableValue(value, time); } diff --git a/src/ntcore/Generated/StringArrayEntryImpl.cs b/src/ntcore/Generated/StringArrayEntryImpl.cs index 36a71ebe..aa6e8d06 100644 --- a/src/ntcore/Generated/StringArrayEntryImpl.cs +++ b/src/ntcore/Generated/StringArrayEntryImpl.cs @@ -91,19 +91,19 @@ public string[][] ReadQueueValues() } - public void Set(params string[] value) + public void Set(string[] value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeStringArray(0, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeStringArray(value.AsSpan(), 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, params string[] value) + public void Set(string[] value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeStringArray(time, value.AsSpan()); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeStringArray(value.AsSpan(), time); NtCore.SetEntryValue(Handle, ntValue); } - public void SetDefault(params string[] value) + public void SetDefault(string[] value) { RefNetworkTableValue ntValue = RefNetworkTableValue.MakeStringArray(value.AsSpan()); NtCore.SetDefaultEntryValue(Handle, ntValue); diff --git a/src/ntcore/Generated/StringArrayPublisher.cs b/src/ntcore/Generated/StringArrayPublisher.cs index ed137a58..6506c967 100644 --- a/src/ntcore/Generated/StringArrayPublisher.cs +++ b/src/ntcore/Generated/StringArrayPublisher.cs @@ -31,7 +31,7 @@ public interface IStringArrayPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, params string[] value); + void Set(string[] value, long time); /** * Publish a default value. @@ -40,5 +40,5 @@ public interface IStringArrayPublisher : IPublisher * * @param value value */ - void SetDefault(params string[] value); + void SetDefault(string[] value); } diff --git a/src/ntcore/Generated/StringEntryImpl.cs b/src/ntcore/Generated/StringEntryImpl.cs index a5ccaff2..380d943d 100644 --- a/src/ntcore/Generated/StringEntryImpl.cs +++ b/src/ntcore/Generated/StringEntryImpl.cs @@ -4,6 +4,7 @@ // THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY +using System; using NetworkTables.Handles; using NetworkTables.Natives; @@ -92,13 +93,13 @@ public string[] ReadQueueValues() public void Set(string value) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeString(0, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeString(value, 0); NtCore.SetEntryValue(Handle, ntValue); } - public void Set(long time, string value) + public void Set(string value, long time) { - RefNetworkTableValue ntValue = RefNetworkTableValue.MakeString(time, value); + RefNetworkTableValue ntValue = RefNetworkTableValue.MakeString(value, time); NtCore.SetEntryValue(Handle, ntValue); } diff --git a/src/ntcore/Generated/StringPublisher.cs b/src/ntcore/Generated/StringPublisher.cs index 20af24ab..4e3f74a2 100644 --- a/src/ntcore/Generated/StringPublisher.cs +++ b/src/ntcore/Generated/StringPublisher.cs @@ -31,7 +31,7 @@ public interface IStringPublisher : IPublisher * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used */ - void Set(long time, string value); + void Set(string value, long time); /** * Publish a default value. diff --git a/src/ntcore/GenericEntryImpl.cs b/src/ntcore/GenericEntryImpl.cs index 27079b1a..a14a6569 100644 --- a/src/ntcore/GenericEntryImpl.cs +++ b/src/ntcore/GenericEntryImpl.cs @@ -51,23 +51,23 @@ public bool Set(in RefNetworkTableValue value) public bool SetValue(T value) { - return SetValue(0, value); + return SetValue(value, 0); } - public bool SetValue(long time, T value) + public bool SetValue(T value, long time) { return value switch { NetworkTableValue v => Set(v), - bool v => Set(RefNetworkTableValue.MakeBoolean(time, v)), - double v => Set(RefNetworkTableValue.MakeDouble(time, v)), - float v => Set(RefNetworkTableValue.MakeFloat(time, v)), - string v => Set(RefNetworkTableValue.MakeString(time, v)), - bool[] v => Set(RefNetworkTableValue.MakeBooleanArray(time, v)), - double[] v => Set(RefNetworkTableValue.MakeDoubleArray(time, v)), - float[] v => Set(RefNetworkTableValue.MakeFloatArray(time, v)), - string[] v => Set(RefNetworkTableValue.MakeStringArray(time, v)), - byte[] v => Set(RefNetworkTableValue.MakeRaw(time, v)), + bool v => Set(RefNetworkTableValue.MakeBoolean(v, time)), + double v => Set(RefNetworkTableValue.MakeDouble(v, time)), + float v => Set(RefNetworkTableValue.MakeFloat(v, time)), + string v => Set(RefNetworkTableValue.MakeString(v, time)), + bool[] v => Set(RefNetworkTableValue.MakeBooleanArray(v, time)), + double[] v => Set(RefNetworkTableValue.MakeDoubleArray(v, time)), + float[] v => Set(RefNetworkTableValue.MakeFloatArray(v, time)), + string[] v => Set(RefNetworkTableValue.MakeStringArray(v, time)), + byte[] v => Set(RefNetworkTableValue.MakeRaw(v, time)), _ => throw new InvalidOperationException($"Value of type {value?.GetType().Name} cannot be put into a table") }; } diff --git a/src/ntcore/GenericPublisher.cs b/src/ntcore/GenericPublisher.cs index a09b0936..4bc1411b 100644 --- a/src/ntcore/GenericPublisher.cs +++ b/src/ntcore/GenericPublisher.cs @@ -19,7 +19,7 @@ public partial interface IGenericPublisher : IPublisher * @return False if the topic already exists with a different type * @throws IllegalArgumentException if the value is not a known type */ - bool SetValue(long time, T value); + bool SetValue(T value, long time); bool SetValue(T value); diff --git a/src/ntcore/NetworkTableInstance.cs b/src/ntcore/NetworkTableInstance.cs index ef63d11e..e6fe27d1 100644 --- a/src/ntcore/NetworkTableInstance.cs +++ b/src/ntcore/NetworkTableInstance.cs @@ -15,6 +15,7 @@ using WPIUtil.Logging; using WPIUtil.Natives; using WPIUtil.Serialization.Protobuf; +using WPIUtil.Serialization.Struct; namespace NetworkTables; @@ -487,6 +488,11 @@ public override int GetHashCode() return !(left == right); } + public void AddSchema(IStructBase proto) + { + throw new NotImplementedException(); + } + public void AddSchema(IProtobufBase proto) { throw new NotImplementedException(); diff --git a/src/ntcore/NetworkTableValue.cs b/src/ntcore/NetworkTableValue.cs index e3f7098d..14ba77d0 100644 --- a/src/ntcore/NetworkTableValue.cs +++ b/src/ntcore/NetworkTableValue.cs @@ -191,17 +191,17 @@ public static implicit operator RefNetworkTableValue(in NetworkTableValue value) { return value.Type switch { - NetworkTableType.Boolean => RefNetworkTableValue.MakeBoolean(value.Time, value.m_structValue.boolValue), - NetworkTableType.Double => RefNetworkTableValue.MakeDouble(value.Time, value.m_structValue.doubleValue), - NetworkTableType.String => RefNetworkTableValue.MakeString(value.Time, (string)value.m_objectValue!), - NetworkTableType.Raw => RefNetworkTableValue.MakeRaw(value.Time, (byte[])value.m_objectValue!), - NetworkTableType.BooleanArray => RefNetworkTableValue.MakeBooleanArray(value.Time, (bool[])value.m_objectValue!), - NetworkTableType.DoubleArray => RefNetworkTableValue.MakeDoubleArray(value.Time, (double[])value.m_objectValue!), - NetworkTableType.StringArray => RefNetworkTableValue.MakeStringArray(value.Time, (string[])value.m_objectValue!), - NetworkTableType.Integer => RefNetworkTableValue.MakeInteger(value.Time, value.m_structValue.longValue), - NetworkTableType.Float => RefNetworkTableValue.MakeFloat(value.Time, value.m_structValue.floatValue), - NetworkTableType.IntegerArray => RefNetworkTableValue.MakeIntegerArray(value.Time, (long[])value.m_objectValue!), - NetworkTableType.FloatArray => RefNetworkTableValue.MakeFloatArray(value.Time, (float[])value.m_objectValue!), + NetworkTableType.Boolean => RefNetworkTableValue.MakeBoolean(value.m_structValue.boolValue, value.Time), + NetworkTableType.Double => RefNetworkTableValue.MakeDouble(value.m_structValue.doubleValue, value.Time), + NetworkTableType.String => RefNetworkTableValue.MakeString((string)value.m_objectValue!, value.Time), + NetworkTableType.Raw => RefNetworkTableValue.MakeRaw((byte[])value.m_objectValue!, value.Time), + NetworkTableType.BooleanArray => RefNetworkTableValue.MakeBooleanArray((bool[])value.m_objectValue!, value.Time), + NetworkTableType.DoubleArray => RefNetworkTableValue.MakeDoubleArray((double[])value.m_objectValue!, value.Time), + NetworkTableType.StringArray => RefNetworkTableValue.MakeStringArray((string[])value.m_objectValue!, value.Time), + NetworkTableType.Integer => RefNetworkTableValue.MakeInteger(value.m_structValue.longValue, value.Time), + NetworkTableType.Float => RefNetworkTableValue.MakeFloat(value.m_structValue.floatValue, value.Time), + NetworkTableType.IntegerArray => RefNetworkTableValue.MakeIntegerArray((long[])value.m_objectValue!, value.Time), + NetworkTableType.FloatArray => RefNetworkTableValue.MakeFloatArray((float[])value.m_objectValue!, value.Time), _ => RefNetworkTableValue.MakeUnassigned(value.Time), }; } diff --git a/src/ntcore/ProtobufEntryImpl.cs b/src/ntcore/ProtobufEntryImpl.cs index 71f5fdd6..7e194c00 100644 --- a/src/ntcore/ProtobufEntryImpl.cs +++ b/src/ntcore/ProtobufEntryImpl.cs @@ -71,6 +71,7 @@ public TimestampedObject GetAtomic(T defaultValue) public TimestampedObject[] ReadQueue() { + throw new System.NotImplementedException(); } @@ -81,12 +82,27 @@ public T[] ReadQueueValues() public void Set(T value) { - throw new System.NotImplementedException(); + Set(value, 0); } - public void Set(long time, T value) + public void Set(T value, long time) { - throw new System.NotImplementedException(); + try + { + lock (m_lockObject) + { + if (!m_schemaPublished) + { + m_schemaPublished = true; + Topic.Instance.AddSchema(m_buf.Proto); + } + NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeRaw(m_buf.Write(value), time)); + } + } + catch + { + + } } public void SetDefault(T value) @@ -100,8 +116,7 @@ public void SetDefault(T value) m_schemaPublished = true; Topic.Instance.AddSchema(m_buf.Proto); } - ReadOnlySpan buf = m_buf.Write(value); - NtCore.SetDefaultEntryValue(Handle, RefNetworkTableValue.MakeRaw(buf)); + NtCore.SetDefaultEntryValue(Handle, RefNetworkTableValue.MakeRaw(m_buf.Write(value))); } } catch @@ -139,6 +154,4 @@ private TimestampedObject FromRaw(T defaultValue) return new TimestampedObject(0, 0, defaultValue); } } - - private static readonly byte[] m_emptyRaw = Array.Empty(); } diff --git a/src/ntcore/ProtobufPublisher.cs b/src/ntcore/ProtobufPublisher.cs index 09c90590..54b3ca71 100644 --- a/src/ntcore/ProtobufPublisher.cs +++ b/src/ntcore/ProtobufPublisher.cs @@ -8,7 +8,7 @@ public interface IProtobufPublisher : IPublisher where T : IProtobufSerializa void Set(T value); - void Set(long time, T value); + void Set(T value, long time); void SetDefault(T value); } diff --git a/src/ntcore/StructArrayEntry.cs b/src/ntcore/StructArrayEntry.cs new file mode 100644 index 00000000..69cd43df --- /dev/null +++ b/src/ntcore/StructArrayEntry.cs @@ -0,0 +1,8 @@ +using WPIUtil.Serialization.Struct; + +namespace NetworkTables; + +public interface IStructArrayEntry : IStructArraySubscriber, IStructArrayPublisher where T : IStructSerializable +{ + void Unpublish(); +} diff --git a/src/ntcore/StructArrayEntryImpl.cs b/src/ntcore/StructArrayEntryImpl.cs new file mode 100644 index 00000000..8c33e1fb --- /dev/null +++ b/src/ntcore/StructArrayEntryImpl.cs @@ -0,0 +1,159 @@ +using System; +using NetworkTables.Handles; +using NetworkTables.Natives; +using WPIUtil.Serialization.Struct; + +namespace NetworkTables; + +internal sealed class StructArrayEntryImpl : EntryBase, IStructArrayEntry where THandle : struct, INtEntryHandle where T : IStructSerializable +{ + internal StructArrayEntryImpl(StructArrayTopic topic, THandle handle, T[] defaultValue, bool schemaPublished) : base(handle) + { + Topic = topic; + m_defaultValue = defaultValue; + m_buf = new StructBuffer(); + m_schemaPublished = schemaPublished; + } + + private readonly T[] m_defaultValue; + private readonly StructBuffer m_buf; + private bool m_schemaPublished; + private readonly object m_lockObject = new(); + + public override StructArrayTopic Topic { get; } + + public T[] Get() + { + return FromRaw(m_defaultValue).Value; + } + + public T[] Get(T[] defaultValue) + { + return FromRaw(defaultValue).Value; + } + + public ReadOnlySpan GetInto(Span output, out bool copiedAll) + { + NetworkTableValue value = NtCore.GetEntryValue(Handle); + if (!value.IsRaw) + { + copiedAll = false; + return new(); + } + byte[] raw = value.GetRaw(); + if (raw.Length == 0) + { + copiedAll = false; + return new(); + } + try + { + lock (m_lockObject) + { + return m_buf.ReadInto(output, raw, out copiedAll); + } + } + catch (Exception) + { + + } + copiedAll = false; + return new(); + } + + public TimestampedObject GetAtomic() + { + return FromRaw(m_defaultValue); + } + + public TimestampedObject GetAtomic(T[] defaultValue) + { + return FromRaw(defaultValue); + } + + public TimestampedObject[] ReadQueue() + { + + throw new System.NotImplementedException(); + } + + public T[][] ReadQueueValues() + { + throw new System.NotImplementedException(); + } + + public void Set(ReadOnlySpan value) + { + Set(value, 0); + } + + public void Set(ReadOnlySpan value, long time) + { + try + { + lock (m_lockObject) + { + if (!m_schemaPublished) + { + m_schemaPublished = true; + Topic.Instance.AddSchema(m_buf.Struct); + } + NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeRaw(m_buf.WriteArray(value), time)); + } + } + catch + { + + } + } + + public void SetDefault(ReadOnlySpan value) + { + try + { + lock (m_lockObject) + { + if (!m_schemaPublished) + { + m_schemaPublished = true; + Topic.Instance.AddSchema(m_buf.Struct); + } + NtCore.SetDefaultEntryValue(Handle, RefNetworkTableValue.MakeRaw(m_buf.WriteArray(value))); + } + } + catch + { + + } + } + + public void Unpublish() + { + NtCore.Unpublish(Handle); + } + + private TimestampedObject FromRaw(T[] defaultValue) + { + NetworkTableValue value = NtCore.GetEntryValue(Handle); + if (!value.IsRaw) + { + return new TimestampedObject(value.Time, value.ServerTime, defaultValue); + } + byte[] raw = value.GetRaw(); + if (raw.Length == 0) + { + return new TimestampedObject(value.Time, value.ServerTime, defaultValue); + } + try + { + lock (m_lockObject) + { + return new TimestampedObject(value.Time, value.ServerTime, m_buf.ReadArray(raw)); + } + } + catch + { + return new TimestampedObject(0, 0, defaultValue); + } + } +} diff --git a/src/ntcore/StructArrayPublisher.cs b/src/ntcore/StructArrayPublisher.cs new file mode 100644 index 00000000..790caee3 --- /dev/null +++ b/src/ntcore/StructArrayPublisher.cs @@ -0,0 +1,15 @@ +using System; +using WPIUtil.Serialization.Struct; + +namespace NetworkTables; + +public interface IStructArrayPublisher : IPublisher where T : IStructSerializable +{ + new StructArrayTopic Topic { get; } + + void Set(ReadOnlySpan value); + + void Set(ReadOnlySpan value, long time); + + void SetDefault(ReadOnlySpan value); +} diff --git a/src/ntcore/StructArraySubscriber.cs b/src/ntcore/StructArraySubscriber.cs new file mode 100644 index 00000000..ea321ea8 --- /dev/null +++ b/src/ntcore/StructArraySubscriber.cs @@ -0,0 +1,23 @@ +using System; +using WPIUtil.Serialization.Struct; + +namespace NetworkTables; + +public interface IStructArraySubscriber : ISubscriber where T : IStructSerializable +{ + new StructArrayTopic Topic { get; } + + T[] Get(); + + T[] Get(T[] defaultValue); + + ReadOnlySpan GetInto(Span output, out bool copiedAll); + + TimestampedObject GetAtomic(); + + TimestampedObject GetAtomic(T[] defaultValue); + + TimestampedObject[] ReadQueue(); + + T[][] ReadQueueValues(); +} diff --git a/src/ntcore/StructArrayTopic.cs b/src/ntcore/StructArrayTopic.cs index 4a8dd486..1efb62fb 100644 --- a/src/ntcore/StructArrayTopic.cs +++ b/src/ntcore/StructArrayTopic.cs @@ -1,29 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Numerics; using NetworkTables.Handles; +using NetworkTables.Natives; using WPIUtil.Serialization.Struct; namespace NetworkTables; -public sealed class StructArrayTopic : Topic +public sealed class StructArrayTopic : Topic, IEquatable?>, IEqualityOperators?, StructArrayTopic?, bool> where T : IStructSerializable { - public IStruct Struct { get; } + public IStruct Proto { get; } = T.Struct; - private StructArrayTopic(Topic topic, IStruct value) : base(topic.Instance, topic.Handle) + private StructArrayTopic(Topic topic) : base(topic.Instance, topic.Handle) { - Struct = value; } - private StructArrayTopic(NetworkTableInstance inst, NtTopic handle, IStruct value) : base(inst, handle) + private StructArrayTopic(NetworkTableInstance inst, NtTopic handle) : base(inst, handle) { - Struct = value; } - public static StructArrayTopic Wrap(Topic topic, IStruct value) + public static StructArrayTopic Wrap(Topic topic) { - return new StructArrayTopic(topic, value); + return new StructArrayTopic(topic); } - public static StructArrayTopic Wrap(NetworkTableInstance inst, NtTopic handle, IStruct value) + public static StructArrayTopic Wrap(NetworkTableInstance instance, NtTopic handle) { - return new StructArrayTopic(inst, handle, value); + return new StructArrayTopic(instance, handle); + } + + public IStructArraySubscriber Subscribe(T[] defaultValue, PubSubOptions options) + { + return new StructArrayEntryImpl(this, NtCore.Subscribe(Handle, NetworkTableType.Raw, Proto.TypeString, options), defaultValue, false); + } + + public IStructArrayPublisher Publish(PubSubOptions options) + { + return new StructArrayEntryImpl(this, NtCore.Publish(Handle, NetworkTableType.Raw, Proto.TypeString, options), default!, false); + } + + public IStructArrayPublisher PublishEx(string properties, PubSubOptions options) + { + return new StructArrayEntryImpl(this, NtCore.PublishEx(Handle, NetworkTableType.Raw, Proto.TypeString, properties, options), default!, false); + } + + public IStructArrayEntry GetEntry(T[] defaultValue, PubSubOptions options) + { + return new StructArrayEntryImpl(this, NtCore.GetEntry(Handle, NetworkTableType.Raw, Proto.TypeString, options), defaultValue, false); + } + + public override bool Equals(object? obj) + { + return Equals(obj as StructArrayTopic); + } + + public bool Equals(StructArrayTopic? other) + { + return other is not null && + EqualityComparer>.Default.Equals(Proto, other.Proto); + } + + public override int GetHashCode() + { + return HashCode.Combine(base.GetHashCode(), Proto); + } + + public static bool operator ==(StructArrayTopic? left, StructArrayTopic? right) + { + return EqualityComparer>.Default.Equals(left, right); + } + + public static bool operator !=(StructArrayTopic? left, StructArrayTopic? right) + { + return !(left == right); } } diff --git a/src/ntcore/StructEntry.cs b/src/ntcore/StructEntry.cs new file mode 100644 index 00000000..4f753e80 --- /dev/null +++ b/src/ntcore/StructEntry.cs @@ -0,0 +1,8 @@ +using WPIUtil.Serialization.Struct; + +namespace NetworkTables; + +public interface IStructEntry : IStructSubscriber, IStructPublisher where T : IStructSerializable +{ + void Unpublish(); +} diff --git a/src/ntcore/StructEntryImpl.cs b/src/ntcore/StructEntryImpl.cs new file mode 100644 index 00000000..07c456a9 --- /dev/null +++ b/src/ntcore/StructEntryImpl.cs @@ -0,0 +1,157 @@ +using System; +using NetworkTables.Handles; +using NetworkTables.Natives; +using WPIUtil.Serialization.Struct; + +namespace NetworkTables; + +internal sealed class StructEntryImpl : EntryBase, IStructEntry where THandle : struct, INtEntryHandle where T : IStructSerializable +{ + internal StructEntryImpl(StructTopic topic, THandle handle, T defaultValue, bool schemaPublished) : base(handle) + { + Topic = topic; + m_defaultValue = defaultValue; + m_buf = new StructBuffer(); + m_schemaPublished = schemaPublished; + } + + private readonly T m_defaultValue; + private readonly StructBuffer m_buf; + private bool m_schemaPublished; + private readonly object m_lockObject = new(); + + public override StructTopic Topic { get; } + + public T Get() + { + return FromRaw(m_defaultValue).Value; + } + + public T Get(T defaultValue) + { + return FromRaw(defaultValue).Value; + } + + public bool GetInto(ref T output) + { + NetworkTableValue value = NtCore.GetEntryValue(Handle); + if (!value.IsRaw) + { + return false; + } + byte[] raw = value.GetRaw(); + if (raw.Length == 0) + { + return false; + } + try + { + lock (m_lockObject) + { + m_buf.ReadInto(ref output, raw); + return true; + } + } + catch (Exception) + { + + } + return false; + } + + public TimestampedObject GetAtomic() + { + return FromRaw(m_defaultValue); + } + + public TimestampedObject GetAtomic(T defaultValue) + { + return FromRaw(defaultValue); + } + + public TimestampedObject[] ReadQueue() + { + + throw new System.NotImplementedException(); + } + + public T[] ReadQueueValues() + { + throw new System.NotImplementedException(); + } + + public void Set(T value) + { + Set(value, 0); + } + + public void Set(T value, long time) + { + try + { + lock (m_lockObject) + { + if (!m_schemaPublished) + { + m_schemaPublished = true; + Topic.Instance.AddSchema(m_buf.Struct); + } + NtCore.SetEntryValue(Handle, RefNetworkTableValue.MakeRaw(m_buf.Write(value), time)); + } + } + catch + { + + } + } + + public void SetDefault(T value) + { + try + { + lock (m_lockObject) + { + if (!m_schemaPublished) + { + m_schemaPublished = true; + Topic.Instance.AddSchema(m_buf.Struct); + } + NtCore.SetDefaultEntryValue(Handle, RefNetworkTableValue.MakeRaw(m_buf.Write(value))); + } + } + catch + { + + } + } + + public void Unpublish() + { + NtCore.Unpublish(Handle); + } + + private TimestampedObject FromRaw(T defaultValue) + { + NetworkTableValue value = NtCore.GetEntryValue(Handle); + if (!value.IsRaw) + { + return new TimestampedObject(value.Time, value.ServerTime, defaultValue); + } + byte[] raw = value.GetRaw(); + if (raw.Length == 0) + { + return new TimestampedObject(value.Time, value.ServerTime, defaultValue); + } + try + { + lock (m_lockObject) + { + return new TimestampedObject(value.Time, value.ServerTime, m_buf.Read(raw)); + } + } + catch + { + return new TimestampedObject(0, 0, defaultValue); + } + } +} diff --git a/src/ntcore/StructPublisher.cs b/src/ntcore/StructPublisher.cs new file mode 100644 index 00000000..8e781e61 --- /dev/null +++ b/src/ntcore/StructPublisher.cs @@ -0,0 +1,14 @@ +using WPIUtil.Serialization.Struct; + +namespace NetworkTables; + +public interface IStructPublisher : IPublisher where T : IStructSerializable +{ + new StructTopic Topic { get; } + + void Set(T value); + + void Set(T value, long time); + + void SetDefault(T value); +} diff --git a/src/ntcore/StructSubscriber.cs b/src/ntcore/StructSubscriber.cs new file mode 100644 index 00000000..4214889a --- /dev/null +++ b/src/ntcore/StructSubscriber.cs @@ -0,0 +1,22 @@ +using WPIUtil.Serialization.Struct; + +namespace NetworkTables; + +public interface IStructSubscriber : ISubscriber where T : IStructSerializable +{ + new StructTopic Topic { get; } + + T Get(); + + T Get(T defaultValue); + + bool GetInto(ref T output); + + TimestampedObject GetAtomic(); + + TimestampedObject GetAtomic(T defaultValue); + + TimestampedObject[] ReadQueue(); + + T[] ReadQueueValues(); +} diff --git a/src/ntcore/StructTopic.cs b/src/ntcore/StructTopic.cs new file mode 100644 index 00000000..395fff40 --- /dev/null +++ b/src/ntcore/StructTopic.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using NetworkTables.Handles; +using NetworkTables.Natives; +using WPIUtil.Serialization.Struct; + +namespace NetworkTables; + +public sealed class StructTopic : Topic, IEquatable?>, IEqualityOperators?, StructTopic?, bool> where T : IStructSerializable +{ + public IStruct Proto { get; } = T.Struct; + + private StructTopic(Topic topic) : base(topic.Instance, topic.Handle) + { + } + + private StructTopic(NetworkTableInstance inst, NtTopic handle) : base(inst, handle) + { + } + + public static StructTopic Wrap(Topic topic) + { + return new StructTopic(topic); + } + + public static StructTopic Wrap(NetworkTableInstance instance, NtTopic handle) + { + return new StructTopic(instance, handle); + } + + public IStructSubscriber Subscribe(T defaultValue, PubSubOptions options) + { + return new StructEntryImpl(this, NtCore.Subscribe(Handle, NetworkTableType.Raw, Proto.TypeString, options), defaultValue, false); + } + + public IStructPublisher Publish(PubSubOptions options) + { + return new StructEntryImpl(this, NtCore.Publish(Handle, NetworkTableType.Raw, Proto.TypeString, options), default!, false); + } + + public IStructPublisher PublishEx(string properties, PubSubOptions options) + { + return new StructEntryImpl(this, NtCore.PublishEx(Handle, NetworkTableType.Raw, Proto.TypeString, properties, options), default!, false); + } + + public IStructEntry GetEntry(T defaultValue, PubSubOptions options) + { + return new StructEntryImpl(this, NtCore.GetEntry(Handle, NetworkTableType.Raw, Proto.TypeString, options), defaultValue, false); + } + + public override bool Equals(object? obj) + { + return Equals(obj as StructTopic); + } + + public bool Equals(StructTopic? other) + { + return other is not null && + EqualityComparer>.Default.Equals(Proto, other.Proto); + } + + public override int GetHashCode() + { + return HashCode.Combine(base.GetHashCode(), Proto); + } + + public static bool operator ==(StructTopic? left, StructTopic? right) + { + return EqualityComparer>.Default.Equals(left, right); + } + + public static bool operator !=(StructTopic? left, StructTopic? right) + { + return !(left == right); + } +} diff --git a/src/wpiutil/Serialization/Struct/StructBuffer.cs b/src/wpiutil/Serialization/Struct/StructBuffer.cs index cd28bb7a..9878cd8d 100644 --- a/src/wpiutil/Serialization/Struct/StructBuffer.cs +++ b/src/wpiutil/Serialization/Struct/StructBuffer.cs @@ -44,6 +44,23 @@ public readonly void ReadInto(ref T output, ReadOnlySpan buffer) Struct.UnpackInto(ref output, ref unpacker); } + public readonly ReadOnlySpan ReadInto(Span output, ReadOnlySpan buffer, out bool copiedAll) + { + if ((buffer.Length % m_structSize) != 0) + { + throw new Exception("Buffer size not a multiple of struct size"); + } + int nelem = buffer.Length / m_structSize; + int length = int.Min(nelem, output.Length); + copiedAll = length == nelem; + StructUnpacker unpacker = new(buffer); + for (int i = 0; i < length; i++) + { + Struct.UnpackInto(ref output[0], ref unpacker); + } + return output[..length]; + } + public ReadOnlySpan WriteArray(ReadOnlySpan values) { if ((values.Length * m_structSize) > m_buf.Length)