Represents the base blob reader that can process a binary blob.
Наследование: IDisposable
Пример #1
0
        public object Read(Object target, BlobReader reader)
        {
            object[] args = new object[1];

            using (reader = reader.ReadFieldBlob())
            {
                while (reader.CanTakeBytes(BlobReader.FieldHeaderLength))
                {
                    reader.ReadFieldHeader();

                    // if there are no data bytes, we can "probably" assume that the keys are the values
                    if (reader.FieldDataBytes > 0)
                    {
                        args[0] = from.Read(target, reader);
                    }
                    else
                    {
                        // only handles ints, refactor this probably
                        args[0] = BitConverter.ToInt32(reader.ByteKey, 0);
                    }

                    add.Invoke(target, args);
                }

                reader.SkipSpare();
            }
            return null;
        }
Пример #2
0
        public object Read(Object target, BlobReader reader)
        {
            object[] args = new object[2];

            using (reader = reader.ReadFieldBlob())
            {
                while (reader.CanTakeBytes(BlobReader.FieldHeaderLength))
                {
                    reader.ReadFieldHeader();

                    switch (Type.GetTypeCode(leftType))
                    {
                        case TypeCode.Int32:
                            args[0] = BitConverter.ToInt32(reader.ByteKey, 0);
                            break;
                        case TypeCode.String:
                            args[0] = Encoding.ASCII.GetString(reader.ByteKey, 0, reader.FieldKeyBytes);
                            break;
                        default:
                            throw new NotImplementedException();
                    }

                    args[1] = from.Read(target, reader);
                    add.Invoke(target, args);
                }

                reader.SkipSpare();
            }

            return null;
        }
Пример #3
0
        public object Read(Object target, BlobReader reader)
        {
            if(target != null)
                reader = reader.ReadFieldBlob();

            object result = Activator.CreateInstance(targetType);

            read_field:
            while (reader.CanTakeBytes(BlobReader.FieldHeaderLength))
            {
                reader.ReadFieldHeader();

                for(int i = 0; i < fields.Length; i++)
                {
                    var field = fields[i];

                    if ((field.PeekIntKey != -1 && field.PeekIntKey == reader.PeekIntKey) || 
                        (field.ByteKey.Length == reader.FieldKeyBytes && BlobUtil.UnsafeCompare(field.ByteKey, reader.ByteKey)))
                    {
                        field.Serializer.Read(result, reader);
                        goto read_field;
                    }
                }

                reader.SkipField();
            }

            reader.SkipSpare();

            if (target != null)
                reader.Dispose();

            return result;
        }
Пример #4
0
        /// <summary>
        /// Deserialize a blob into a type. Does not JIT
        /// </summary>
        /// <param name="reader">Blob reader</param>
        /// <param name="type">Target type</param>
        /// <returns>Type model</returns>
        public static object DeserializeSlow(BlobReader reader, Type type)
        {
            TypeSerializer serializer = new TypeSerializer(type);

            using (reader)
            {
                return serializer.Read(null, reader);
            }
        }
Пример #5
0
        /// <summary>
        /// Deserialize a blob into a type
        /// </summary>
        /// <param name="reader">Blob reader</param>
        /// <param name="type">Target type</param>
        /// <returns>Type model</returns>
        public static object Deserialize(BlobReader reader, Type type)
        {
            TypeSerializer serializer = new TypeSerializer(type);
            JITContext.BlobDeserializer deserialize = JITContext.BuildDeserializer(serializer);

            using (reader)
            {
                return deserialize(reader, JITContext.ByteKeys.ToArray());
            }
        }
        public object Read(Object target, BlobReader reader)
        {
            if (from is ListSerializer || from is DictionarySerializer)
            {
                object value = Activator.CreateInstance(prop.PropertyType);
                prop.SetValue(target, value, null);
                from.Read(value, reader);
            }
            else
            {
                prop.SetValue(target, from.Read(target, reader), null);
            }

            return null;
        }
Пример #7
0
        public object Read(Object target, BlobReader reader)
        {
            if (from is ListSerializer || from is DictionarySerializer)
            {
                object value = Activator.CreateInstance(field.FieldType);
                field.SetValue(target, value);
                from.Read(value, reader);
            }
            else
            {
                field.SetValue(target, from.Read(target, reader));
            }

            return null;
        }
 public object Read(Object target, BlobReader reader)
 {
     return Encoding.UTF8.GetString(reader.ReadFieldStream().ReadBytesCached(reader.FieldDataBytes), 0, reader.FieldDataBytes - 1);
 }
Пример #9
0
 public object Read(Object target, BlobReader reader)
 {
     return reader.ReadFieldStream().ReadByte() > 0;
 }
 public object Read(Object target, BlobReader reader)
 {
     return new MicroTime(reader.ReadFieldStream().ReadUInt64());
 }
Пример #11
0
 public object Read(Object target, BlobReader reader)
 {
     return reader.ReadFieldStream().ReadUInt32();
 }
Пример #12
0
 public object Read(Object target, BlobReader reader)
 {
     return(reader.ReadFieldStream().ReadByte() > 0);
 }
Пример #13
0
 public object Read(Object target, BlobReader reader)
 {
     return(reader.ReadFieldStream().ReadUInt32());
 }