Esempio n. 1
0
        /// <summary>
        /// Serialize struct to NetDataWriter (fast)
        /// </summary>
        /// <param name="writer">Serialization target NetDataWriter</param>
        /// <param name="obj">Struct to serialize</param>
        public void Serialize <T>(NetDataWriter writer, T obj) where T : class, new()
        {
            var info = RegisterInternal <T>();

            _hasher.WriteHash(info.Hash, writer);
            info.Write(writer, obj);
        }
Esempio n. 2
0
        /// <summary>
        /// Serialize struct to NetDataWriter (fast)
        /// </summary>
        /// <param name="writer">Serialization target NetDataWriter</param>
        /// <param name="obj">Struct to serialize</param>
        public void Serialize <T>(NetDataWriter writer, T obj) where T : class, new()
        {
            Type  t         = typeof(T);
            ulong nameHash  = _hasher.GetHash(t.Name);
            var   classInfo = Register <T>(t, nameHash);
            var   wd        = classInfo.WriteDelegate;
            var   wdlen     = wd.Length;

            classInfo.Reference = obj;
            _hasher.WriteHash(t.Name, writer);
            for (int i = 0; i < wdlen; i++)
            {
                wd[i](writer);
            }
        }