Exemplo n.º 1
0
        // pack message before sending
        // -> NetworkWriter passed as arg so that we can use .ToArraySegment
        //    and do an allocation free send before recycling it.
        public static void Pack <T>(T message, NetworkWriter writer)
        {
            // if it is a value type,  just use typeof(T) to avoid boxing
            // this works because value types cannot be derived
            // if it is a reference type (for example IMessageBase),
            // ask the message for the real type
            Type mstType = default(T) == null && message != null?message.GetType() : typeof(T);

            int msgType = GetId(mstType);

            writer.WriteUInt16((ushort)msgType);

            writer.Write(message);
        }
Exemplo n.º 2
0
 public static void WriteNotifyPacket(this NetworkWriter writer, NotifyPacket packet)
 {
     writer.WriteUInt16(packet.Sequence);
     writer.WriteUInt16(packet.ReceiveSequence);
     writer.WriteUInt64(packet.AckMask);
 }