// Autogenerated C# message buffer code. // Source: clad/externalInterface/messageCubeToEngine.clad // Full command line: victor-clad/tools/message-buffers/emitters/CSharp_emitter.py -C src -I clad/src lib/util/source/anki/clad robot/clad/src coretech/vision/clad_src coretech/common/clad_src -o generated/cladCSharp clad/externalInterface/messageCubeToEngine.clad namespace Anki { namespace Vector { public partial class RawCubeAccel { private short[] _accel; // int_16[3] public short[] accel { get { return _accel; } set { if (value == null) { throw new System.ArgumentException("accel fixed-length array is null. Must have a length of 3.", "value"); } if (value.Length != 3) { throw new System.ArgumentException("accel fixed-length array is the wrong size. Must have a length of 3.", "value"); } _accel = value; } } /**** Constructors ****/ public RawCubeAccel() { this.accel = new short[3]; } public RawCubeAccel(short[] accel) { this.accel = accel; } public RawCubeAccel(System.IO.Stream stream) { Unpack(stream); } public RawCubeAccel(System.IO.BinaryReader reader) { Unpack(reader); } public RawCubeAccel Initialize(short[] accel) { this.accel = accel; return this; } public void Unpack(System.IO.Stream stream) { System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); Unpack(reader); } public void Unpack(System.IO.BinaryReader reader) { _accel = new short[3]; for (int i = 0; i < 3; ++i) { _accel[i] = reader.ReadInt16(); } } public void Pack(System.IO.Stream stream) { System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream); Pack(writer); } public void Pack(System.IO.BinaryWriter writer) { for (int i = 0; i < 3; ++i) { writer.Write((short)_accel[i]); } } public int Size { get { return 6; } } public static bool ArrayEquals(System.Collections.Generic.IList a1, System.Collections.Generic.IList a2) { if (System.Object.ReferenceEquals(a1, a2)) return true; if (System.Object.ReferenceEquals(a1, null) || System.Object.ReferenceEquals(a2, null)) return false; if (a1.Count != a2.Count) return false; for (int i = 0; i < a1.Count; i++) { if (!a1[i].Equals(a2[i])) { return false; } } return true; } public static bool operator ==(RawCubeAccel a, RawCubeAccel b) { if (System.Object.ReferenceEquals(a, null)) { return System.Object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(RawCubeAccel a, RawCubeAccel b) { return !(a == b); } public override bool Equals(System.Object obj) { return this.Equals(obj as RawCubeAccel); } public bool Equals(RawCubeAccel p) { if (System.Object.ReferenceEquals(p, null)) { return false; } return ArrayEquals(this._accel,p._accel); } public override int GetHashCode() { unchecked { int hash = 17; return hash; } } } public partial class CubeAccelData { private byte _tap_count = 0; // uint_8 private Anki.Vector.RawCubeAccel[] _accelReadings; // RawCubeAccel[3] public byte tap_count { get { return _tap_count; } set { _tap_count = value; } } public Anki.Vector.RawCubeAccel[] accelReadings { get { return _accelReadings; } set { if (value == null) { throw new System.ArgumentException("accelReadings fixed-length array is null. Must have a length of 3.", "value"); } if (value.Length != 3) { throw new System.ArgumentException("accelReadings fixed-length array is the wrong size. Must have a length of 3.", "value"); } _accelReadings = value; } } /**** Constructors ****/ public CubeAccelData() { this.accelReadings = new Anki.Vector.RawCubeAccel[3]; } public CubeAccelData(byte tap_count, Anki.Vector.RawCubeAccel[] accelReadings) { this.tap_count = tap_count; this.accelReadings = accelReadings; } public CubeAccelData(System.IO.Stream stream) { Unpack(stream); } public CubeAccelData(System.IO.BinaryReader reader) { Unpack(reader); } public CubeAccelData Initialize(byte tap_count, Anki.Vector.RawCubeAccel[] accelReadings) { this.tap_count = tap_count; this.accelReadings = accelReadings; return this; } public void Unpack(System.IO.Stream stream) { System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); Unpack(reader); } public void Unpack(System.IO.BinaryReader reader) { _tap_count = reader.ReadByte(); _accelReadings = new Anki.Vector.RawCubeAccel[3]; for (int i = 0; i < 3; ++i) { _accelReadings[i] = new Anki.Vector.RawCubeAccel(reader); } } public void Pack(System.IO.Stream stream) { System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream); Pack(writer); } public void Pack(System.IO.BinaryWriter writer) { writer.Write((byte)_tap_count); for (int i = 0; i < 3; ++i) { if (_accelReadings[i] == null) { throw new System.InvalidOperationException("Arrays in messages may not have null entries."); } _accelReadings[i].Pack(writer); } } public int Size { get { return 19; } } public static bool ArrayEquals(System.Collections.Generic.IList a1, System.Collections.Generic.IList a2) { if (System.Object.ReferenceEquals(a1, a2)) return true; if (System.Object.ReferenceEquals(a1, null) || System.Object.ReferenceEquals(a2, null)) return false; if (a1.Count != a2.Count) return false; for (int i = 0; i < a1.Count; i++) { if (!a1[i].Equals(a2[i])) { return false; } } return true; } public static bool operator ==(CubeAccelData a, CubeAccelData b) { if (System.Object.ReferenceEquals(a, null)) { return System.Object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(CubeAccelData a, CubeAccelData b) { return !(a == b); } public override bool Equals(System.Object obj) { return this.Equals(obj as CubeAccelData); } public bool Equals(CubeAccelData p) { if (System.Object.ReferenceEquals(p, null)) { return false; } return this._tap_count.Equals(p._tap_count) && ArrayEquals(this._accelReadings,p._accelReadings); } public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + this._tap_count.GetHashCode(); return hash; } } } public partial class CubeVoltageData { private byte _unused = 0; // uint_8 private ushort _railVoltageCnts; // uint_16 public byte unused { get { return _unused; } set { _unused = value; } } public ushort railVoltageCnts { get { return _railVoltageCnts; } set { _railVoltageCnts = value; } } /**** Constructors ****/ public CubeVoltageData() { } public CubeVoltageData(byte unused, ushort railVoltageCnts) { this.unused = unused; this.railVoltageCnts = railVoltageCnts; } public CubeVoltageData(System.IO.Stream stream) { Unpack(stream); } public CubeVoltageData(System.IO.BinaryReader reader) { Unpack(reader); } public CubeVoltageData Initialize(byte unused, ushort railVoltageCnts) { this.unused = unused; this.railVoltageCnts = railVoltageCnts; return this; } public void Unpack(System.IO.Stream stream) { System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); Unpack(reader); } public void Unpack(System.IO.BinaryReader reader) { _unused = reader.ReadByte(); _railVoltageCnts = reader.ReadUInt16(); } public void Pack(System.IO.Stream stream) { System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream); Pack(writer); } public void Pack(System.IO.BinaryWriter writer) { writer.Write((byte)_unused); writer.Write((ushort)_railVoltageCnts); } public int Size { get { return 3; } } public static bool ArrayEquals(System.Collections.Generic.IList a1, System.Collections.Generic.IList a2) { if (System.Object.ReferenceEquals(a1, a2)) return true; if (System.Object.ReferenceEquals(a1, null) || System.Object.ReferenceEquals(a2, null)) return false; if (a1.Count != a2.Count) return false; for (int i = 0; i < a1.Count; i++) { if (!a1[i].Equals(a2[i])) { return false; } } return true; } public static bool operator ==(CubeVoltageData a, CubeVoltageData b) { if (System.Object.ReferenceEquals(a, null)) { return System.Object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(CubeVoltageData a, CubeVoltageData b) { return !(a == b); } public override bool Equals(System.Object obj) { return this.Equals(obj as CubeVoltageData); } public bool Equals(CubeVoltageData p) { if (System.Object.ReferenceEquals(p, null)) { return false; } return this._unused.Equals(p._unused) && this._railVoltageCnts.Equals(p._railVoltageCnts); } public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + this._unused.GetHashCode(); hash = hash * 23 + this._railVoltageCnts.GetHashCode(); return hash; } } } public class MessageCubeToEngine { public enum Tag { accelData = 2, // 2 voltageData = 4, // 4 available = 5, // 5 INVALID = 255 }; private Tag _tag = Tag.INVALID; public Tag GetTag() { return _tag; } private object _state = null; public object GetState() { return _state; } public Anki.Vector.CubeAccelData accelData { get { if (_tag != Tag.accelData) { throw new System.InvalidOperationException(string.Format( "Cannot access union member \"accelData\" when a value of type {0} is stored.", _tag.ToString())); } return (Anki.Vector.CubeAccelData)this._state; } set { _tag = (value != null) ? Tag.accelData : Tag.INVALID; _state = value; } } public Anki.Vector.CubeVoltageData voltageData { get { if (_tag != Tag.voltageData) { throw new System.InvalidOperationException(string.Format( "Cannot access union member \"voltageData\" when a value of type {0} is stored.", _tag.ToString())); } return (Anki.Vector.CubeVoltageData)this._state; } set { _tag = (value != null) ? Tag.voltageData : Tag.INVALID; _state = value; } } public Anki.Vector.ExternalInterface.ObjectAvailable available { get { if (_tag != Tag.available) { throw new System.InvalidOperationException(string.Format( "Cannot access union member \"available\" when a value of type {0} is stored.", _tag.ToString())); } return (Anki.Vector.ExternalInterface.ObjectAvailable)this._state; } set { _tag = (value != null) ? Tag.available : Tag.INVALID; _state = value; } } public MessageCubeToEngine Initialize(T state) { _state = state; if(typeof(T) == typeof(Anki.Vector.CubeAccelData)) { _tag = Tag.accelData; } else if(typeof(T) == typeof(Anki.Vector.CubeVoltageData)) { _tag = Tag.voltageData; } else if(typeof(T) == typeof(Anki.Vector.ExternalInterface.ObjectAvailable)) { _tag = Tag.available; } else { _state = null; _tag = Tag.INVALID; } return this; } /**** Constructors ****/ public MessageCubeToEngine() { } public MessageCubeToEngine(System.IO.Stream stream) { Unpack(stream); } public MessageCubeToEngine(System.IO.BinaryReader reader) { Unpack(reader); } public void Unpack(System.IO.Stream stream) { System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); Unpack(reader); } public void Unpack(System.IO.BinaryReader reader) { Tag newTag = (Tag)reader.ReadByte(); switch(newTag) { case Tag.accelData: accelData = new Anki.Vector.CubeAccelData(reader); break; case Tag.voltageData: voltageData = new Anki.Vector.CubeVoltageData(reader); break; case Tag.available: available = new Anki.Vector.ExternalInterface.ObjectAvailable(reader); break; default: break; } _tag = newTag; } public void Pack(System.IO.Stream stream) { System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream); Pack(writer); } public void Pack(System.IO.BinaryWriter writer) { writer.Write((byte)GetTag()); switch(GetTag()) { case Tag.accelData: if (accelData == null) { throw new System.InvalidOperationException("Arrays in messages may not have null entries."); } accelData.Pack(writer); break; case Tag.voltageData: if (voltageData == null) { throw new System.InvalidOperationException("Arrays in messages may not have null entries."); } voltageData.Pack(writer); break; case Tag.available: if (available == null) { throw new System.InvalidOperationException("Arrays in messages may not have null entries."); } available.Pack(writer); break; default: break; } } public int Size { get { int result = 1; // tag = byte switch(GetTag()) { case Tag.accelData: if (accelData == null) { throw new System.InvalidOperationException("Messages may not have null members."); } result += accelData.Size; break; case Tag.voltageData: if (voltageData == null) { throw new System.InvalidOperationException("Messages may not have null members."); } result += voltageData.Size; break; case Tag.available: if (available == null) { throw new System.InvalidOperationException("Messages may not have null members."); } result += available.Size; break; default: // Just tag size break; } return result; } } public static bool operator ==(MessageCubeToEngine a, MessageCubeToEngine b) { if (System.Object.ReferenceEquals(a, null)) { return System.Object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(MessageCubeToEngine a, MessageCubeToEngine b) { return !(a == b); } public override bool Equals(System.Object obj) { return this.Equals(obj as MessageCubeToEngine); } public bool Equals(MessageCubeToEngine p) { if (System.Object.ReferenceEquals(p, null)) { return false; } return (_tag == p._tag && _state.Equals(p._state)); } public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + this._tag.GetHashCode(); hash = hash * 23 + this._state.GetHashCode(); return hash; } } } } // namespace Vector } // namespace Anki