Example #1
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_UNITID))
     {
         bw.WriteInt(_unitId);
     }
     if (mask.CheckFlag(__FLAG_TYPE))
     {
         bw.WriteByte(_type);
     }
     if (mask.CheckFlag(__FLAG_X))
     {
         bw.WriteFloat(_x);
     }
     if (mask.CheckFlag(__FLAG_Y))
     {
         bw.WriteFloat(_y);
     }
     if (mask.CheckFlag(__FLAG_Z))
     {
         bw.WriteFloat(_z);
     }
     if (mask.CheckFlag(__FLAG_FACETO))
     {
         bw.WriteFloat(_faceTo);
     }
 }
Example #2
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_UNITID))
     {
         bw.WriteInt(_unitId);
     }
     if (mask.CheckFlag(__FLAG_BASEVALUE))
     {
         bw.WriteInt(_baseValue);
     }
     if (mask.CheckFlag(__FLAG_VALUE))
     {
         bw.WriteInt(_value);
     }
     if (mask.CheckFlag(__FLAG_DAMAGETYPE))
     {
         bw.WriteInt(_damageType);
     }
     if (mask.CheckFlag(__FLAG_DAMAGEFLAG))
     {
         bw.WriteInt(_damageFlag);
     }
     if (mask.CheckFlag(__FLAG_KILLEDPARAM))
     {
         bw.WriteByte(_killedParam);
     }
 }
Example #3
0
 public static void WriteUnknow(this IWritableBuffer bw, DataObject obj)
 {
     if (obj != null)
     {
         using (var tempBw = ByteBuffer.Pool.Get())
         {
             var typeCode = Protocol.Instance.GetTypeCode(obj.GetType().FullName);
             tempBw.WriteUnsignedShort(typeCode);
             if (typeCode == 0)
             {
                 Logger.Error("GetTypeCode failed! -> {0}", obj.GetType());
             }
             else
             {
                 obj.Encode(tempBw);
             }
             bw.WriteUnsignedVarint(tempBw.Length);
             bw.Write(tempBw);
         }
     }
     else
     {
         bw.WriteUnsignedVarint(0);
     }
 }
Example #4
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_ACTIONS))
     {
         bw.WriteUnknowArray(_actions);
     }
 }
Example #5
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_UNITID))
     {
         bw.WriteInt(_unitId);
     }
 }
Example #6
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_DATA))
     {
         bw.Write(_data);
     }
 }
Example #7
0
        public static void WriteArray <T>(this IWritableBuffer bw, T[] arr) where T : DataObject, new()
        {
            int len = arr == null ? 0 : arr.Length;

            bw.WriteUnsignedVarint(len);
            for (int i = 0; i < len; i++)
            {
                bw.Write(arr[i]);
            }
        }
Example #8
0
        public static void WriteUnknowArray(this IWritableBuffer bw, DataObject[] arr)
        {
            int len = arr == null ? 0 : arr.Length;

            bw.WriteUnsignedVarint(len);
            for (int i = 0; i < len; i++)
            {
                bw.WriteUnknow(arr[i]);
            }
        }
Example #9
0
        internal static void WriteNodeArray(this IWritableBuffer bw, DDNode[] arr, DDFieldTmpl dataTmpl)
        {
            int len = arr == null ? 0 : arr.Length;

            bw.WriteUnsignedVarint(len);
            for (int i = 0; i < len; i++)
            {
                bw.WritNode(arr[i], dataTmpl);
            }
        }
Example #10
0
        public static void WriteUnsignedVarintArray(this IWritableBuffer bw, long[] dat)
        {
            var len = dat == null ? 0 : dat.Length;

            bw.WriteUnsignedVarint(len);
            for (var i = 0; i < len; i++)
            {
                bw.WriteUnsignedVarint(dat[i]);
            }
        }
Example #11
0
        public static void WriteByteArray(this IWritableBuffer bw, byte[] dat)
        {
            var len = dat == null ? 0 : dat.Length;

            bw.WriteUnsignedVarint(len);
            if (len > 0)
            {
                bw.Write(dat);
            }
        }
Example #12
0
 public static void WriteBoolean(this IWritableBuffer bw, bool val)
 {
     if (val)
     {
         bw.WriteByte(1);
     }
     else
     {
         bw.WriteByte(0);
     }
 }
