コード例 #1
0
ファイル: GString.cs プロジェクト: zcmrp/MProxy
        public GString(Octets os, Encoding enc)
        {
            CompactUInt len = os.ReadCompactUInt();

            byte[] bstr = os.ReadBytes(len);
            this.str       = enc.GetString(bstr);
            this.GEncoding = enc;
        }
コード例 #2
0
 public Octets Write(object data)
 {
     byte[] conv;
     if (data is byte[])
     {
         byte[] write = (byte[])data;
         this.Extend((uint)write.Length);
         write.CopyTo(this.buffer, this.EXLen);
         return(this);
     }
     else if (data is bool)
     {
         return(Write((byte)((bool)data ? 1 : 0)));
     }
     else if (data is byte)
     {
         this.Extend(1).buffer[this.EXLen] = (byte)data;
         return(this);
     }
     else if (data is short || data is ushort)
     {
         conv = BitConverter.GetBytes((ushort)data);
         if (this.Order == ByteOrder.BigEndian)
         {
             conv = conv.Reverse().ToArray();
         }
         return(Write(conv));
     }
     else if (data is uint || data is int)
     {
         conv = BitConverter.GetBytes((uint)data);
         if (this.Order == ByteOrder.BigEndian)
         {
             conv = conv.Reverse().ToArray();
         }
         return(Write(conv));
     }
     else if (data is ulong || data is long)
     {
         conv = BitConverter.GetBytes((ulong)data);
         if (this.Order == ByteOrder.BigEndian)
         {
             conv = conv.Reverse().ToArray();
         }
         return(Write(conv));
     }
     else if (data is Octets)
     {
         Octets src = (Octets)data;
         return(Write(src.Length).Write(src.RawData()));
     }
     else if (data is CompactUInt)
     {
         CompactUInt cu = (CompactUInt)data;
         return(Write(cu.RawData()));
     }
     else if (data is GString)
     {
         GString gstr = (GString)data;
         return(Write(gstr.Length).Write(gstr.RawData()));
     }
     return(this);
 }
コード例 #3
0
 public Octets(Octets os)
 {
     this.Order = BitConverter.IsLittleEndian ? ByteOrder.LittleEndian : ByteOrder.BigEndian;
     Length     = new CompactUInt(os);
     buffer     = os.ReadBytes(Length);
 }