Example #1
0
        private void XmlStartField(FieldKeyType type, byte[] key, int fieldSize)
        {
            string keyValue;

            if (BlobUtil.IsIntDescriptor(key))
            {
                keyValue = Convert.ToString(BitConverter.ToUInt32(key, 0));
            }
            else
            {
                keyValue = Encoding.UTF8.GetString(key);
            }

            xmlOut.WriteStartElement("field");
            xmlOut.WriteAttributeString("key", keyValue);
        }
Example #2
0
        private void ProcessFields(int serializedSize)
        {
            while (serializedSize > FieldHeaderLength && CanRead(FieldHeaderLength))
            {
                Int16 descriptorLength;
                Int32 dataLength;

                byte[] descriptor;

                Mark(FieldHeaderLength);

                try
                {
                    descriptorLength = input.ReadInt16();
                    dataLength       = input.ReadInt32();

                    if (descriptorLength <= 0 || !CanRead(descriptorLength + dataLength))
                    {
                        Reset();
                        throw new Exception("Corrupted field lengths");
                    }

                    serializedSize -= FieldHeaderLength;

                    descriptor = new byte[descriptorLength];
                    input.Read(descriptor, 0, descriptorLength);

                    serializedSize -= descriptorLength;
                }
                catch (Exception)
                {
                    Reset();
                    throw new Exception("Corrupted field");
                }

                if (Field != null)
                {
                    Field((BlobUtil.IsIntDescriptor(descriptor) ? FieldKeyType.IntType : FieldKeyType.StringType),
                          descriptor, dataLength);
                }

                if (!TryReadBlob((uint)dataLength))
                {
                    byte[] data = new byte[dataLength];
                    input.Read(data, 0, dataLength);

                    if (FieldValue != null)
                    {
                        FieldValue(data);
                    }
                }

                if (EndField != null)
                {
                    EndField();
                }

                serializedSize -= dataLength;
            }

            if (serializedSize != 0)
            {
                throw new Exception("Data left untouched in Field");
            }
        }
Example #3
0
        private void TypeStartField(FieldKeyType type, byte[] key, int fieldSize)
        {
            string keyValue;

            if (BlobUtil.IsIntDescriptor(key))
            {
                keyValue = Convert.ToString(BitConverter.ToUInt32(key, 0));
            }
            else
            {
                keyValue = Encoding.UTF8.GetString(key);
            }

            int          fieldIndex;
            ProcessState top = PeekStackTop();

            if (top.State == EProcessingState.TopSearch &&
                TestFieldAttributeState(top, keyValue, out fieldIndex))
            {
                PushTypeAttributesToStack(typeof(T), Target);
            }
            else if (top.State == EProcessingState.FieldSearch &&
                     TestFieldAttributeState(top, keyValue, out fieldIndex))
            {
                PropertyInfo       prop   = top.Properties[fieldIndex];
                BlobFieldAttribute attrib = top.Attributes[fieldIndex];

                Type subType = prop.PropertyType;
                Type genericType;
                int  genericCount;

                if (subType.IsTypeListOrDictionary(out genericType, out genericCount))
                {
                    object subInstance = CacheUtil.FastConstruct(TypedCache, subType); //Activator.CreateInstance(subType);

                    prop.SetValue(top.WorkingType, subInstance, null);

                    PushListTypeAttributesToStack(subInstance, attrib, prop);
                }
                else if (attrib.Complex == true)
                {
                    object subInstance = CacheUtil.FastConstruct(TypedCache, subType); //Activator.CreateInstance(subType);

                    prop.SetValue(top.WorkingType, subInstance, null);

                    PushTypeAttributesToStack(subType, subInstance);
                }
                else if (attrib.SubFieldDepth > 0 ||
                         attrib.SubFieldKey != null)
                {
                    PushSubSearchAttributeToStack(top, attrib, prop, top.WorkingType);
                }
                else
                {
                    expectingIndex = fieldIndex;
                }
            }
            else if (top.State == EProcessingState.SubFieldSearch &&
                     TestSubFieldAttributeState(top, keyValue, out fieldIndex))
            {
                expectingIndex = fieldIndex;
            }
            else if (top.State == EProcessingState.EveryFieldSearch &&
                     depth - top.Depth == 1)
            {
                PropertyInfo prop = top.Properties[0];

                Type subType;
                int  genericCount;

                bool genericType = prop.PropertyType.IsTypeListOrDictionary(out subType, out genericCount);

                if (top.Attributes[0].Complex == true && genericType)
                {
                    object subInstance = CacheUtil.FastConstruct(TypedCache, subType); //Activator.CreateInstance(subType);

                    CacheUtil.HandleAddCall(prop, genericCount, top.WorkingType, keyValue, subInstance);

                    PushTypeAttributesToStack(subType, subInstance);
                }
                else if (fieldSize == 0 && genericType)
                {
                    // key is the actual field.
                    object value = GetDataForProp(key, subType);

                    CacheUtil.HandleAddCall(prop, genericCount, top.WorkingType, expectedKey, value);
                }
                else
                {
                    expectedKey    = keyValue;
                    expectingIndex = 0;
                }
            }
        }