Beispiel #1
0
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if ((srcBuf == null) || (length <= 0))
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType type = TdrError.ErrorType.TDR_NO_ERROR;
            uint dest = 0;
            int  num3 = 0;
            int  num4 = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < (num4 + length))
            {
                type = srcBuf.readVarUInt32(ref dest);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
                switch (TdrTLV.getFieldId(dest))
                {
                case 1:
                    if (!this.has_Len())
                    {
                        this.set_has_Len();
                    }
                    if (useVarInt)
                    {
                        type = srcBuf.readVarUInt16(ref this.wLen);
                        if (type != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(type);
                        }
                        continue;
                    }
                    type = srcBuf.readUInt16(ref this.wLen);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        continue;
                    }
                    return(type);

                case 2:
                {
                    if (!this.has_Data())
                    {
                        this.set_has_Data();
                    }
                    int num5 = 0;
                    type = srcBuf.readInt32(ref num5);
                    if (type != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(type);
                    }
                    if (num5 == 0)
                    {
                        return(TdrError.ErrorType.TDR_ERR_NULL_ARRAY);
                    }
                    int num6 = srcBuf.getUsedSize();
                    for (int i = 0; i < 0xffff; i++)
                    {
                        type = srcBuf.readUInt8(ref this.szData[i]);
                        if (type != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(type);
                        }
                        if (srcBuf.getUsedSize() > (num6 + num5))
                        {
                            return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
                        }
                        if (srcBuf.getUsedSize() == (num6 + num5))
                        {
                            this.wLen = (ushort)(i + 1);
                            break;
                        }
                    }
                    continue;
                }
                }
                uint num8 = TdrTLV.getTypeId(dest);
                type = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)num8);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
            }
            if (srcBuf.getUsedSize() > (num4 + length))
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num3 < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(type);
        }
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if (srcBuf == null || length <= 0)
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType errorType = TdrError.ErrorType.TDR_NO_ERROR;
            uint tagid    = 0u;
            int  num      = 0;
            int  usedSize = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < usedSize + length)
            {
                errorType = srcBuf.readVarUInt32(ref tagid);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                uint fieldId = TdrTLV.getFieldId(tagid);
                uint num2    = fieldId;
                if (num2 != 1u)
                {
                    if (num2 != 2u)
                    {
                        uint typeId = TdrTLV.getTypeId(tagid);
                        errorType = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)typeId);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                    else
                    {
                        if (!this.has_Data())
                        {
                            this.set_has_Data();
                        }
                        int num3 = 0;
                        errorType = srcBuf.readInt32(ref num3);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                        if (num3 == 0)
                        {
                            return(TdrError.ErrorType.TDR_ERR_NULL_ARRAY);
                        }
                        int usedSize2 = srcBuf.getUsedSize();
                        for (int i = 0; i < 65535; i++)
                        {
                            errorType = srcBuf.readUInt8(ref this.szData[i]);
                            if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                            {
                                return(errorType);
                            }
                            if (srcBuf.getUsedSize() > usedSize2 + num3)
                            {
                                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
                            }
                            if (srcBuf.getUsedSize() == usedSize2 + num3)
                            {
                                this.wLen = (ushort)(i + 1);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (!this.has_Len())
                    {
                        this.set_has_Len();
                    }
                    if (useVarInt)
                    {
                        errorType = srcBuf.readVarUInt16(ref this.wLen);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                    else
                    {
                        errorType = srcBuf.readUInt16(ref this.wLen);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                }
            }
            if (srcBuf.getUsedSize() > usedSize + length)
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(errorType);
        }