Exemple #1
0
 /// <summary>
 ///   このメソッドはposition, lengthを触らないので、seekの調整は呼びだし元が責任をもって行なう事。
 /// </summary>
 unsafe public static void Memcpy(byte [] dstBuf, AmByteArray srcBuf, int size)
 {
     fixed(byte *dst = &dstBuf[0])
     {
         fixed(byte *src = &srcBuf.data[srcBuf.position])
         {
             for (int idx = 0; idx < size; ++idx)
             {
                 dst[idx] = src[idx];
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        ///   このメソッドはposition, lengthを触らないので、seekの調整は呼びだし元が責任をもって行なう事。
        /// </summary>
        unsafe public static int Memcmp(AmByteArray s1, AmByteArray s2, int n)
        {
            int ret = 0;

            fixed(byte *sa = &s1.data[s1.position])
            {
                fixed(byte *sb = &s2.data[s2.position])
                {
                    for (int idx = 0; idx < n; ++idx)
                    {
                        if (sa[idx] != sb[idx])
                        {
                            ret = -1; break;
                        }
                    }
                }
            }

            return(ret);
        }
Exemple #3
0
        // @todo
        //public void writeUTFBytes(string value){}

        unsafe public void writeBytes(AmByteArray bytes, uint _offset = uint.MaxValue, uint _length = 0)
        {
            int valueOffset = (_offset != uint.MaxValue) ? (int)_offset : (int)bytes.position;
            int valueLen    = (_length != 0) ? (int)_length : (int)(bytes.length - valueOffset);

            byte [] valueBytes = bytes.data;
            fixed(byte *dst = &m_buf[position])
            {
                fixed(byte *src = &valueBytes[valueOffset])
                {
                    for (int idx = 0; idx < valueLen; ++idx)
                    {
                        dst[idx] = src[idx];
                    }

                    position = position + (uint)valueLen;

                    // 注意:WriteのSoruceとなった方のByteArrayのPositionは変わらない(readと微妙に違うので注意)
                }
            }
        }
Exemple #4
0
        unsafe public void readBytes(AmByteArray bytes, uint _offset = uint.MaxValue, uint _length = 0)
        {
            int valueOffset = (_offset != uint.MaxValue) ? (int)_offset : (int)bytes.position;
            int valueLen    = (_length != 0) ? (int)_length : (int)bytesAvailable;

            byte [] valueBytes = bytes.data;
            fixed(byte *dst = &valueBytes[valueOffset])
            {
                fixed(byte *src = &m_buf[position])
                {
                    for (int idx = 0; idx < valueLen; ++idx)
                    {
                        dst[idx] = src[idx];
                    }

                    bytes.position = bytes.position + (uint)valueLen;

                    // 読込み元のpositionも変わる
                    position = position + (uint)valueLen;
                }
            }
        }
Exemple #5
0
 // 省略したら、配列の長さをそのまま渡す
 public static string HexDump(AmByteArray src, int length)
 {
     return(HexDump(src.data, length));
 }