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); }
private List <object> GetRecord(uint fieldCnt, byte[] buf, ref int offset) { int valType = 0; List <object> objList = new List <object>(); for (uint i = 0; i < fieldCnt; i++) { valType = (int)IntTool.ReadRawVarint32(buf, ref offset); object obj = GetStoreData(buf, ref offset, valType); objList.Add(obj); } return(objList); }
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.BigInt: return(IntTool.DecodeZigZag64(IntTool.ReadRawVarint64(buf, ref offset))); case PDBType.Double: return(IntTool.ReadDouble(buf, ref offset)); case PDBType.DateTime: ulong lval = IntTool.ReadRawVarint64(buf, ref offset); DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); return((object)dtStart.AddMilliseconds(lval)); 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); }