public static IPacket SendName(string s) { var pack = new MutablePacket(); pack.WriteUShort((ushort)OperationCode.SetName); //OPCode pack.WriteStandardString(s); return pack; }
public static IPacket SendMessage(string s) { var pack = new MutablePacket(); pack.WriteShort(2); //OPCode pack.WriteStandardString(s); return pack; }
public async Task TestPacketWriteStandardString() { const string str = "kaka"; var packet = new MutablePacket(); packet.WriteStandardString(str); var bytes = packet.Lock(); if (packet.Locked) { var task = new Task(() => packet.WriteString("sdgsgd")); task.Start(); Assert.IsTrue(await TaskTimesOut(TimeSpan.FromSeconds(2), task), "Packet reported being locked after locking but was still mutable"); } else { bytes[0] = 212; var newBytes = packet.Lock(); if (bytes[0] != newBytes[0]) Assert.Fail("Packet reported not being locked but the buffer was returned by reference not copy. Return a full copy of the buffer if you wish to unlock else ensure you set the buffer to a locked state when Lock() is called."); } }