예제 #1
0
        public static long UF_readnumber(CBytesBuffer buffer)
        {
            if (buffer.UF_getSize() < 1)
            {
                return(0);
            }

            byte nNumberType;

            buffer.UF_read(out nNumberType);

            switch (nNumberType)
            {
            case BIT_8:
            {
                byte u8;
                buffer.UF_read(out u8);
                return((sbyte)u8);
            }

            case BIT_16:
            {
                byte[] u16;
                buffer.UF_read(out u16, 2);
#if BIG_ENDIAN
                UF_Reverse(u16);
                                        #endif
                return(BitConverter.ToInt16(u16, 0));
            }

            case BIT_32:
            {
                byte[] u32;
                buffer.UF_read(out u32, 4);
#if BIG_ENDIAN
                UF_Reverse(u32);
                                        #endif
                return(BitConverter.ToInt32(u32, 0));
            }

            case BIT_64:
            {
                byte[] u64;
                buffer.UF_read(out u64, 8);
#if BIG_ENDIAN
                UF_Reverse(u64);
                                        #endif
                //				return BitConverter.ToString(u64);
                return(BitConverter.ToInt64(u64, 0));
            }

            default:
            {
                //返回自己
                return((sbyte)nNumberType);
            }
            }
        }
예제 #2
0
        public static uint UF_readuint32(CBytesBuffer buffer)
        {
            byte[] _tmp;
            buffer.UF_read(out _tmp, 4);
#if BIG_ENDIAN
            UF_Reverse(_tmp);
                        #endif
            return(BitConverter.ToUInt32(_tmp, 0));
        }
예제 #3
0
        public static string UF_readuint64(CBytesBuffer buffer)
        {
            byte[] _tmp;
            buffer.UF_read(out _tmp, 8);
#if BIG_ENDIAN
            UF_Reverse(_tmp);
                        #endif
            UInt64 data = BitConverter.ToUInt64(_tmp, 0);
            return(Convert.ToString(data));
        }
예제 #4
0
        public static byte UF_readuint8(CBytesBuffer buffer)
        {
            if (buffer == null)
            {
                throw new Exception("read buffer is null");
            }
            byte _b = 0;

            buffer.UF_read(out _b);
            return(_b);
        }
예제 #5
0
        public static int UF_readsize(CBytesBuffer buffer)
        {
            uint _size = 0;
            byte _tmpb = 0;

            byte[] _tmpbuf;
            if (buffer == null)
            {
                throw new Exception("read buffer is null");
            }

            buffer.UF_read(out _tmpb);
            if ((_size = _tmpb) >= 0xff)
            {
                buffer.UF_read(out _tmpbuf, 2);
                if ((_size = BitConverter.ToUInt16(_tmpbuf, 0)) >= 0xffff)
                {
                    buffer.UF_read(out _tmpbuf, 4);
                    _size = BitConverter.ToUInt32(_tmpbuf, 0);
                }
            }
            return((int)_size);
        }
예제 #6
0
        public static string UF_readstring(CBytesBuffer buffer)
        {
            //first: read the size type
            if (buffer == null)
            {
                throw new Exception("reading buffer is null");
            }

            //			int _size = readsize(buffer);
            int _size = (int)UF_readnumber(buffer);

            //second: read the string data
            byte[] _byte;
            buffer.UF_read(out _byte, _size);
            if (_byte == null)
            {
                return("");
            }
            else
            {
                return(Encoding.UTF8.GetString(_byte));
            }
        }
예제 #7
0
 public static byte[] UF_readbytes(CBytesBuffer buffer, int size)
 {
     byte[] data = null;
     buffer.UF_read(out data, size);
     return(data);
 }