Example #13
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_TMPLID))
     {
         bw.WriteInt(_tmplId);
     }
     if (mask.CheckFlag(__FLAG_LEV))
     {
         bw.WriteInt(_lev);
     }
 }
Example #14
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_SCENEMAP))
     {
         bw.WriteUTF8(_sceneMap);
     }
     if (mask.CheckFlag(__FLAG_UNITS))
     {
         bw.WriteArray(_units);
     }
 }
Example #15
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_INFO))
     {
         bw.Write(_info);
     }
     if (mask.CheckFlag(__FLAG_PROP))
     {
         bw.Write(_prop);
     }
 }
Example #16
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_KEY))
     {
         bw.WriteUTF8(_key);
     }
     if (mask.CheckFlag(__FLAG_VALUE))
     {
         bw.WriteInt(_value);
     }
 }
Example #17
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_DUNGEONTMPL))
     {
         bw.WriteUTF8(_dungeonTmpl);
     }
     if (mask.CheckFlag(__FLAG_DIFFICULTY))
     {
         bw.WriteInt(_difficulty);
     }
 }
Example #18
0
 public static void Write(this IWritableBuffer bw, ByteBuffer other)
 {
     if (other == null || other.Length == 0)
     {
         return;
     }
     if (other == bw)
     {
         throw new ArgumentException();
     }
     bw.Write(other.data, 0, other.Length);
 }
Example #19
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_UNITID))
     {
         bw.WriteInt(_unitId);
     }
     if (mask.CheckFlag(__FLAG_FACETO))
     {
         bw.WriteFloat(_faceTo);
     }
     if (mask.CheckFlag(__FLAG_X))
     {
         bw.WriteFloat(_x);
     }
     if (mask.CheckFlag(__FLAG_Y))
     {
         bw.WriteFloat(_y);
     }
     if (mask.CheckFlag(__FLAG_Z))
     {
         bw.WriteFloat(_z);
     }
     if (mask.CheckFlag(__FLAG_HPPERCENT))
     {
         bw.WriteFloat(_hpPercent);
     }
     if (mask.CheckFlag(__FLAG_MPPERCENT))
     {
         bw.WriteFloat(_mpPercent);
     }
     if (mask.CheckFlag(__FLAG_ACTIONSTATE))
     {
         bw.WriteByte(_actionState);
     }
     if (mask.CheckFlag(__FLAG_ANIMPLAYCODE))
     {
         bw.WriteInt(_AnimPlayCode);
     }
     if (mask.CheckFlag(__FLAG_ANIMPLAYTIME))
     {
         bw.WriteFloat(_AnimPlayTime);
     }
     if (mask.CheckFlag(__FLAG_EFFECTSHOW))
     {
         bw.WriteInt(_effectShow);
     }
     if (mask.CheckFlag(__FLAG_CONTROLFLAG))
     {
         bw.WriteInt(_controlFlag);
     }
 }
Example #20
0
 public static void WriteUTF8(this IWritableBuffer bw, string str)
 {
     if (str != null)
     {
         using (var temp = ByteBuffer.Pool.Get())
         {
             CodingUtil.DecodeUTF8(str, temp);
             bw.WriteUnsignedShort(temp.Length);
             bw.Write(temp.data, 0, temp.Length);
         }
     }
     else
     {
         bw.WriteShort(0);
     }
 }
Example #21
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_UNITID))
     {
         bw.WriteInt(_unitId);
     }
     if (mask.CheckFlag(__FLAG_BASEVALUE))
     {
         bw.WriteInt(_baseValue);
     }
     if (mask.CheckFlag(__FLAG_VALUE))
     {
         bw.WriteInt(_value);
     }
 }
Example #22
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_UNITID))
     {
         bw.WriteInt(_unitId);
     }
     if (mask.CheckFlag(__FLAG_TARGETID))
     {
         bw.WriteInt(_targetId);
     }
     if (mask.CheckFlag(__FLAG_ABILITYID))
     {
         bw.WriteInt(_abilityId);
     }
 }
Example #23
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_TYPE))
     {
         bw.WriteByte(_type);
     }
     if (mask.CheckFlag(__FLAG_UUID))
     {
         bw.WriteLong(_uuid);
     }
     if (mask.CheckFlag(__FLAG_UNITS))
     {
         bw.WriteArray(_units);
     }
 }
