public TdrError.ErrorType unpackTLV(ref long selector, ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if (srcBuf == null || length == 0)
            {
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }
            int  usedSize = srcBuf.getUsedSize();
            uint tagid    = 0u;

            TdrError.ErrorType errorType = srcBuf.readVarUInt32(ref tagid);
            if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
            {
                return(errorType);
            }
            uint fieldId = TdrTLV.getFieldId(tagid);

            switch (fieldId)
            {
            case 0u:
                if (useVarInt)
                {
                    errorType = srcBuf.readVarInt32(ref this.iNilCmd);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                }
                else
                {
                    errorType = srcBuf.readInt32(ref this.iNilCmd);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                }
                break;

            case 1u:
            {
                if (this.szStrCmd == null)
                {
                    this.szStrCmd = new byte[64];
                }
                int num = 0;
                errorType = srcBuf.readInt32(ref num);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                if (num >= 64)
                {
                    return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                }
                errorType = srcBuf.readCString(ref this.szStrCmd, num);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                break;
            }

            case 2u:
                if (useVarInt)
                {
                    errorType = srcBuf.readVarInt32(ref this.iIntCmd);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                }
                else
                {
                    errorType = srcBuf.readInt32(ref this.iIntCmd);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                }
                break;

            default:
                errorType = TdrError.ErrorType.TDR_ERR_SUSPICIOUS_SELECTOR;
                break;
            }
            if (srcBuf.getUsedSize() > usedSize + length)
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            selector = (long)((ulong)fieldId);
            return(errorType);
        }
Beispiel #2
0
        public TdrError.ErrorType unpackTLV(ref long selector, ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if ((srcBuf == null) || (length == 0))
            {
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }
            TdrError.ErrorType type = TdrError.ErrorType.TDR_NO_ERROR;
            int  num  = srcBuf.getUsedSize();
            uint dest = 0;

            type = srcBuf.readVarUInt32(ref dest);
            if (type == TdrError.ErrorType.TDR_NO_ERROR)
            {
                uint num3 = TdrTLV.getFieldId(dest);
                switch (num3)
                {
                case 0:
                    if (!useVarInt)
                    {
                        type = srcBuf.readInt32(ref this.iNilCmd);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            break;
                        }
                        return(type);
                    }
                    type = srcBuf.readVarInt32(ref this.iNilCmd);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        break;
                    }
                    return(type);

                case 1:
                {
                    if (this.szStrCmd == null)
                    {
                        this.szStrCmd = new byte[0x40];
                    }
                    int num4 = 0;
                    type = srcBuf.readInt32(ref num4);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        if (num4 >= 0x40)
                        {
                            return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                        }
                        type = srcBuf.readCString(ref this.szStrCmd, num4);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            break;
                        }
                    }
                    return(type);
                }

                case 2:
                    if (!useVarInt)
                    {
                        type = srcBuf.readInt32(ref this.iIntCmd);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            break;
                        }
                        return(type);
                    }
                    type = srcBuf.readVarInt32(ref this.iIntCmd);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        break;
                    }
                    return(type);

                default:
                    type = TdrError.ErrorType.TDR_ERR_SUSPICIOUS_SELECTOR;
                    break;
                }
                if (srcBuf.getUsedSize() > (num + length))
                {
                    return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
                }
                selector = num3;
            }
            return(type);
        }