Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
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]);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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]);
            }
        }
Exemplo n.º 5
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]);
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
0
 public void Encode(IWritableBuffer bw)
 {
     bw.WriteUnsignedVarint(value);
 }
Exemplo n.º 10
0
        public void Encode(IWritableBuffer bw)
        {
            switch (Tmpl.token)
            {
            case DDToken.ft_bool:
                if (Tmpl.isArray)
                {
                    bw.WriteBooleanArray((bool[])arrValue);
                }
                else
                {
                    var bv = int32Value != 0 ? true : false;
                    bw.WriteBoolean(bv);
                }
                break;

            case DDToken.ft_byte:
                if (Tmpl.isArray)
                {
                    bw.WriteByteArray((byte[])arrValue);
                }
                else
                {
                    bw.WriteByte((byte)int32Value);
                }
                break;

            case DDToken.ft_int16:
                if (Tmpl.isArray)
                {
                    bw.WriteShortArray((short[])arrValue);
                }
                else
                {
                    bw.WriteShort((short)int32Value);
                }
                break;

            case DDToken.ft_int32:
                if (Tmpl.isArray)
                {
                    bw.WriteIntArray((int[])arrValue);
                }
                else
                {
                    bw.WriteInt(int32Value);
                }
                break;

            case DDToken.ft_int64:
                if (Tmpl.isArray)
                {
                    bw.WriteLongArray((long[])arrValue);
                }
                else
                {
                    bw.WriteLong(int64Value);
                }
                break;

            case DDToken.ft_intXU:
                if (Tmpl.isArray)
                {
                    bw.WriteUnsignedVarintArray((long[])arrValue);
                }
                else
                {
                    bw.WriteUnsignedVarint(int64Value);
                }
                break;

            case DDToken.ft_intX:
                if (Tmpl.isArray)
                {
                    bw.WriteVarintArray((long[])arrValue);
                }
                else
                {
                    bw.WriteVarint(int64Value);
                }
                break;

            case DDToken.ft_float:
                if (Tmpl.isArray)
                {
                    bw.WriteFloatArray((float[])arrValue);
                }
                else
                {
                    bw.WriteFloat(floatValue);
                }
                break;

            case DDToken.ft_float16:
                if (Tmpl.isArray)
                {
                    bw.WriteFloat16Array((float[])arrValue);
                }
                else
                {
                    bw.WriteFloat16(floatValue);
                }
                break;

            case DDToken.ft_str:
                if (Tmpl.isArray)
                {
                    bw.WriteUTF8Array((string[])arrValue);
                }
                else
                {
                    bw.WriteUTF8(strValue);
                }
                break;

            case DDToken.ft_object:
                if (Tmpl.isArray)
                {
                    bw.WriteNodeArray((DDNode[])arrValue, Tmpl);
                }
                else
                {
                    bw.WritNode(objValue, Tmpl);
                }
                break;
            }
        }