public void EmitRead(JITContext context)
 {
     context.LoadBlobReader();
     context.ReadFieldStream();
     context.EmitStreamCall("ReadUInt64");
     context.CreateType(typeof(MicroTime), CtorParams);
 }
 public void EmitRead(JITContext context)
 {
     context.LoadBlobReader();
     context.ReadFieldStream();
     context.EmitStreamCall("ReadUInt64");
     context.CreateType(typeof(MicroTime), CtorParams);
 }
Esempio n. 3
0
 public void EmitRead(JITContext context)
 {
     context.LoadBlobReader();
     context.ReadFieldStream();
     context.EmitStreamCall("ReadByte");
     context.CompareGreaterThanZero();
 }
Esempio n. 4
0
 public void EmitRead(JITContext context)
 {
     context.LoadBlobReader();
     context.ReadFieldStream();
     context.EmitStreamCall("ReadByte");
     context.CompareGreaterThanZero();
 }
Esempio n. 5
0
        public void EmitRead(JITContext context)
        {
            LocalBuilder top = context.PeekTypeDef();

            if (top != null)
            {
                context.ReadFieldBlob();
                context.PushType(typeof(BlobReader));
            }

            context.CreateType(targetType);
            context.PushType(targetType);
            context.PushTypeDef(context.PeekTop(targetType));

            Label readField = context.CreateLabel();
            Label cleanup   = context.CreateLabel();

            context.MarkLabel(readField);
            context.CanReadBytes(BlobReader.FieldHeaderLength);
            context.GotoWhenFalse(cleanup);

            context.ReadFieldHeader();

            for (int i = 0; i < fields.Length; i++)
            {
                Label nextField = context.CreateLabel();

                if (fields[i].PeekIntKey != -1)
                {
                    context.EmitKeyPeekTest(fields[i].PeekIntKey, nextField);
                }
                else
                {
                    context.EmitKeyTest(fields[i].ByteKey, nextField);
                }

                fields[i].Serializer.EmitRead(context);

                context.Goto(readField);
                context.MarkLabel(nextField);
            }

            context.SkipField();
            context.Goto(readField);

            context.MarkLabel(cleanup);
            context.SkipSpare();

            if (top != null)
            {
                context.DisposeReaderOnTop();
                context.PopType(typeof(BlobReader));
            }

            context.LoadLocal(context.PeekTypeDef());
            context.PopTypeDef();
            context.PopType(targetType);
        }
Esempio n. 6
0
        public static BlobDeserializer BuildDeserializer(IBlobSerializer source)
        {
            JITContext ctx = new JITContext(source.ExpectedType);

            source.EmitRead(ctx);
            ctx.Return();

            return((BlobDeserializer)ctx.method.CreateDelegate(typeof(BlobDeserializer)));
        }
Esempio n. 7
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 void EmitRead(JITContext context)
 {
     context.PushUTF8Encoding();
     context.ReadFieldStream();
     context.GetFieldDataBytes();
     context.EmitStreamCall("ReadBytesCached");
     context.LoadIntConstant(0);
     context.GetFieldDataBytes();
     context.LoadIntConstant(1);
     context.Subtract();
     context.ByteConvertToString();
 }
Esempio n. 9
0
 public void EmitRead(JITContext context)
 {
     context.PushUTF8Encoding();
     context.ReadFieldStream();
     context.GetFieldDataBytes();
     context.EmitStreamCall("ReadBytesCached");
     context.LoadIntConstant(0);
     context.GetFieldDataBytes();
     context.LoadIntConstant(1);
     context.Subtract();
     context.ByteConvertToString();
 }
