public object Deserialize(IParser parser, Type type)
        {
            if (parser == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            bool   flag   = parser.Allow <StreamStart>() != null;
            bool   flag2  = parser.Allow <DocumentStart>() != null;
            object result = null;

            if (!parser.Accept <DocumentEnd>() && !parser.Accept <StreamEnd>())
            {
                using (SerializerState serializerState = new SerializerState())
                {
                    result = valueDeserializer.DeserializeValue(parser, type, serializerState, valueDeserializer);
                    serializerState.OnDeserialization();
                }
            }
            if (flag2)
            {
                parser.Expect <DocumentEnd>();
            }
            if (flag)
            {
                parser.Expect <StreamEnd>();
            }
            return(result);
        }
Ejemplo n.º 2
0
        public object DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
        {
            NodeEvent nodeEvent     = parser.Peek <NodeEvent>();
            Type      typeFromEvent = GetTypeFromEvent(nodeEvent, expectedType);

            try
            {
                foreach (INodeDeserializer deserializer in deserializers)
                {
                    if (deserializer.Deserialize(parser, typeFromEvent, (IParser r, Type t) => nestedObjectDeserializer.DeserializeValue(r, t, state, nestedObjectDeserializer), out object value))
                    {
                        return(TypeConverter.ChangeType(value, expectedType));
                    }
                }
            }
            catch (YamlException)
            {
                throw;
            }
            catch (Exception innerException)
            {
                throw new YamlException(nodeEvent.Start, nodeEvent.End, "Exception during deserialization", innerException);
            }
            throw new YamlException(nodeEvent.Start, nodeEvent.End, $"No node deserializer was able to deserialize the node into type {expectedType.AssemblyQualifiedName}");
        }
Ejemplo n.º 3
0
 internal static void SerializeObject(Object obj, WriteOnlyDatagram datagram, SerializerState state)
 {
     if (obj == null)
     {
         datagram.WriteUInt((uint)SerializedTypeCode.Null, 8);
     }
     else if (obj is String)
     {
         datagram.WriteUInt((uint)SerializedTypeCode.String, 8);
         datagram.WriteString(obj as String);
     }
     else if (obj is MISP.ScriptList)
     {
         datagram.WriteUInt((uint)SerializedTypeCode.List, 8);
         var filteredList = new MISP.ScriptList(
             (obj as MISP.ScriptList).Where((o) => IsSerializableType(o)));
         datagram.WriteUInt((uint)filteredList.Count, 16);
         foreach (var item in filteredList)
             SerializeObject(item, datagram, state);
     }
     else if (obj is int)
     {
         datagram.WriteUInt((uint)SerializedTypeCode.Integer, 8);
         datagram.WriteUInt((uint)(obj as int?).Value, 32);
     }
     else if (obj is MISP.GenericScriptObject)
     {
         state.WriteObject(obj as MISP.GenericScriptObject, datagram);
     }
 }
        public PolymorphicComplexBuilder(Type type, SerializerState state)
        {
            _typeDescriptionsByHashCode = new AdaptiveHashtable <TypeDescriptionWithIndex>();
            var typeDescriptions = new Dictionary <int, TypeDescriptionWithIndex>();

            foreach (var description in state.GetDescriptionsForDerivedTypes(type))
            {
                _typeDescriptionsByHashCode.AddValue(
                    (uint)RuntimeHelpers.GetHashCode(description.Type),
                    new TypeDescriptionWithIndex
                {
                    Description = description
                });

                if (!typeDescriptions.ContainsKey(description.Type.GetHashCode()))
                {
                    typeDescriptions.Add(description.Type.GetHashCode(), new TypeDescriptionWithIndex
                    {
                        Description = description
                    });
                }
            }
            _typeDescriptionsByIndex = new TypeDescription[typeDescriptions.Count];
            var index = (byte)0;

            foreach (var item in typeDescriptions)
            {
                item.Value.Index = index;
                var val = _typeDescriptionsByHashCode.TryGetValue((uint)RuntimeHelpers.GetHashCode(item.Value.Description.Type));
                Debug.Assert(val != null, "Type should exist in the type descriptions hash");
                val.Index = index;
                _typeDescriptionsByIndex[index++] = item.Value.Description;
            }
        }
Ejemplo n.º 5
0
 public static void EnsureAllocated(SerializerState serializer)
 {
     if (!serializer.IsAllocated)
     {
         throw new InvalidOperationException("Call Init() first");
     }
 }
Ejemplo n.º 6
0
        public object?DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
        {
            parser.Accept <NodeEvent>(out var nodeEvent);
            var nodeType = GetTypeFromEvent(nodeEvent, expectedType);

            try
            {
                foreach (var deserializer in deserializers)
                {
                    if (deserializer.Deserialize(parser, nodeType, (r, t) => nestedObjectDeserializer.DeserializeValue(r, t, state, nestedObjectDeserializer), out var value))
                    {
                        return(TypeConverter.ChangeType(value, expectedType));
                    }
                }
            }
            catch (YamlException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new YamlException(
                          nodeEvent?.Start ?? Mark.Empty,
                          nodeEvent?.End ?? Mark.Empty,
                          "Exception during deserialization",
                          ex
                          );
            }

            throw new YamlException(
                      nodeEvent?.Start ?? Mark.Empty,
                      nodeEvent?.End ?? Mark.Empty,
                      $"No node deserializer was able to deserialize the node into type {expectedType.AssemblyQualifiedName}"
                      );
        }
Ejemplo n.º 7
0
 public static void Deserialize(MISP.GenericScriptObject into, ReadOnlyDatagram from, Database database)
 {
     var state = new SerializerState();
     state.referencedObjects.Add(0, into);
     while (from.More)
         impleDeserialize(from, state, database);
 }
Ejemplo n.º 8
0
        public object DeserializeValue(EventReader reader, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
        {
            var nodeEvent = reader.Peek <NodeEvent>();

            var nodeType = GetTypeFromEvent(nodeEvent, expectedType);

            try
            {
                foreach (var deserializer in deserializers)
                {
                    object value;
                    if (deserializer.Deserialize(reader, nodeType, (r, t) => nestedObjectDeserializer.DeserializeValue(r, t, state, nestedObjectDeserializer), out value))
                    {
                        return(value);
                    }
                }
            }
            catch (YamlException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new YamlException(nodeEvent.Start, nodeEvent.End, "Exception during deserialization", ex);
            }

            throw new YamlException(
                      nodeEvent.Start,
                      nodeEvent.End,
                      string.Format(
                          "No node deserializer was able to deserialize the node into type {0}",
                          expectedType.AssemblyQualifiedName
                          )
                      );
        }
Ejemplo n.º 9
0
        public void InterceptClientSideShortCall()
        {
            var policy = new MyPolicy("a");

            (var server, var client) = SetupClientServerPair();

            using (server)
                using (client)
                {
                    //client.WhenConnected.Wait();

                    var counters = new Counters();
                    server.Main = new TestInterfaceImpl(counters);
                    using (var main = policy.Attach(client.GetMain <ITestInterface>()))
                    {
                        var request1 = main.Foo(321, false, default);
                        Assert.IsTrue(policy.Calls.TryReceive(out var cc));
                        Assert.IsFalse(request1.IsCompleted);

                        var rw = SerializerState.CreateForRpc <Capnproto_test.Capnp.Test.TestInterface.Result_Foo.WRITER>();
                        rw.X       = "bar";
                        cc.OutArgs = rw;

                        cc.ReturnToAlice();

                        Assert.IsTrue(request1.IsCompleted);

                        Assert.AreEqual("bar", request1.Result);
                    }
                }
        }
Ejemplo n.º 10
0
        public object DeserializeValue(EventReader reader, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
        {
            var nodeEvent = reader.Peek<NodeEvent>();

            var nodeType = GetTypeFromEvent(nodeEvent, expectedType);

            try
            {
                foreach (var deserializer in deserializers)
                {
                    object value;
                    if (deserializer.Deserialize(reader, nodeType, (r, t) => nestedObjectDeserializer.DeserializeValue(r, t, state, nestedObjectDeserializer), out value))
                    {
                        return value;
                    }
                }
            }
            catch (YamlException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new YamlException(nodeEvent.Start, nodeEvent.End, "Exception during deserialization", ex);
            }

            throw new YamlException(
                nodeEvent.Start,
                nodeEvent.End,
                string.Format(
                    "No node deserializer was able to deserialize the node into type {0}",
                    expectedType.AssemblyQualifiedName
                )
            );
        }
Ejemplo n.º 11
0
        public object Deserialize(EventReader reader, Type type)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            bool   flag  = reader.Allow <StreamStart>() != null;
            bool   flag2 = reader.Allow <DocumentStart>() != null;
            object obj2  = null;

            if (!reader.Accept <DocumentEnd>() && !reader.Accept <StreamEnd>())
            {
                using (SerializerState state = new SerializerState())
                {
                    obj2 = this.valueDeserializer.DeserializeValue(reader, type, state, this.valueDeserializer);
                    state.OnDeserialization();
                }
            }
            if (flag2)
            {
                reader.Expect <DocumentEnd>();
            }
            if (flag)
            {
                reader.Expect <StreamEnd>();
            }
            return(obj2);
        }
Ejemplo n.º 12
0
        public void DeserializerStateBadConv()
        {
            SerializerState s = null;

            Assert.ThrowsException <ArgumentNullException>(() => (DeserializerState)s);
            s = new DynamicSerializerState();
            Assert.ThrowsException <InvalidOperationException>(() => (DeserializerState)s);
        }
Ejemplo n.º 13
0
        async Task <AnswerOrCounterquestion> MethodA(DeserializerState d_, CancellationToken cancellationToken_)
        {
            var in_ = CapnpSerializable.Create <CapnpGen.GenericA <TT> .Params_methodA>(d_);
            await Impl.MethodA(in_.Param1, cancellationToken_);

            var s_ = SerializerState.CreateForRpc <CapnpGen.GenericA <TT> .Result_methodA.WRITER>();

            return(s_);
        }
Ejemplo n.º 14
0
        async Task <AnswerOrCounterquestion> Stop(DeserializerState d_, CancellationToken cancellationToken_)
        {
            using (d_)
            {
                await Impl.Stop(cancellationToken_);

                var s_ = SerializerState.CreateForRpc <Mas.Schema.Service.Admin.Result_Stop.WRITER>();
                return(s_);
            }
        }
Ejemplo n.º 15
0
        async Task <AnswerOrCounterquestion> SetTimeout(DeserializerState d_, CancellationToken cancellationToken_)
        {
            using (d_)
            {
                var in_ = CapnpSerializable.Create <Mas.Schema.Service.Admin.Params_SetTimeout>(d_);
                await Impl.SetTimeout(in_.Seconds, cancellationToken_);

                var s_ = SerializerState.CreateForRpc <Mas.Schema.Service.Admin.Result_SetTimeout.WRITER>();
                return(s_);
            }
        }
Ejemplo n.º 16
0
        async Task <AnswerOrCounterquestion> UpdateIdentity(DeserializerState d_, CancellationToken cancellationToken_)
        {
            using (d_)
            {
                var in_ = CapnpSerializable.Create <Mas.Schema.Service.Admin.Params_UpdateIdentity>(d_);
                await Impl.UpdateIdentity(in_.OldId, in_.NewInfo, cancellationToken_);

                var s_ = SerializerState.CreateForRpc <Mas.Schema.Service.Admin.Result_UpdateIdentity.WRITER>();
                return(s_);
            }
        }
Ejemplo n.º 17
0
        async Task <AnswerOrCounterquestion> SetupPorts(DeserializerState d_, CancellationToken cancellationToken_)
        {
            using (d_)
            {
                var in_ = CapnpSerializable.Create <Mas.Schema.Fbp.Component.Params_SetupPorts>(d_);
                await Impl.SetupPorts(in_.InPorts, in_.OutPorts, cancellationToken_);

                var s_ = SerializerState.CreateForRpc <Mas.Schema.Fbp.Component.Result_SetupPorts.WRITER>();
                return(s_);
            }
        }
Ejemplo n.º 18
0
        internal override MemberDescription[] GetDescriptions(SerializerState state)
        {
            var piMap = Type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance)
                        .ToDictionary(pi => pi.Name);

            return(Type.GetTypeInfo().GetConstructors()[0]
                   .GetParameters()
                   .Select(p => new PropertyDescription(piMap[p.Name], state)
            {
                NestedTypeDescription = Serializer.GetTypeDescription(p.ParameterType, state)
            }).ToArray());
        }
Ejemplo n.º 19
0
        public static WriteOnlyDatagram Serialize(MISP.ScriptObject obj)
        {
            var r = new WriteOnlyDatagram();
            var state = new SerializerState();
            state.referencedObjects.Add(obj);
            state.referencedObjectsIDs.Add(obj, 0);

            for (int i = 0; i < state.referencedObjects.Count; ++i)
                impleSerialize(state.referencedObjects[i], i, r, state);

            return r;
        }
Ejemplo n.º 20
0
 internal TypeDescription(ushort typeId, Type type, SerializerState state)
 {
     TypeId         = typeId;
     Type           = type;
     _isInitialized = new Lazy <bool>(() =>
     {
         InitDescriptions(state);
         InitSerializers();
         InitDeserializer();
         return(true);
     });
 }
Ejemplo n.º 21
0
        public object DeserializeValue(EventReader reader, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
        {
            object value;
            var    alias = reader.Allow <AnchorAlias>();

            if (alias != null)
            {
                var          aliasState = state.Get <AliasState>();
                ValuePromise valuePromise;
                if (!aliasState.TryGetValue(alias.Value, out valuePromise))
                {
                    valuePromise = new ValuePromise(alias);
                    aliasState.Add(alias.Value, valuePromise);
                }

                return(valuePromise.HasValue ? valuePromise.Value : valuePromise);
            }

            string anchor = null;

            var nodeEvent = reader.Peek <NodeEvent>();

            if (nodeEvent != null && !string.IsNullOrEmpty(nodeEvent.Anchor))
            {
                anchor = nodeEvent.Anchor;
            }

            value = innerDeserializer.DeserializeValue(reader, expectedType, state, nestedObjectDeserializer);

            if (anchor != null)
            {
                var aliasState = state.Get <AliasState>();

                ValuePromise valuePromise;
                if (!aliasState.TryGetValue(anchor, out valuePromise))
                {
                    aliasState.Add(anchor, new ValuePromise(value));
                }
                else if (!valuePromise.HasValue)
                {
                    valuePromise.Value = value;
                }
                else
                {
                    throw new DuplicateAnchorException(nodeEvent.Start, nodeEvent.End, string.Format(
                                                           "Anchor '{0}' already defined",
                                                           anchor
                                                           ));
                }
            }

            return(value);
        }
Ejemplo n.º 22
0
            /// <summary>
            /// AWARENESS: not thread safe
            /// </summary>
            /// <param name="reader"></param>
            /// <param name="expectedType"></param>
            /// <param name="state"></param>
            /// <param name="nestedObjectDeserializer"></param>
            /// <returns></returns>
            public object DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
            {
                object value = _innerDeserializer.DeserializeValue(parser, expectedType, state, nestedObjectDeserializer);

                if (value is string str && str.Trim() == Constants.ContentPlaceholder)
                {
                    ContainPlaceholder = true;
                    return(_replacer);
                }

                return(value);
            }
Ejemplo n.º 23
0
        public async Task <Mas.Schema.Common.IdInformation> Info(CancellationToken cancellationToken_ = default)
        {
            var in_  = SerializerState.CreateForRpc <Mas.Schema.Common.Identifiable.Params_Info.WRITER>();
            var arg_ = new Mas.Schema.Common.Identifiable.Params_Info()
            {
            };

            arg_?.serialize(in_);
            using (var d_ = await Call(12875740530987518165UL, 0, in_.Rewrap <DynamicSerializerState>(), false, cancellationToken_).WhenReturned)
            {
                var r_ = CapnpSerializable.Create <Mas.Schema.Common.IdInformation>(d_);
                return(r_);
            }
        }
Ejemplo n.º 24
0
            public SerializerState(SerializationSettings settings, SerializerState previousState)
            {
                this.PreviousState = previousState;

                this.Settings         = settings;
                this.Buffer           = BufferPool.Retain();
                this.ObjectReferences = new Dictionary <object, int>();
                this.ObjectInstances  = new List <object>();

                this.IsText           = Settings.Flags.HasFlag(SerializationFlags.Text);
                this.WriteOnlyChanged = settings.Flags.HasFlag(SerializationFlags.WriteOnlyChanged);
                this.LocalOffset      = Int32.MaxValue;
                Retain();
            }
Ejemplo n.º 25
0
        public async Task <IReadOnlyList <Mas.Schema.Common.IdInformation> > Identities(CancellationToken cancellationToken_ = default)
        {
            var in_  = SerializerState.CreateForRpc <Mas.Schema.Service.Admin.Params_Identities.WRITER>();
            var arg_ = new Mas.Schema.Service.Admin.Params_Identities()
            {
            };

            arg_?.serialize(in_);
            using (var d_ = await Call(18357226832451728969UL, 3, in_.Rewrap <DynamicSerializerState>(), false, cancellationToken_).WhenReturned)
            {
                var r_ = CapnpSerializable.Create <Mas.Schema.Service.Admin.Result_Identities>(d_);
                return(r_.Infos);
            }
        }
Ejemplo n.º 26
0
        public async Task <Mas.Schema.Crop.Cultivar> Cultivar(CancellationToken cancellationToken_ = default)
        {
            var in_  = SerializerState.CreateForRpc <Mas.Schema.Crop.Crop.Params_Cultivar.WRITER>();
            var arg_ = new Mas.Schema.Crop.Crop.Params_Cultivar()
            {
            };

            arg_?.serialize(in_);
            using (var d_ = await Call(16757216515467467908UL, 1, in_.Rewrap <DynamicSerializerState>(), false, cancellationToken_).WhenReturned)
            {
                var r_ = CapnpSerializable.Create <Mas.Schema.Crop.Crop.Result_Cultivar>(d_);
                return(r_.Cult);
            }
        }
Ejemplo n.º 27
0
        public async Task Stop(CancellationToken cancellationToken_ = default)
        {
            var in_  = SerializerState.CreateForRpc <Mas.Schema.Fbp.Component.Params_Stop.WRITER>();
            var arg_ = new Mas.Schema.Fbp.Component.Params_Stop()
            {
            };

            arg_?.serialize(in_);
            using (var d_ = await Call(15499137556701095600UL, 1, in_.Rewrap <DynamicSerializerState>(), false, cancellationToken_).WhenReturned)
            {
                var r_ = CapnpSerializable.Create <Mas.Schema.Fbp.Component.Result_Stop>(d_);
                return;
            }
        }
Ejemplo n.º 28
0
        Task <AnswerOrCounterquestion> Save(DeserializerState d_, CancellationToken cancellationToken_)
        {
            using (d_)
            {
                return(Impatient.MaybeTailCall(Impl.Save(CapnpSerializable.Create <Capnp.Persistent <TSturdyRef, TOwner> .SaveParams>(d_), cancellationToken_), r_ =>
                {
                    var s_ = SerializerState.CreateForRpc <Capnp.Persistent <TSturdyRef, TOwner> .SaveResults.WRITER>();
                    r_.serialize(s_);
                    return s_;
                }

                                               ));
            }
        }
Ejemplo n.º 29
0
        public object DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
        {
            object value;
            var    alias = parser.Allow <AnchorAlias>();

            if (alias != null)
            {
                var          aliasState = state.Get <AliasState>();
                ValuePromise valuePromise;
                if (!aliasState.TryGetValue(alias.Value, out valuePromise))
                {
                    valuePromise = new ValuePromise(alias);
                    aliasState.Add(alias.Value, valuePromise);
                }

                return(valuePromise.HasValue ? valuePromise.Value : valuePromise);
            }

            string anchor = null;

            var nodeEvent = parser.Peek <NodeEvent>();

            if (nodeEvent != null && !string.IsNullOrEmpty(nodeEvent.Anchor))
            {
                anchor = nodeEvent.Anchor;
            }

            value = innerDeserializer.DeserializeValue(parser, expectedType, state, nestedObjectDeserializer);

            if (anchor != null)
            {
                var aliasState = state.Get <AliasState>();

                ValuePromise valuePromise;
                if (!aliasState.TryGetValue(anchor, out valuePromise))
                {
                    aliasState.Add(anchor, new ValuePromise(value));
                }
                else if (!valuePromise.HasValue)
                {
                    valuePromise.Value = value;
                }
                else
                {
                    aliasState[anchor] = new ValuePromise(value);
                }
            }

            return(value);
        }
Ejemplo n.º 30
0
        internal override void InitDescriptions(SerializerState state)
        {
            _descriptions = GetDescriptions(state);
            _orderMapping = new Dictionary <string, int>();
            for (var i = 0; i < _descriptions.Length; i++)
            {
                _orderMapping[_descriptions[i].Name] = i;
            }

            foreach (var description in _descriptions)
            {
                description.NestedTypeDescription?.InitDescriptions(state);
            }
        }
Ejemplo n.º 31
0
        private void KeepOriginalState(SerializerState state, byte[] bytes)
        {
            if (this.OriginalState != null)
            {
                this.OriginalState.Release();
            }
            this.OriginalState = state;
            if (this.OriginalState != null)
            {
                this.OriginalState.Retain();
            }

            this.OriginalBytes = bytes;
        }
Ejemplo n.º 32
0
        Task <AnswerOrCounterquestion> MethodA(DeserializerState d_, CancellationToken cancellationToken_)
        {
            return(Impatient.MaybeTailCall(Impl.MethodA(cancellationToken_), result =>
            {
                var s_ = SerializerState.CreateForRpc <CapnpGen.Issue25A.Result_methodA.WRITER>();
                var r_ = new CapnpGen.Issue25A.Result_methodA {
                    Result = result
                };
                r_.serialize(s_);
                return s_;
            }

                                           ));
        }
Ejemplo n.º 33
0
        public async Task Stop(CancellationToken cancellationToken_ = default)
        {
            var in_  = SerializerState.CreateForRpc <Mas.Schema.Service.Admin.Params_Stop.WRITER>();
            var arg_ = new Mas.Schema.Service.Admin.Params_Stop()
            {
            };

            arg_?.serialize(in_);
            using (var d_ = await Call(18357226832451728969UL, 2, in_.Rewrap <DynamicSerializerState>(), false, cancellationToken_).WhenReturned)
            {
                var r_ = CapnpSerializable.Create <Mas.Schema.Service.Admin.Result_Stop>(d_);
                return;
            }
        }
Ejemplo n.º 34
0
            /// <summary>
            /// AWARENESS: not thread safe
            /// </summary>
            /// <param name="reader"></param>
            /// <param name="expectedType"></param>
            /// <param name="state"></param>
            /// <param name="nestedObjectDeserializer"></param>
            /// <returns></returns>
            public object DeserializeValue(EventReader reader, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
            {
                object value = _innerDeserializer.DeserializeValue(reader, expectedType, state, nestedObjectDeserializer);

                var str = value as string;

                if (str != null && str.Trim() == Constants.ContentPlaceholder)
                {
                    ContainPlaceholder = true;
                    return(_replacer);
                }

                return(value);
            }
Ejemplo n.º 35
0
        internal static void impleSerialize(MISP.ScriptObject obj, int index, WriteOnlyDatagram datagram, SerializerState state)
        {
            datagram.WriteUInt((uint)index, 16);

            var propList = obj.ListProperties();
            var filteredList = new List<Object>(
                propList.Where((o) => { return IsSerializableType(obj.GetLocalProperty(o as String)); }));

            datagram.WriteUInt((uint)filteredList.Count, 16);
            foreach (var item in filteredList)
            {
                datagram.WriteString(item as String);
                SerializeObject(obj.GetLocalProperty(item as String), datagram, state);
            }
        }
Ejemplo n.º 36
0
		public object DeserializeValue (EventReader reader, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
		{
			var nodeEvent = reader.Peek<NodeEvent>();

			var nodeType = GetTypeFromEvent(nodeEvent, expectedType);

			foreach (var deserializer in deserializers)
			{
				object value;
				if (deserializer.Deserialize(reader, nodeType, (r, t) => nestedObjectDeserializer.DeserializeValue(r, t, state, nestedObjectDeserializer), out value))
				{
					return value;
				}
			}

			throw new SerializationException(
				string.Format(
					"No node deserializer was able to deserialize the node at {0} into type {1}",
					reader.Parser.Current.Start,
					expectedType.AssemblyQualifiedName
				)
			);
		}
Ejemplo n.º 37
0
        internal static void impleDeserialize(ReadOnlyDatagram datagram, SerializerState state, Database database)
        {
            uint index = 0;
            if (!datagram.ReadUInt(out index, 16)) throw new DeserializeError();
            MISP.GenericScriptObject into = null;
            if (state.referencedObjects.ContainsKey(index)) into = state.referencedObjects[index];
            else
            {
                into = new MISP.GenericScriptObject();
                state.referencedObjects.Add(index, into);
            }

            uint propertyCount = 0;
            if (!datagram.ReadUInt(out propertyCount, 16)) throw new DeserializeError();
            for (int i = 0; i < propertyCount; ++i)
            {
                String propertyName = "";
                Object value = null;
                if (!datagram.ReadString(out propertyName)) throw new DeserializeError();
                value = DeserializeObject(datagram, state, database);
                into.SetProperty(propertyName, value);
            }
        }
Ejemplo n.º 38
0
 internal static Object DeserializeObject(ReadOnlyDatagram datagram, SerializerState state, Database database)
 {
     uint rawTypeCode = 0;
     if (!datagram.ReadUInt(out rawTypeCode, 8)) throw new DeserializeError();
     switch ((SerializedTypeCode)rawTypeCode)
     {
         case SerializedTypeCode.Null:
             return null;
         case SerializedTypeCode.Integer:
             {
                 uint value = 0;
                 if (!datagram.ReadUInt(out value, 32)) throw new DeserializeError();
                 return (int)value;
             }
         case SerializedTypeCode.String:
             {
                 String value = "";
                 if (!datagram.ReadString(out value)) throw new DeserializeError();
                 return value;
             }
         case SerializedTypeCode.List:
             {
                 uint length = 0;
                 if (!datagram.ReadUInt(out length, 16)) throw new DeserializeError();
                 var result = new MISP.ScriptList();
                 for (int i = 0; i < length; ++i)
                     result.Add(DeserializeObject(datagram, state, database));
                 return result;
             }
         case SerializedTypeCode.InternalObject:
             return state.ReadObject(datagram, SerializedTypeCode.InternalObject, database);
         case SerializedTypeCode.NamedObject:
             return state.ReadObject(datagram, SerializedTypeCode.NamedObject, database);
         default:
             throw new DeserializeError();
     }
 }