public void ByteOutputStream_WriteAndReadString_Works() { var encoding = new UTF8Encoding(); var sendShort = "banana"; var sendLong = "thisisalongstringrepeatedoverthisisalongstringrepeatedoverthisisalongstringrepeatedoverandoverthisisalongstringrepeatedoverandoverthisisalongstringrepeatedoverandoverthisisalongstringrepeatedoverandoverthisisalongstringrepeatedoverandoverthisisalongstringrepeatedoverandover"; var sendUTF = "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ"; writer.WriteString(sendShort, encoding); writer.WriteString(sendLong, encoding); writer.WriteString(sendUTF, encoding); reader = new DataStreamReader(writer, 0, writer.Length); context = default(DataStreamReader.Context); var recvShort = reader.ReadString(ref context, encoding); var recvLong = reader.ReadString(ref context, encoding); var recvUTF = reader.ReadString(ref context, encoding); Assert.AreEqual(sendShort, recvShort); sendLong = sendLong.Substring(0, recvLong.Length); Assert.AreEqual(sendLong, recvLong); sendUTF = sendUTF.Substring(0, recvUTF.Length); Assert.AreEqual(sendUTF, recvUTF); }
public void FromStream(DataStreamReader reader, ref DataStreamReader.Context ctx) { CurrentPlayers = reader.ReadUShortNetworkByteOrder(ref ctx); MaxPlayers = reader.ReadUShortNetworkByteOrder(ref ctx); ServerName = reader.ReadString(ref ctx, encoding); GameType = reader.ReadString(ref ctx, encoding); BuildId = reader.ReadString(ref ctx, encoding); Map = reader.ReadString(ref ctx, encoding); Port = reader.ReadUShortNetworkByteOrder(ref ctx); }
public void ReadRow(DataStreamReader dataR, int[] filedIndex) { var schemeNames = dataR.GetSchemeName(); int col = 0; while(true) { col = dataR.MoreFieldOnRow(); if (col == -1) { break; } switch (filedIndex[col]) { case 0: m_Id = dataR.ReadString(); break; case 1: m_ItemName = dataR.ReadString(); break; case 2: m_ItemDes = dataR.ReadString(); break; case 3: m_Rare = dataR.ReadInt(); break; case 4: m_ItemLevel = dataR.ReadInt(); break; case 5: m_Type = dataR.ReadInt(); break; case 6: m_StackNum = dataR.ReadInt(); break; case 7: m_NumMax = dataR.ReadInt(); break; case 8: m_UsedType = dataR.ReadInt(); break; case 9: m_FlowID = dataR.ReadString(); break; default: TableHelper.CacheNewField(dataR, schemeNames[col], m_DataCacheNoGenerate); break; } } }
public void ReadRow(DataStreamReader dataR, int[] filedIndex) { //var schemeNames = dataR.GetSchemeName(); int col = 0; while(true) { col = dataR.MoreFieldOnRow(); if (col == -1) { break; } switch (filedIndex[col]) { case 0: m_Id = dataR.ReadInt(); break; case 1: m_Process = dataR.ReadString(); break; default: //TableHelper.CacheNewField(dataR, schemeNames[col], m_DataCacheNoGenerate); break; } } }
public void Deserialize(ref DataStreamReader reader) { Name = reader.ReadString(); Size.x = reader.ReadInt(); Size.y = reader.ReadInt(); //reader.ReadInt(); }
protected override FileTransporter RecieveStart(int hash, DataStreamReader stream, ref DataStreamReader.Context ctx) { if (string.IsNullOrEmpty(SaveDirectory)) { SaveDirectory = Application.persistentDataPath + "/RecieveFile"; System.IO.Directory.CreateDirectory(SaveDirectory); } string fileName = stream.ReadString(ref ctx); int fileSize = stream.ReadInt(ref ctx); ushort dataSize = stream.ReadUShort(ref ctx); string path = SaveDirectory + "/" + hash + "_" + fileName; FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite); var transporter = new FileTransporter(hash, fileName, fs, 8092, 8092); unsafe { fixed(byte *data = transporter.buffer) { stream.ReadBytes(ref ctx, data, dataSize); transporter.bufferPos += dataSize; } } return(transporter); }
public override void DeserializeObject(ref DataStreamReader reader) { base.DeserializeObject(ref reader); PlayerID = reader.ReadInt(); Colour = reader.ReadUInt(); PlayerName = reader.ReadString().ToString(); }
public void Deserialize(ref DataStreamReader reader) { skillId = reader.ReadShort(); skill2Id = reader.ReadShort(); skill3Id = reader.ReadShort(); skill4Id = reader.ReadShort(); characterId = (uint)reader.ReadInt(); skinId = (uint)reader.ReadInt(); userId = reader.ReadString(); }
public void ReadWriteString() { var dataStream = new DataStreamWriter(300 * 4, Allocator.Temp); NativeString64 src = new NativeString64("This is a string"); dataStream.WriteString(src); //Assert.AreEqual(src.LengthInBytes+2, dataStream.Length); var reader = new DataStreamReader(dataStream.AsNativeArray()); var dst = reader.ReadString(); Assert.AreEqual(src, dst); }
public static void NewPlayer(DataStreamReader stream) { stream.ReadUInt(); Player p = new Player { id = stream.ReadInt(), hexColor = stream.ReadUInt(), name = stream.ReadString().ToString() }; Debug.Log("Client: Player we got sent: " + $"ID: {p.id}, HexColor: {p.hexColor}, Name: {p.name}"); NewPlayerReceived?.Invoke(p); }
public void ReadWriteString() { var dataStream = new DataStreamWriter(300 * 4, Allocator.Temp); NativeString64 src = new NativeString64("This is a string"); dataStream.WriteString(src); //Assert.AreEqual(src.LengthInBytes+2, dataStream.Length); var reader = new DataStreamReader(dataStream, 0, dataStream.Length); DataStreamReader.Context ctx = default; var dst = reader.ReadString(ref ctx); Assert.AreEqual(src, dst); ctx = default; }
protected override LargeBytesTransporter RecieveStart(int hash, DataStreamReader stream, ref DataStreamReader.Context ctx) { string name = stream.ReadString(ref ctx); int dataSize = stream.ReadInt(ref ctx); var transporter = new LargeBytesTransporter(hash, new byte[dataSize]); transporter.name = name; int fragmentSize = stream.Length - stream.GetBytesRead(ref ctx); unsafe { fixed(byte *data = &transporter.data[transporter.pos]) { stream.ReadBytes(ref ctx, data, fragmentSize); transporter.pos += fragmentSize; } } return(transporter); }
public void ReadRow(DataStreamReader dataR, int[] filedIndex) { //var schemeNames = dataR.GetSchemeName(); int col = 0; while(true) { col = dataR.MoreFieldOnRow(); if (col == -1) { break; } switch (filedIndex[col]) { case 0: m_Id = dataR.ReadInt(); break; case 1: m_Group = dataR.ReadInt(); break; case 2: m_RewardGold = dataR.ReadInt(); break; case 3: m_Describe = dataR.ReadString(); break; case 4: m_Condition1 = dataR.ReadInt(); break; case 5: m_Title = dataR.ReadInt(); break; case 6: m_Condition2 = dataR.ReadInt(); break; default: //TableHelper.CacheNewField(dataR, schemeNames[col], m_DataCacheNoGenerate); break; } } }
public static void SetName(DataStreamReader stream, NetworkConnection connection) { stream.ReadUInt(); var playerName = stream.ReadString(); Debug.Log("Server: name the client has send = " + playerName); Player player = new Player { id = connection.InternalId, hexColor = ServerBehaviour.Instance.availableHexColors[connection.InternalId].ColorToUInt(), name = playerName.ToString() }; ServerBehaviour.Instance.players.Add(player); Debug.Log("Server: Player I added: " + $"ID: {player.id}, HexColor: {player.hexColor}, Name: {player.name}"); ServerSend.NewPlayer(connection, player); ServerSend.SendOtherPlayers(connection); }
public override void DeserializeObject(ref DataStreamReader reader) { base.DeserializeObject(ref reader); Name = reader.ReadString().ToString(); }
public async Task StartClient() { if (isStarted) { return; } isStarted = true; isHost = false; client = new UdpClient(broadcastPort); Debug.Log("Broadcast StartClient"); while (true) { if (isStarted) { var result = await client.ReceiveAsync(); var responseBytes = result.Buffer; if (responseBytes == null || responseBytes.Length == 0) { continue; } using (var writer = new DataStreamWriter(responseBytes.Length, Allocator.Temp)) { unsafe { fixed(byte *data = responseBytes) { writer.WriteBytes(data, responseBytes.Length); var reader = new DataStreamReader(writer, 0, writer.Length); var ctx = default(DataStreamReader.Context); var key = reader.ReadInt(ref ctx); var version = reader.ReadInt(ref ctx); if (key != m_broadcastKey) { return; } if (version != m_broadcastVersion) { return; } var str = reader.ReadString(ref ctx); //Debug.Log ("OnReciveBroadcast key=" + key + ", version=" + version + ", str=" + str + "time=" + Time.time); OnReciveBroadcast?.Invoke(result.RemoteEndPoint, key, version, str); //Stop (); } } } } else { break; } } if (client != null) { client.Close(); client = null; } }
public static void EchoText(DataStreamReader stream) { var text = stream.ReadString(); Debug.Log(text); }
public static void HelloReceived(DataStreamReader stream) { var text = stream.ReadString(); Debug.Log(text); }
public static void Text(DataStreamReader stream, NetworkConnection connection) { var text = stream.ReadString(); ServerSend.EchoText(connection, text); }
public void Deserialize(ref DataStreamReader reader) { Version = reader.ReadString(); // 需要与下面的成对出现 把组件值传递给 TestInt = reader.ReadInt(); }
public override void Read(DataStreamReader reader, ref DataStreamReader.Context context) { Data = reader.ReadString(ref context).ToString(); }