Esempio n. 10
0
        public void EmitRead(JITContext context)
        {
            context.ReadFieldBlob();
            context.PushType(typeof(BlobReader));

            Label readField = context.CreateLabel();
            Label cleanup   = context.CreateLabel();

            context.MarkLabel(readField);
            context.CanReadBytes(BlobReader.FieldHeaderLength);
            context.GotoWhenFalse(cleanup);

            context.ReadFieldHeader();

            context.LoadLocal(context.PeekTypeDef());

            switch (Type.GetTypeCode(leftType))
            {
            case TypeCode.Int32:
                context.LoadByteKey();
                context.LoadIntConstant(0);
                context.BitConvertTo("Int32");
                break;

            case TypeCode.String:
                context.PushUTF8Encoding();
                context.LoadByteKey();
                context.LoadIntConstant(0);
                context.GetFieldKeyBytes();
                context.ByteConvertToString();
                break;

            default:
                throw new NotImplementedException();
            }

            from.EmitRead(context);
            context.EmitCall(add);
            context.Goto(readField);

            context.MarkLabel(cleanup);
            context.SkipSpare();

            context.DisposeReaderOnTop();
            context.PopType(typeof(BlobReader));
        }
Esempio n. 11
0
        public void EmitRead(JITContext context)
        {
            context.ReadFieldBlob();
            context.PushType(typeof(BlobReader));

            Label readField = context.CreateLabel();
            Label cleanup = context.CreateLabel();

            context.MarkLabel(readField);
            context.CanReadBytes(BlobReader.FieldHeaderLength);
            context.GotoWhenFalse(cleanup);

            context.ReadFieldHeader();

            context.LoadLocal(context.PeekTypeDef());

            switch (Type.GetTypeCode(leftType))
            {
                case TypeCode.Int32:
                    context.LoadByteKey();
                    context.LoadIntConstant(0);
                    context.BitConvertTo("Int32");
                    break;
                case TypeCode.String:
                    context.PushUTF8Encoding();
                    context.LoadByteKey();
                    context.LoadIntConstant(0);
                    context.GetFieldKeyBytes();
                    context.ByteConvertToString();
                    break;
                default:
                    throw new NotImplementedException();
            }

            from.EmitRead(context);
            context.EmitCall(add);
            context.Goto(readField);
           
            context.MarkLabel(cleanup);
            context.SkipSpare();

            context.DisposeReaderOnTop();
            context.PopType(typeof(BlobReader));
        }
Esempio n. 12
0
        public void EmitRead(JITContext context)
        {
            context.ReadFieldBlob();
            context.PushType(typeof(BlobReader));

            Label readField = context.CreateLabel();
            Label cleanup = context.CreateLabel();

            context.MarkLabel(readField);
            context.CanReadBytes(BlobReader.FieldHeaderLength);
            context.GotoWhenFalse(cleanup);

            context.ReadFieldHeader();

            context.LoadLocal(context.PeekTypeDef());

            // is this a safe optimization?
            if (from.ExpectedType.IsValueType)
            {
                context.LoadByteKey();
                context.LoadIntConstant(0);
                context.BitConvertTo("Int32");
                context.EmitCall(add);
                context.Goto(readField);
            }
            else
            {
                from.EmitRead(context);
                context.EmitCall(add);
                context.Goto(readField);
            }

            context.MarkLabel(cleanup);
            context.SkipSpare();

            context.DisposeReaderOnTop();
            context.PopType(typeof(BlobReader));
        }
Esempio n. 13
0
        public void EmitRead(JITContext context)
        {
            context.ReadFieldBlob();
            context.PushType(typeof(BlobReader));

            Label readField = context.CreateLabel();
            Label cleanup   = context.CreateLabel();

            context.MarkLabel(readField);
            context.CanReadBytes(BlobReader.FieldHeaderLength);
            context.GotoWhenFalse(cleanup);

            context.ReadFieldHeader();

            context.LoadLocal(context.PeekTypeDef());

            // is this a safe optimization?
            if (from.ExpectedType.IsValueType)
            {
                context.LoadByteKey();
                context.LoadIntConstant(0);
                context.BitConvertTo("Int32");
                context.EmitCall(add);
                context.Goto(readField);
            }
            else
            {
                from.EmitRead(context);
                context.EmitCall(add);
                context.Goto(readField);
            }

            context.MarkLabel(cleanup);
            context.SkipSpare();

            context.DisposeReaderOnTop();
            context.PopType(typeof(BlobReader));
        }
