Ejemplo n.º 1
0
        private object GetStoreData(byte[] buf, ref int offset, int valType)
        {
            object obj;

            switch ((PDBType)valType)
            {
            case PDBType.Null:
                return(DBNull.Value);

            case PDBType.Bool:
                return(IntTool.ReadSInt8(buf, ref offset) != 0);

            case PDBType.TinyInt:
                return(Convert.ToSByte(IntTool.DecodeZigZag64(IntTool.ReadRawVarint64(buf, ref offset))));

            case PDBType.ShortInt:
                return(Convert.ToInt16(IntTool.DecodeZigZag64(IntTool.ReadRawVarint64(buf, ref offset))));

            case PDBType.Int:
                return(Convert.ToInt32(IntTool.DecodeZigZag64(IntTool.ReadRawVarint64(buf, ref offset))));

            case PDBType.BigInt:
                return(IntTool.DecodeZigZag64(IntTool.ReadRawVarint64(buf, ref offset)));

            case PDBType.Float:
                return(IntTool.ReadFloat(buf, ref offset));

            case PDBType.Double:
                return(IntTool.ReadDouble(buf, ref offset));

            case PDBType.DateTime:
                long tmpTs = IntTool.DecodeZigZag64(IntTool.ReadRawVarint64(buf, ref offset));
                return(new DateTime(1970, 1, 1).Add(TimeZoneInfo.Local.BaseUtcOffset).AddTicks((long)tmpTs * 10));

            case PDBType.String:
                int valLen = 0;
                valLen  = (int)IntTool.ReadRawVarint32(buf, ref offset);
                obj     = (object)Encoding.UTF8.GetString(buf, offset, valLen);
                offset += valLen;
                return(obj);

            case PDBType.Blob:
                valLen = (int)IntTool.ReadRawVarint32(buf, ref offset);
                byte[] blobVal = new byte[valLen];
                Array.Copy(buf, offset, blobVal, 0, valLen);
                obj     = (object)blobVal;
                offset += valLen;
                return(obj);
            }
            return(DBNull.Value);
        }