Example #24
0
        public static void Write <T>(this IWritableBuffer bw, T obj) where T : DataObject, new()
        {
            if (obj != null)
            {
                using (var tempBw = ByteBuffer.Pool.Get())
                {
                    obj.Encode(tempBw);

                    bw.WriteUnsignedVarint(tempBw.Length);
                    bw.Write(tempBw);
                }
            }
            else
            {
                bw.WriteUnsignedVarint(0);
            }
        }
Example #25
0
 public void Encode(IWritableBuffer bw)
 {
     // -- protos
     bw.WriteUnsignedShort(protosDict.Count);
     for (var iter = protosDict.GetEnumerator(); iter.MoveNext();)
     {
         bw.WriteShort(iter.Current.Key);
         iter.Current.Value.EncodeTo(bw);
     }
     // -- types
     bw.WriteUnsignedShort(typesCode.Count);
     for (var iter = typesCode.GetEnumerator(); iter.MoveNext();)
     {
         bw.WriteUTF8(iter.Current.Key);
         bw.WriteShort(iter.Current.Value);
     }
 }
Example #26
0
 public void EncodeTo(IWritableBuffer bw)
 {
     bw.WriteUTF8(route);
     bw.WriteByte((byte)ptype);
     if (ptype == ProtoType.Request)
     {
         bw.WriteUTF8(c2sdt);
         bw.WriteUTF8(s2cdt);
     }
     else if (ptype == ProtoType.Notify)
     {
         bw.WriteUTF8(c2sdt);
     }
     else if (ptype == ProtoType.Push)
     {
         bw.WriteUTF8(s2cdt);
     }
 }
Example #27
0
        public static void WriteUnsignedVarint(this IWritableBuffer bw, long mv)
        {
            long value = mv;
            byte b;

            while (true)
            {
                b     = (byte)(value & 0x7F);
                value = (value >> 7) & 0x1FFFFFFFFFFFFFFL;
                if (value != 0)
                {
                    b |= 0x80;
                    bw.WriteByte(b);
                }
                else
                {
                    bw.WriteByte(b);
                    break;
                }
            }
        }
Example #28
0
        public void Encode(IWritableBuffer bw)
        {
            var mask = Mask.Cache.Get();

            for (byte i = 0; i < fields.Count; i++)
            {
                if (fields[i].maskBit)
                {
                    mask.AddFlag(i);
                }
            }
            mask.Encode(bw);
            for (byte i = 0; i < fields.Count; i++)
            {
                if (mask.CheckFlag(i))
                {
                    fields[i].Encode(bw);
                }
            }
            Mask.Cache.Put(mask);
        }
Example #29
0
 internal static void WritNode(this IWritableBuffer bw, DDNode obj, DDFieldTmpl fieldTmpl)
 {
     if (obj != null)
     {
         using (var tempBw = ByteBuffer.Pool.Get())
         {
             if (fieldTmpl.isUnknowType)
             {
                 var typeCode = Protocol.Instance.GetTypeCode(obj.Tmpl.fullName);
                 tempBw.WriteUnsignedShort(typeCode);
                 if (typeCode == 0)
                 {
                     Logger.Error("GetTypeCode failed! -> {0}", obj.GetType());
                 }
                 else
                 {
                     obj.Encode(tempBw);
                 }
             }
             else
             {
                 if (fieldTmpl.objTmpl != obj.Tmpl.fullName)
                 {
                     Logger.Error("write failed! can't match tmpl {0} -> {1} ", fieldTmpl.objTmpl, obj.Tmpl.fullName);
                 }
                 else
                 {
                     obj.Encode(tempBw);
                 }
             }
             bw.WriteUnsignedVarint(tempBw.Length);
             bw.Write(tempBw);
         }
     }
     else
     {
         bw.WriteShort(0);
     }
 }
Example #30
0
        public static void WriteVarint(this IWritableBuffer bw, long val)
        {
            byte b;

            if (val < 0)
            {
                val = ~val;
                b   = (byte)(val & 0x3F);
                b  |= 0x40;
            }
            else
            {
                b = (byte)(val & 0x3F);
            }
            val = val >> 6;
            if (val != 0)
            {
                b |= 0x80;
            }
            bw.WriteByte(b);
            while (val != 0)
            {
                b   = (byte)(val & 0x7F);
                val = val >> 7;
                if (val != 0)
                {
                    b |= 0x80;
                    bw.WriteByte(b);
                }
                else
                {
                    bw.WriteByte(b);
                    break;
                }
            }
        }