Esempio n. 14
0
        public void EmitRead(JITContext context)
        {
            context.LoadLocal(context.PeekTypeDef());

            if (from is ListSerializer || from is DictionarySerializer)
            {
                context.CreateType(field.FieldType);
                context.PushType(field.FieldType);
                context.PushTypeDef(context.PeekTop(field.FieldType));

                context.LoadLocal(context.PeekTop(field.FieldType));
                context.StoreField(field);

                from.EmitRead(context);
                context.PopTypeDef();
                context.PopType(field.FieldType);
            }
            else
            {
                from.EmitRead(context);
                context.StoreField(field);
            }
        }
        public void EmitRead(JITContext context)
        {
            context.LoadLocal(context.PeekTypeDef());

            if (from is ListSerializer || from is DictionarySerializer)
            {
                context.CreateType(prop.PropertyType);
                context.PushType(prop.PropertyType);
                context.PushTypeDef(context.PeekTop(prop.PropertyType));

                context.LoadLocal(context.PeekTop(prop.PropertyType));
                context.StoreProp(prop);

                from.EmitRead(context);
                context.PopTypeDef();
                context.PopType(prop.PropertyType);
            }
            else
            {
                from.EmitRead(context);
                context.StoreProp(prop);
            }
        }
Esempio n. 16
0
 public void EmitRead(JITContext context)
 {
     context.LoadBlobReader();
     context.ReadFieldStream();
     context.StreamRead(2, "Int16");
 }
Esempio n. 17
0
        public static BlobDeserializer BuildDeserializer(IBlobSerializer source)
        {
            JITContext ctx = new JITContext(source.ExpectedType);

            source.EmitRead(ctx);
            ctx.Return();

            return (BlobDeserializer)ctx.method.CreateDelegate(typeof(BlobDeserializer));
        }
Esempio n. 18
0
 public void EmitRead(JITContext context)
 {
     context.LoadBlobReader();
     context.ReadFieldStream();
     context.StreamRead(4, "UInt32");
 }
Esempio n. 19
0
 public void EmitRead(JITContext context)
 {
     context.LoadBlobReader();
     context.ReadFieldStream();
     context.StreamRead(2, "Int16");
 }
Esempio n. 20
0
 public void EmitRead(JITContext context)
 {
     context.LoadBlobReader();
     context.ReadFieldStream();
     context.StreamRead(4, "UInt32");
 }
Esempio n. 21
0
        public void EmitRead(JITContext context)
        {
            LocalBuilder top = context.PeekTypeDef();
            if (top != null)
            {
                context.ReadFieldBlob();
                context.PushType(typeof(BlobReader));
            }

            context.CreateType(targetType);
            context.PushType(targetType);
            context.PushTypeDef(context.PeekTop(targetType));

            Label readField = context.CreateLabel();
            Label cleanup = context.CreateLabel();

            context.MarkLabel(readField);
            context.CanReadBytes(BlobReader.FieldHeaderLength);
            context.GotoWhenFalse(cleanup);

            context.ReadFieldHeader();

            for (int i = 0; i < fields.Length; i++)
            {
                Label nextField = context.CreateLabel();

                if (fields[i].PeekIntKey != -1)
                {
                    context.EmitKeyPeekTest(fields[i].PeekIntKey, nextField);
                }
                else
                {
                    context.EmitKeyTest(fields[i].ByteKey, nextField);
                }

                fields[i].Serializer.EmitRead(context);

                context.Goto(readField);
                context.MarkLabel(nextField);
            }

            context.SkipField();
            context.Goto(readField);

            context.MarkLabel(cleanup);
            context.SkipSpare();

            if (top != null)
            {
                context.DisposeReaderOnTop();
                context.PopType(typeof(BlobReader));
            }

            context.LoadLocal(context.PeekTypeDef());
            context.PopTypeDef();
            context.PopType(targetType);
        }
Esempio n. 22
0
 public void EmitRead(JITContext context)
 {
     context.ReadFieldStream();
     context.EmitStreamCall("ReadUInt16");
 }
Esempio n. 23
0
 public void EmitRead(JITContext context)
 {
     context.ReadFieldStream();
     context.EmitStreamCall("ReadUInt32");
 }