Ejemplo n.º 1
0
        private void DecodeInsertTablePacket(byte[] resPacket, out PDBErrorCode retVal)
        {
            ProtoHeader proHdr = new ProtoHeader(resPacket);

            InsertResult.Clear();
            SuccessCount = 0;
            retVal       = (PDBErrorCode)proHdr.GetReturnVal();
            if (retVal == PDBErrorCode.PdbE_OK)
            {
                SuccessCount = (int)proHdr.GetRecordCnt();
                for (int i = 0; i < SuccessCount; i++)
                {
                    InsertResult.Add(PDBErrorCode.PdbE_OK);
                }
            }
            else if (retVal == PDBErrorCode.PdbE_INSERT_PART_ERROR)
            {
                int offset = ProtoHeader.kHeadLen;
                int recCnt = (int)proHdr.GetRecordCnt();
                for (int i = 0; i < recCnt; i++)
                {
                    long         recErrVal  = IntTool.DecodeZigZag64(IntTool.ReadRawVarint64(resPacket, ref offset));
                    PDBErrorCode recErrCode = (PDBErrorCode)(recErrVal);
                    if (recErrCode == PDBErrorCode.PdbE_OK)
                    {
                        SuccessCount++;
                    }

                    InsertResult.Add(recErrCode);
                }
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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.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);
        }