Example #1
0
 /// <summary>
 /// Serializes <see cref="Packet"/> instance into a byte array
 /// </summary>
 /// <returns>Byte array if successful else throws exception</returns>
 public byte[] Serialize()
 {
     try {
         BytesWriter writer = new BytesWriter();
         writer.WriteString("PACKET_DATA");
         writer.WriteString(Tag);
         writer.WriteBytes(Payload);
         return(writer.Bytes);
     }
     catch (Exception e) {
         var msg = "Packet serialization error : " + e.Message;
         UnityEngine.Debug.LogError(msg);
         throw;
     }
 }
Example #2
0
        /// <summary>
        /// Serializes <see cref="Message"/> instance into a byte array
        /// </summary>
        /// <returns>Returns byte array if successful else exception</returns>
        public byte[] Serialize()
        {
            BytesWriter writer = new BytesWriter();

            try {
                writer.WriteString("MESSAGE_DATA");
                writer.WriteShort(sender);
                writer.WriteShortArray(recipients);
                writer.WriteByteArray(bytes);
                return(writer.Bytes);
            }
            catch (Exception e) {
                var msg = "Message serialization error : " + e.Message;
                UnityEngine.Debug.LogError(msg);
                throw;
            }
        }