public ProtobufMessageSerializer(IEnumerable<Message> messages, IEnumerable<MessageHeader> headers)
        {
            _model = TypeModel.Create();
            _model.AllowParseableTypes = true;
            _model[typeof(Message)].UseConstructor = false;

            foreach (var message in messages)
            {
                if (message.GetType() == typeof(Message))
                    continue;

                var type = message.GetType();
                _model[typeof(Message)].AddSubType(GenerateId(type), type);
                _model[type].UseConstructor = false;
            }


            _model[typeof(MessageHeader)].UseConstructor = false;

            foreach (var header in headers)
            {
                if (header.GetType() == typeof(MessageHeader))
                    continue;

                var type = header.GetType();
                _model[typeof(MessageHeader)].AddSubType(GenerateId(type), type);
                _model[type].UseConstructor = false;
            }

            _model.CompileInPlace();
        }
		protected CoreTestBase()
		{
			_runtimeModel = ProtoBufNetFactory.GenerateTypeModel();
			_runtimeModel.AutoCompile = false;

			_compileInPlaceModel = ProtoBufNetFactory.GenerateTypeModel();
			_compileInPlaceModel.AutoCompile = false;
			_compileInPlaceModel.CompileInPlace();

			//_compileModel = ProtoBufNetFactory.GenerateTypeModel().Compile("TestYo", @"TestYo.dll");
		}
Example #3
0
        static ProtobufSerializer2()
        {
            model.DynamicTypeFormatting += (sender, args) =>
            {
                if (args.FormattedName == null)
                {
                    return;
                }

                if (Type.GetType(args.FormattedName) == null)
                {
                    args.Type = typeof(NilContainer);
                }
            };

#if UNITY_EDITOR
            model.CompileInPlace();
#endif
        }
        public ProtobufMessageSerializer(params Assembly[] protocolAssemblies)
        {
            var types = protocolAssemblies.SelectMany(assembly => assembly.GetTypes());
            _model = TypeModel.Create();
            _model.AllowParseableTypes = true;
            _model[typeof(Message)].UseConstructor = false;

            foreach (var type in types.Where(t => typeof(Message).IsAssignableFrom(t) && t != typeof(Message)))
            {
                _model[typeof(Message)].AddSubType(GenerateId(type), type);
                _model[type].UseConstructor = false;
            }


            _model[typeof(MessageHeader)].UseConstructor = false;

            foreach (var type in types.Where(t => typeof(MessageHeader).IsAssignableFrom(t) && t != typeof(MessageHeader)))
            {
                _model[typeof(MessageHeader)].AddSubType(GenerateId(type), type);
                _model[type].UseConstructor = false;
            }

            _model.CompileInPlace();
        }