public void Reset() { Interlocked.Exchange(ref lengt, -1); Interlocked.Exchange(ref Vlent, 0); Interlocked.Exchange(ref current, 0); ByteList.Clear(); }
/*AUTO SCRIPT*/ /*AUTO SCRIPT*/ public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) /*AUTO SCRIPT*/ { /*AUTO SCRIPT*/ if (list == null) /*AUTO SCRIPT*/ { /*AUTO SCRIPT*/ list = EditorUtility.GetPropertyObject <ByteList>(property); /*AUTO SCRIPT*/ rList = new ReorderableList(list, typeof(byte), true, false, true, true); /*AUTO SCRIPT*/ // rList.onAddCallback += data => { list.Add(defaultVal); }; /*AUTO SCRIPT*/ // rList.onChangedCallback += data=> { /*AUTO SCRIPT*/ // }; /*AUTO SCRIPT*/ } /*AUTO SCRIPT*/ /*AUTO SCRIPT*/ numLines = 3 + list.Count; /*AUTO SCRIPT*/ var title = new GUIContent($" {label.text}"); /*AUTO SCRIPT*/ var height = base.GetPropertyHeight(property, label); /*AUTO SCRIPT*/ var rect = new Rect(position.x, position.y, position.width, height); /*AUTO SCRIPT*/ EditorGUI.BeginChangeCheck(); /*AUTO SCRIPT*/ rList.DoList(rect); /*AUTO SCRIPT*/ EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), title); /*AUTO SCRIPT*/ /*AUTO SCRIPT*/ if (EditorGUI.EndChangeCheck()) { /*AUTO SCRIPT*/ property.serializedObject.ApplyModifiedProperties(); } /*AUTO SCRIPT*/ /*AUTO SCRIPT*/ }
public void FieldLayoutReply_Everything() { PlayingFieldLayout pfl = new PlayingFieldLayout(100, 120); Assert.AreEqual(100, pfl.Width); Assert.AreEqual(120, pfl.Height); Assert.IsNotNull(pfl.SidewalkSquares); PlayingFieldReply r1 = new PlayingFieldReply(Reply.PossibleStatus.Success, pfl, "Test"); Assert.AreEqual(Reply.PossibleStatus.Success, r1.Status); Assert.IsNotNull(r1.Layout); Assert.AreSame(pfl, r1.Layout); ByteList bytes = new ByteList(); r1.Encode(bytes); Message msg = Message.Create(bytes); Assert.IsNotNull(msg); Assert.IsTrue(msg is PlayingFieldReply); PlayingFieldReply r2 = msg as PlayingFieldReply; Assert.AreEqual(Reply.PossibleStatus.Success, r2.Status); Assert.AreEqual(pfl.Height, r2.Layout.Height); Assert.AreEqual(pfl.Width, r2.Layout.Width); }
/// <summary> /// Parse the incoming data /// </summary> /// <returns></returns> private bool ParseResponse() { if (_data != null && _data.Length > 0) { using (var content = new ByteList(_data)) { // Receive the device id from the response DeviceId = content.Skip(8).Take(4).ToArray(); var timestamp = content.ReadInt32LE(12, 4); if (timestamp > 0) { Timestamp = new ServerTimestamp(timestamp); } var encrypted = content.Skip(32); if (encrypted.Count() > 0) { var decrypted = AESHelper.Decrypt(_miToken.Key, _miToken.InitializationVector, encrypted.ToArray()); ResponseText = ASCIIEncoding.ASCII.GetString(decrypted); } return(true); } } return(false); }
protected override void Decode(ByteList bytes) { Log.Debug("Decode a AnswerMessage"); if (bytes == null || !bytes.IsMore) { return; } GameId = bytes.GetShort(); Log.DebugFormat("Decoded GameId = {0}", GameId); if (!bytes.IsMore) { return; } Result = (bytes.GetByte() == 1); Log.DebugFormat("Decoded Result = {0}", Result); if (!bytes.IsMore) { return; } Score = bytes.GetShort(); Log.DebugFormat("Decoded Score = {0}", Score); if (!bytes.IsMore) { return; } Hint = bytes.GetString(); Log.DebugFormat("Decoded Hint = {0}", Hint); }
internal byte[] GetData() { try { byte[] data = ByteList.ToArray(); if (data.Length >= 4) { int length = BitConverter.ToInt32(data, 0); if (length == ByteList.Count) { Reset(); ByteList.Clear(); return(data); } else { return(null); } } else { return(null); } } catch { Reset(); ByteList.Clear(); return(null); } }
public void WhiningSpinner_CheckEncodeAndDecode() { Tick t1 = new Tick(); Tick t2 = new Tick(); Tick t3 = new Tick(); Tick t4 = new Tick(); List <Tick> ticks = new List <Tick> { t1, t2, t3 }; WhiningTwine e1 = new WhiningTwine(10, ticks, t4); Assert.AreEqual(10, e1.CreatorId); Assert.IsNotNull(e1.Ticks); Assert.AreEqual(3, e1.Ticks.Count); Assert.AreSame(t1, e1.Ticks[0]); Assert.AreSame(t2, e1.Ticks[1]); Assert.AreSame(t3, e1.Ticks[2]); Assert.AreSame(t4, e1.RequestTick); ByteList bytes = new ByteList(); e1.Encode(bytes); WhiningTwine e2 = WhiningTwine.Create(bytes); Assert.AreEqual(e1.CreatorId, e2.CreatorId); Assert.AreEqual(e1.Ticks.Count, e2.Ticks.Count); Assert.AreEqual(e1.Ticks[0].LogicalClock, e2.Ticks[0].LogicalClock); Assert.AreEqual(e1.Ticks[0].HashCode, e2.Ticks[0].HashCode); Assert.AreEqual(e1.Ticks[1].LogicalClock, e2.Ticks[1].LogicalClock); Assert.AreEqual(e1.Ticks[1].HashCode, e2.Ticks[1].HashCode); Assert.AreEqual(e1.Ticks[2].LogicalClock, e2.Ticks[2].LogicalClock); Assert.AreEqual(e1.Ticks[2].HashCode, e2.Ticks[2].HashCode); Assert.AreEqual(e1.RequestTick.LogicalClock, e2.RequestTick.LogicalClock); Assert.AreEqual(e1.RequestTick.HashCode, e2.RequestTick.HashCode); bytes.Clear(); e1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { e2 = WhiningTwine.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); e1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { e2 = WhiningTwine.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
public void FieldLocation_CheckEncodeDecode() { ByteList bytes = new ByteList(); FieldLocation loc1 = new FieldLocation { X = 100, Y = 200 }; loc1.Encode(bytes); Assert.AreEqual(9, bytes.Length); Assert.AreEqual(3, bytes[0]); Assert.AreEqual(238, bytes[1]); Assert.AreEqual(0, bytes[2]); Assert.AreEqual(5, bytes[3]); Assert.AreEqual(0, bytes[4]); Assert.AreEqual(100, bytes[5]); Assert.AreEqual(0, bytes[6]); Assert.AreEqual(200, bytes[7]); Assert.AreEqual(0, bytes[8]); FieldLocation loc2 = FieldLocation.Create(bytes); Assert.AreEqual(loc1.X, loc2.X); Assert.AreEqual(loc1.Y, loc2.Y); Assert.AreEqual(false, loc2.Immutable); }
public void StatusReply_TestEverything() { AgentInfo agentInfo = new AgentInfo(1001, AgentInfo.PossibleAgentType.BrilliantStudent) { ANumber = "A0001", FirstName = "Joe", LastName = "Jone" }; StatusReply r1 = new StatusReply(Reply.PossibleStatus.Success, agentInfo); Assert.AreEqual(Reply.PossibleStatus.Success, r1.Status); Assert.AreSame(agentInfo, r1.Info); r1 = new StatusReply(Reply.PossibleStatus.Success, agentInfo, "test note"); Assert.AreEqual(Reply.PossibleStatus.Success, r1.Status); Assert.AreSame(agentInfo, r1.Info); Assert.AreEqual("test note", r1.Note); ByteList byteList = new ByteList(); r1.Encode(byteList); Message msg = Message.Create(byteList); Assert.IsNotNull(msg); Assert.IsTrue(msg is StatusReply); StatusReply r2 = msg as StatusReply; Assert.AreEqual(r1.Status, r2.Status); Assert.AreEqual(r1.Info.Id, r2.Info.Id); Assert.AreEqual(r1.Info.LastName, r2.Info.LastName); Assert.AreEqual(r1.Note, r2.Note); }
protected override void Decode(ByteList bytes) { Log.Debug("Decode an GameDef"); if (bytes == null || !bytes.IsMore) { return; } GameId = bytes.GetShort(); Log.DebugFormat("Decoded GameId = {0}", GameId); if (!bytes.IsMore) { return; } Hint = bytes.GetString(); Log.DebugFormat("Decoded Hint = {0}", Hint); if (!bytes.IsMore) { return; } Definition = bytes.GetString(); Log.DebugFormat("Decoded Definition = {0}", Definition); }
/// <summary> /// サーボの現在角度を読み込む /// </summary> /// <param name="servoID"></param> /// <param name="angle"></param> /// <returns></returns> static public bool b3mAngleRead(SerialPort serialPort, byte servoID, ref int angle) { ByteList cmd = new ByteList(); byte[] rx = new byte[7]; //コマンド受信用(Readで2byte受け取るコマンドは7byte) //コマンドの作成 cmd.Bytes = B3MLib.B3MLib.Read(0x00, B3MLib.B3MLib.SERVO_CURRENT_POSITION, 2, servoID); //option:0 //address:B3MLib.B3MLib.SERVO_CURRENT_POSITION (0x2C) //count:2(受け取るデータの数) //ID:servoID // コマンドを送信 if (B3MLib.B3MLib.Synchronize(serialPort, cmd.Bytes, ref rx) == false) { return(false); } //取得したデータをint(short)型に変換 angle = (short)Extensions.Converter.ByteConverter.ByteArrayToInt16(rx[4], rx[5]); return(true); }
/// <summary> /// This method encodes /// </summary> /// <param name="bytes"></param> public override void Encode(ByteList bytes) { bytes.Add(ClassId); // Write out this class id first Int16 lengthPos = bytes.CurrentWritePosition; // Get the current write position, so we // can write the length here later bytes.Add((Int16)0); // Write out a place holder for the length base.Encode(bytes); // Encode stuff from base class bytes.Add(Convert.ToByte(ReplyType)); // Write out a place holder for the length bytes.Add(Convert.ToByte(Status)); // Write out a place holder for the length if (Note == null) { Note = string.Empty; } bytes.Add(Note); Int16 length = Convert.ToInt16(bytes.CurrentWritePosition - lengthPos - 2); bytes.WriteInt16To(lengthPos, length); // Write out the length of this object }
public override byte[] Encode() { ByteList list = new ByteList(); list.Add((short)MessageType); return(list.ToBytes()); }
// Main Method static public void Main(String[] args) { ByteList list = new ByteList(); Console.WriteLine("koko: " + list.size()); Console.WriteLine("Main Method\n"); }
protected override void Decode(ByteList bytes) { Log.Debug("Decode a NewGameMessage"); if (bytes == null || !bytes.IsMore) { return; } Log.Debug("Try to get the A#"); if (bytes.PeekShort() < 0 && bytes.PeekShort() > 24) { Log.Warn($"The length of the encoded A#, {bytes.PeekShort()}, is probably not correct. Check how you are encoding the string's length"); } ANumber = bytes.GetString(); Log.Debug($"Decoded A# = {ANumber}"); if (string.IsNullOrWhiteSpace(ANumber) || !ANumber.StartsWith("A")) { Log.Warn($"The ANumber doesn't start with an A, and therefore may not be encoded correctly"); } if (!bytes.IsMore) { return; } Log.Debug("Try to get the LastName"); if (bytes.PeekShort() < 0 && bytes.PeekShort() > 48) { Log.Warn($"The length of the encoded LastName, {bytes.PeekShort()}, is probably not correct. Check how you are encoding the string's length"); } LastName = bytes.GetString(); Log.Debug($"Decoded LastName = {LastName}"); if (!bytes.IsMore) { return; } Log.Debug("Try to get the FirstName"); if (bytes.PeekShort() < 0 && bytes.PeekShort() > 48) { Log.Warn($"The length of the encoded FirstName, {bytes.PeekShort()}, is probably not correct. Check how you are encoding the string's length"); } FirstName = bytes.GetString(); Log.Debug($"Decoded FirstName = {FirstName}"); if (!bytes.IsMore) { return; } Log.Debug("Try to get the Alias"); if (bytes.PeekShort() < 0 && bytes.PeekShort() > 48) { Log.Warn($"The length of the encoded Alias, {bytes.PeekShort()}, is probably not correct. Check how you are encoding the string's length"); } Alias = bytes.GetString(); Log.Debug($"Decoded Alias = {Alias}"); }
/////////////////////////////////////////////////////////////////////////////////////////////// public ReturnCode Read( /* throw */ ref ByteList list, ref Result error ) { CheckDisposed(); return(Read(Count.Invalid, ref list, ref error)); }
/// <summary> /// 基本的に [型番号] [[情報長]情報]です。 /// </summary> public CheckedRet <object> Deserial(ByteList bytes) { object obj = null; var ms = new MemoryStream(bytes.ToArray()); BinaryFormatter bf = new BinaryFormatter(); obj = bf.Deserialize(ms); return(new CheckedRet <object>().Set(true, obj)); }
private void CalculateTokenVector() { Key = MD5Helper.Hash(Token); // Join MD5 of key and the token itself to get the vector var ivContent = ByteList.Join(Key, Token); InitializationVector = MD5Helper.Hash(ivContent.ToArray()); }
public static CheckedRet <object> Deserial(ByteList bytes) { try { return(CheckedRet <object> .Gen(true, bytes.DropInt32())); } catch (Exception e) { Debug.Log("Int parse error" + e); return(CheckedRet <object> .Fail()); } }
public void AckNak_CheckConstructorsAndFactories() { Tick t1 = new Tick(); AckNak m = new AckNak(Reply.PossibleStatus.Success, 10, t1, "Test Message", "Test Note"); Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType); Assert.AreEqual(Reply.PossibleStatus.Success, m.Status); Assert.AreEqual(10, m.IntResult); Assert.AreSame(t1, m.ObjResult); Assert.AreEqual("Test Message", m.Message); Assert.AreEqual("Test Note", m.Note); m = new AckNak(Reply.PossibleStatus.Failure, 20); Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType); Assert.AreEqual(Reply.PossibleStatus.Failure, m.Status); Assert.AreEqual(20, m.IntResult); Assert.IsNull(m.ObjResult); Assert.AreEqual("", m.Message); Assert.AreEqual("", m.Note); m = new AckNak(Reply.PossibleStatus.Failure, 20, "Test Message"); Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType); Assert.AreEqual(Reply.PossibleStatus.Failure, m.Status); Assert.AreEqual(20, m.IntResult); Assert.IsNull(m.ObjResult); Assert.AreEqual("Test Message", m.Message); Assert.AreEqual("", m.Note); m = new AckNak(Reply.PossibleStatus.Failure, t1); Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType); Assert.AreEqual(Reply.PossibleStatus.Failure, m.Status); Assert.AreEqual(0, m.IntResult); Assert.AreSame(t1, m.ObjResult); Assert.AreEqual("", m.Message); Assert.AreEqual("", m.Note); m = new AckNak(Reply.PossibleStatus.Failure, t1, "Test Message"); Assert.AreEqual(Reply.PossibleTypes.AckNak, m.ReplyType); Assert.AreEqual(Reply.PossibleStatus.Failure, m.Status); Assert.AreEqual(0, m.IntResult); Assert.AreSame(t1, m.ObjResult); Assert.AreEqual("Test Message", m.Message); Assert.AreEqual("", m.Note); ByteList bytes = new ByteList(); m.Encode(bytes); Message msg = Message.Create(bytes); Assert.IsNotNull(msg); Assert.IsTrue(msg is AckNak); AckNak m2 = msg as AckNak; Assert.AreEqual(m.Status, m2.Status); Assert.AreEqual(m.Note, m2.Note); }
public void AgentInfo_CheckEncodeAndDecode() { EndPoint ep = new EndPoint("129.123.7.24:1345"); AgentInfo info1 = new AgentInfo(20, AgentInfo.PossibleAgentType.WhiningSpinner, ep) { ANumber = "A00001", FirstName = "Joe", LastName = "Jones", Location = new FieldLocation(10, 20, false), Strength = 1200.5, Speed = 1500.0 }; ByteList bytes = new ByteList(); info1.Encode(bytes); AgentInfo info2 = AgentInfo.Create(bytes); Assert.AreEqual(info1.Id, info2.Id); Assert.AreEqual(info1.AgentType, info2.AgentType); Assert.AreEqual(info1.ANumber, info2.ANumber); Assert.AreEqual(info1.FirstName, info2.FirstName); Assert.AreEqual(info1.LastName, info2.LastName); Assert.AreEqual(info1.Strength, info2.Strength); Assert.AreEqual(info1.Speed, info2.Speed); Assert.AreEqual(info1.Points, info2.Points); Assert.AreEqual(info1.Location.X, info2.Location.X); Assert.AreEqual(info1.Location.Y, info2.Location.Y); Assert.AreEqual(info1.CommunicationEndPoint.Address, info2.CommunicationEndPoint.Address); Assert.AreEqual(info1.CommunicationEndPoint.Port, info2.CommunicationEndPoint.Port); bytes.Clear(); info1.Encode(bytes); bytes.GetByte(); // Read one byte, which will throw the length off try { info2 = AgentInfo.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } bytes.Clear(); info1.Encode(bytes); bytes.Add((byte)100); // Add a byte bytes.GetByte(); // Read one byte, which will make the ID wrong try { info2 = AgentInfo.Create(bytes); Assert.Fail("Expected an exception to be thrown"); } catch (ApplicationException) { } }
/// <summary> /// 登録された手続を使ってオブジェクトを直列化する /// 基本的に [型番号] [[情報長]情報]です。 /// </summary> public ByteList ToSerial(object obj) { var ms = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms, obj); var arr = ByteList.Gen().Add(ms.ToArray()); return(arr); }
/** * Constructor. */ public ByteList(ByteList other) { this.bytes = new byte[other.size()]; for (int i = 0; i < other.size(); i++) { this.bytes[i] = other.bytes[i]; } this.pointer = other.pointer; this.readingPointer = other.readingPointer; }
/////////////////////////////////////////////////////////////////////// #region Public Constructors // // NOTE: This constructor does not contain a typo. It is passing its // "bytes" parameter twice into the other constructor, once for // the "data" parameter and once for the "bytes" parameter. It // will allow callers to obtain the value of "bytes" using the // IClientData interface. // public ReadScriptClientData( string fileName, string originalText, string text, ByteList bytes ) : this(bytes, fileName, originalText, text, bytes) { // do nothing. }
override public void Decode(ByteList bytes) { Int16 objType = bytes.GetInt16(); Int16 objLength = bytes.GetInt16(); bytes.SetNewReadLimit(objLength); base.Decode(bytes); bytes.RestorePreviosReadLimit(); }
public static CheckedRet <object> Deserial(ByteList bytes) { try { var size = bytes.DropInt32(); var data = BitConverter.ToSingle(bytes.DropRange(0, size), 0); return(CheckedRet <object> .Gen(true, data)); } catch (Exception e) { Debug.Log("parse error" + e); return(CheckedRet <object> .Fail()); } }
public static CheckedRet <object> Deserial(ByteList bytes) { try { var size = bytes.DropInt32(); var data = System.Text.Encoding.UTF8.GetString(bytes.DropRange(0, size)); return(CheckedRet <object> .Gen(true, data)); } catch (Exception e) { Debug.Log("parse error" + e); return(CheckedRet <object> .Fail()); } }
protected override void Decode(ByteList bytes) { Log.Debug("Decode an HeartbeatMessage"); if (bytes == null || !bytes.IsMore) { return; } GameId = bytes.GetShort(); Log.DebugFormat("Decoded GameId = {0}", GameId); }
/////////////////////////////////////////////////////////////////////////////////////////////// public ReturnCode Read( /* throw */ CharList endOfLine, bool useAnyEndOfLineChar, ref ByteList list, ref Result error ) { CheckDisposed(); return(Read(Count.Invalid, endOfLine, useAnyEndOfLineChar, ref list, ref error)); }
public ByteList GetTypeList(List <string> list) { var count = list.Count; var bytes = ByteList.Gen().Add(count); foreach (var t in list) { bytes.Add(ToSerial(t)); } return(bytes); }
public IntelHexRecord(UInt16 addr, IntexHexRecordTyp typ, Byte[] data) { ByteList list = new ByteList(); int len = (data == null) ? 0 : data.Length; list.AddByte8((Byte)len); list.AddByte16(addr, Endianess.Big); list.AddByte8((Byte)typ); list.AddBuffer(data); list.AddByte8(0xAA); _buffer = list.ToBuffer(); UpdateCrc(); UpdateText(); }