Ejemplo n.º 1
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);
     }
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
0
 public void Encode(IWritableBuffer bw)
 {
     this.mask.Encode(bw);
     if (mask.CheckFlag(__FLAG_DATA))
     {
         bw.Write(_data);
     }
 }
Ejemplo n.º 4
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]);
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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);
     }
 }
Ejemplo n.º 10
0
 public static void Write(this IWritableBuffer bw, byte[] bytes)
 {
     bw.Write(bytes, 0, bytes.Length);
 }