Exemplo n.º 1
0
        internal void AddDictionaryField(int pIndex, RiftPacketFieldValueDictionary pValue)
        {
            RiftPacketField field = new RiftPacketField(ERiftPacketFieldType.Dictionary, pIndex);

            field.Value = new RiftPacketFieldValue(ERiftPacketFieldType.Dictionary, pValue);
            mFields.Add(field);
        }
Exemplo n.º 2
0
        private bool ReadFieldValue(ERiftPacketFieldType pFieldType, out RiftPacketFieldValue pFieldValue, out int pSizeOfFieldValue)
        {
            pFieldValue       = null;
            pSizeOfFieldValue = 0;
            switch (pFieldType)
            {
            case ERiftPacketFieldType.False:
            case ERiftPacketFieldType.True:
            case ERiftPacketFieldType.Invalid:
            case ERiftPacketFieldType.Terminator:
                break;

            case ERiftPacketFieldType.Unsigned7BitEncoded:
            case ERiftPacketFieldType.Signed7BitEncoded:
            {
                long value;
                int  sizeOfValue;
                if (!Decode7BitValue(out value, out sizeOfValue, mBuffer, mCursor, mLength))
                {
                    return(false);
                }
                pSizeOfFieldValue += sizeOfValue;
                mCursor           += sizeOfValue;
                mLength           -= sizeOfValue;
                pFieldValue        = new RiftPacketFieldValue(pFieldType, value);
                break;
            }

            case ERiftPacketFieldType.Raw4Bytes:
            {
                if (mLength < 4)
                {
                    return(false);
                }
                byte[] value = new byte[4];
                Buffer.BlockCopy(mBuffer, mCursor, value, 0, 4);
                pSizeOfFieldValue += 4;
                mCursor           += 4;
                mLength           -= 4;
                pFieldValue        = new RiftPacketFieldValue(pFieldType, value);
                break;
            }

            case ERiftPacketFieldType.Raw8Bytes:
            {
                if (mLength < 8)
                {
                    return(false);
                }
                byte[] value = new byte[8];
                Buffer.BlockCopy(mBuffer, mCursor, value, 0, 8);
                pSizeOfFieldValue += 8;
                mCursor           += 8;
                mLength           -= 8;
                pFieldValue        = new RiftPacketFieldValue(pFieldType, value);
                break;
            }

            case ERiftPacketFieldType.ByteArray:
            {
                long length;
                int  sizeOfLength;
                if (!Decode7BitValue(out length, out sizeOfLength, mBuffer, mCursor, mLength))
                {
                    return(false);
                }
                pSizeOfFieldValue += sizeOfLength;
                mCursor           += sizeOfLength;
                mLength           -= sizeOfLength;
                if (mLength < length)
                {
                    return(false);
                }
                byte[] value = new byte[length];
                Buffer.BlockCopy(mBuffer, mCursor, value, 0, (int)length);
                pSizeOfFieldValue += (int)length;
                mCursor           += (int)length;
                mLength           -= (int)length;
                pFieldValue        = new RiftPacketFieldValue(pFieldType, value);
                break;
            }

            case ERiftPacketFieldType.Packet:
            {
                RiftPacket value;
                int        sizeOfValue;
                if (!ReadPacket(out value, out sizeOfValue))
                {
                    return(false);
                }
                pSizeOfFieldValue += sizeOfValue;
                pFieldValue        = new RiftPacketFieldValue(pFieldType, value);
                break;
            }

            case ERiftPacketFieldType.List:
            {
                long listData;
                int  sizeOfListData;
                if (!Decode7BitValue(out listData, out sizeOfListData, mBuffer, mCursor, mLength))
                {
                    return(false);
                }
                pSizeOfFieldValue += sizeOfListData;
                mCursor           += sizeOfListData;
                mLength           -= sizeOfListData;
                int listType;
                int listCount;
                if (!Decode2Parameters(listData, out listType, out listCount))
                {
                    return(false);
                }
                RiftPacketFieldValueList value = new RiftPacketFieldValueList((ERiftPacketFieldType)listType);
                for (int listIndex = 0; listIndex < listCount; ++listIndex)
                {
                    RiftPacketFieldValue listValue;
                    int sizeOfListValue;
                    if (!ReadFieldValue((ERiftPacketFieldType)listType, out listValue, out sizeOfListValue))
                    {
                        return(false);
                    }
                    pSizeOfFieldValue += sizeOfListValue;
                    if (listValue != null)
                    {
                        value.Add(listValue);
                    }
                }
                pFieldValue = new RiftPacketFieldValue(pFieldType, value);
                break;
            }

            case ERiftPacketFieldType.Dictionary:
            {
                long dictionaryData;
                int  sizeOfDictionaryData;
                if (!Decode7BitValue(out dictionaryData, out sizeOfDictionaryData, mBuffer, mCursor, mLength))
                {
                    return(false);
                }
                pSizeOfFieldValue += sizeOfDictionaryData;
                mCursor           += sizeOfDictionaryData;
                mLength           -= sizeOfDictionaryData;
                int dictionaryKeyType;
                int dictionaryValueType;
                int dictionaryCount;
                if (!Decode3Parameters(dictionaryData, out dictionaryKeyType, out dictionaryValueType, out dictionaryCount))
                {
                    return(false);
                }
                RiftPacketFieldValueDictionary value = new RiftPacketFieldValueDictionary((ERiftPacketFieldType)dictionaryKeyType, (ERiftPacketFieldType)dictionaryValueType);
                for (int dictionaryIndex = 0; dictionaryIndex < dictionaryCount; ++dictionaryIndex)
                {
                    RiftPacketFieldValue dictionaryKeyValue = null;
                    if (Enum.IsDefined(typeof(ERiftPacketFieldType), dictionaryKeyType))
                    {
                        int sizeOfDictionaryKeyValue;
                        if (!ReadFieldValue((ERiftPacketFieldType)dictionaryKeyType, out dictionaryKeyValue, out sizeOfDictionaryKeyValue))
                        {
                            return(false);
                        }
                        pSizeOfFieldValue += sizeOfDictionaryKeyValue;
                    }
                    RiftPacketFieldValue dictionaryValueValue = null;
                    if (Enum.IsDefined(typeof(ERiftPacketFieldType), dictionaryValueType))
                    {
                        int sizeOfDictionaryValueValue;
                        if (!ReadFieldValue((ERiftPacketFieldType)dictionaryValueType, out dictionaryValueValue, out sizeOfDictionaryValueValue))
                        {
                            return(false);
                        }
                        pSizeOfFieldValue += sizeOfDictionaryValueValue;
                    }
                    if (dictionaryKeyValue != null || dictionaryValueValue != null)
                    {
                        value.Add(new KeyValuePair <RiftPacketFieldValue, RiftPacketFieldValue>(dictionaryKeyValue, dictionaryValueValue));
                    }
                }
                pFieldValue = new RiftPacketFieldValue(pFieldType, value);
                break;
            }

            default: break;
            }
            return(true);
        }
Exemplo n.º 3
0
 public RiftPacketFieldValue(ERiftPacketFieldType pType, RiftPacketFieldValueDictionary pDictionary)
 {
     Type       = pType;
     Dictionary = pDictionary;
 }