public RuntimeTypeModel Configure(RuntimeTypeModel typeModel) { typeModel.Add(typeof(EntityTypeSurrogate), false) .Add(1, "Id").SetFactory(SurrogateFactory<EntityTypeSurrogate>.Factory.Method); typeModel.Add(typeof(IEntityType), false).SetSurrogate(typeof(EntityTypeSurrogate)); return typeModel; }
/// <summary> /// Creates a new PBF reader. /// </summary> public PBFReader(Stream stream) { _stream = stream; _runtimeTypeModel = RuntimeTypeModel.Create(); _runtimeTypeModel.Add(_blockHeaderType, true); _runtimeTypeModel.Add(_blobType, true); _runtimeTypeModel.Add(_primitiveBlockType, true); _runtimeTypeModel.Add(_headerBlockType, true); }
public ProtobufSerializerFactory() { _runtimeTypeModel = TypeModel.Create(); _runtimeTypeModel.Add(typeof (SomeMessage), true) .Add(1, "Text"); _runtimeTypeModel.Add(typeof (RootObject), true) .Add(1, "BigObjects"); _runtimeTypeModel.Add(typeof (BigObject), true) .Add(1, "Integer") .Add(2, "String"); }
/// <summary> /// Creates a new PBF stream target. /// </summary> public PBFOsmStreamTarget(Stream stream) { _stream = stream; _currentEntities = new List<Osm.OsmGeo>(); _reverseStringTable = new Dictionary<string, int>(); _buffer = new MemoryStream(); _runtimeTypeModel = RuntimeTypeModel.Create(); _runtimeTypeModel.Add(_blobHeaderType, true); _runtimeTypeModel.Add(_blobType, true); _runtimeTypeModel.Add(_primitiveBlockType, true); _runtimeTypeModel.Add(_headerBlockType, true); }
public static void Register(RuntimeTypeModel typeModel, Assembly assembly) { foreach (var type in GetTypesSafely(assembly)) { if (type.IsClass == false && type.IsValueType == false) continue; if (Attribute.GetCustomAttribute(type, typeof(ProtoBuf.ProtoContractAttribute)) == null) continue; var loweredTypeName = type.Name.ToLower(); if (loweredTypeName.Contains("surrogatedirectives")) { foreach (var field in type.GetFields()) { var sourceType = FindSurrogateSourceType(field.FieldType); if (sourceType != null) { if (typeModel.CanSerialize(sourceType)) continue; try { typeModel.Add(sourceType, false).SetSurrogate(field.FieldType); } catch (InvalidOperationException) { } } } } else if (type.Name.ToLower().Contains("surrogate")) { var sourceType = FindSurrogateSourceType(type); if (sourceType != null) { if (typeModel.CanSerialize(sourceType)) continue; try { typeModel.Add(sourceType, false).SetSurrogate(type); } catch (InvalidOperationException) { } } } } }
static RuntimeTypeModel GetProtobufModel() { if (_pbModel == null) { _pbModel = TypeModel.Create(); _pbModel.AllowParseableTypes=true; _pbModel.Add(typeof(Font), false).SetSurrogate(typeof(ProtoFont)); _pbModel.Add(typeof(Color), false).SetSurrogate(typeof(ProtoColor)); _pbModel.Add(typeof(StringFormat), false).SetSurrogate(typeof(ProtoStringFormat)); _pbModel.Add(typeof(Point<float>), true).Add("X", "Y"); _pbModel.Add(typeof(DrawStyle), true).AddSubType(100, typeof(DiagramDrawStyle)); _pbModel[typeof(BoundingBox<float>)].Add("X1", "X2", "Y1", "Y2"); _pbModel[typeof(BoundingBox<float>)].UseConstructor = false; Debug.WriteLine(_pbModel.GetSchema(typeof(DiagramDocumentCore))); } return _pbModel; }
internal static void Build(RuntimeTypeModel runtimeTypeModel, Type type) { if (BuiltTypes.Contains(type)) { return; } lock (type) { if (runtimeTypeModel.CanSerialize(type)) { if (type.IsGenericType) { BuildGenerics(runtimeTypeModel, type); } return; } var meta = runtimeTypeModel.Add(type, false); var fields = type.GetFields(Flags); meta.Add(fields.Select(x => x.Name).ToArray()); meta.UseConstructor = false; BuildBaseClasses(runtimeTypeModel, type); BuildGenerics(runtimeTypeModel, type); foreach (var memberType in fields.Select(f => f.FieldType).Where(t => !t.IsPrimitive)) { Build(runtimeTypeModel, memberType); } BuiltTypes.Add(type); } }
public ProtobufSerializer(RuntimeTypeModel runtimeTypeModel) { if (runtimeTypeModel == null) throw new ArgumentNullException(nameof(runtimeTypeModel)); _runtimeTypeModel = runtimeTypeModel; var subscribeRequestType = _runtimeTypeModel.Add(typeof (SubscribeRequest), true); subscribeRequestType.AddField(1, Reflect.Path<SubscribeRequest>(r => r.Topic)); subscribeRequestType.AddField(2, Reflect.Path<SubscribeRequest>(r => r.SubscriberAddress)); var unsubscribeRequestType = _runtimeTypeModel.Add(typeof (UnsubscribeRequest), true); unsubscribeRequestType.AddField(1, Reflect.Path<UnsubscribeRequest>(r => r.Topic)); unsubscribeRequestType.AddField(2, Reflect.Path<UnsubscribeRequest>(r => r.SubscriberAddress)); var dataBusAttachmentType = _runtimeTypeModel.Add(typeof(DataBusAttachment), true); dataBusAttachmentType.AddField(1, Reflect.Path<DataBusAttachment>(r => r.Id)); }
public void Work(RuntimeTypeModel model) { foreach (Type current in RuntimeReflectionUtilities.GetUnityObjectTypes()) { Type surrogate = typeof(UnityObjectSurrogate<>).MakeGenericType(new Type[] { current }); model.Add(current, false).SetSurrogate(surrogate); } }
private static void AddProperties(RuntimeTypeModel model, Type type) { var metaType = model.Add(type, true); foreach (var property in type.GetProperties().OrderBy(x => x.Name)) { metaType.Add(property.Name); var propertyType = property.PropertyType; if (!IsBuiltinType(propertyType) && !model.IsDefined(propertyType) && propertyType.GetProperties().Length > 0) { AddProperties(model, propertyType); } } }
static void Add(RuntimeTypeModel model, Type type, string name, string origin, Type serializerType) { var mt = model.Add(type, true); if (name is object) { mt.Name = name; } if (origin is object) { mt.Origin = origin; } if (serializerType is object) { mt.SerializerType = serializerType; } }
public PerformanceTests() { _model = TypeModel.Create(); _model.Add(typeof(Event), true); _stream = new MemoryStream(); for (var i = 0; i < 1000 * 1000; i++) { var id = Guid.NewGuid(); var item = new OrderPlacedEvent(id, "Ordered by customer number" + i.ToString(CultureInfo.InvariantCulture), new[] { new OrderItem("Test product", i) }); var shipment = new OrderShippedEvent(id, DateTime.Now); _model.SerializeWithLengthPrefix(_stream, item, typeof(Event), Prefix, 0); _model.SerializeWithLengthPrefix(_stream, shipment, typeof(Event), Prefix, 0); } }
static Serializer() { model = TypeModel.Create(); model.AutoAddMissingTypes = true; //RuntimeTypeModel mdl = new RuntimeTypeModel(); model.Add(typeof(Point), true).Add("X", "Y"); model.Add(typeof(Demo.Entity), true).Add("tile", "x", "y", "pos").AddSubType(40, typeof(Demo.Mob)); model.Add(typeof(SkillAreaKind), true); MetaType sk = model.Add(typeof(Skill), true).Add("minSkillDistance", "maxSkillDistance", "radius", "areaKind", "damage", "hitsAllies", "name", "targetSquare"); sk.UseConstructor = false; MetaType mb = model.Add(typeof(Demo.Mob), true).Add("hp_internal", "maxHP", "friendly", "o_pos", "name", "moveSpeed", "actionCount", "skillList", "dlevelIndex"); mb.UseConstructor = false; model.Add(typeof(Level), true).Add("floor", "entities", "o_entities", "allies", "map1D", "mapWidthBound", "mapHeightBound", "fixtures", "safeUpCells", "safeDownCells", "enemyBlockedCells"); model.Add(typeof(Demo.GameState), true).Add("initiative", "currentInitiative", "fullDungeon", "levelIndex", "cursorX", "cursorY", "confirmKey", "backKey"); // System.IO.File.WriteAllText("debuggery2.txt", model.GetTypes().ToString()); }
public IntegrationTests() { _model = TypeModel.Create(); _model.Add(typeof(Employee), true); }
public static RuntimeTypeModel BuildTypeModel(TypeDescription desc, RuntimeTypeModel existing = null) { existing = existing ?? RuntimeTypeModel.Create(); if (desc is SimpleTypeDescription) return existing; if (desc is NullableTypeDescription) return existing; if (desc is BackReferenceTypeDescription) return existing; if (desc is DictionaryTypeDescription) { var key = ((DictionaryTypeDescription)desc).KeyType; var val = ((DictionaryTypeDescription)desc).ValueType; BuildTypeModel(key, existing); BuildTypeModel(val, existing); return existing; } if (desc is ListTypeDescription) { var contains = ((ListTypeDescription)desc).Contains; BuildTypeModel(contains, existing); return existing; } if (desc is EnumTypeDescription) { var meta = existing.Add(((EnumTypeDescription)desc).ForType, applyDefaultBehaviour: false); var ordered = ((EnumTypeDescription)desc).Values.OrderBy(o => o, StringOrdinalComparer.Singleton); var equiv = 0; foreach (var val in ordered) { meta.AddField(equiv, val); equiv++; } return existing; } if (!(desc is ClassTypeDescription)) { throw new Exception("Unexpected desc: " + desc); } var asClass = desc as ClassTypeDescription; var type = existing.Add(asClass.ForType, applyDefaultBehaviour: false); int ix = 1; foreach (var mem in asClass.Members.OrderBy(o => o.Key, StringComparer.Ordinal)) { type.AddField(ix, mem.Key); BuildTypeModel(mem.Value, existing); ix++; } return existing; }
public ProjectionTypeBuilderTests() { _model = TypeModel.Create(); _model.Add(typeof(PlainObject), true); }
public static void Register(RuntimeTypeModel typeModel) { typeModel.Add(typeof(ActorPath), false).SetSurrogate(typeof(SurrogateForActorPath)); typeModel.Add(typeof(Address), false).SetSurrogate(typeof(SurrogateForAddress)); typeModel.Add(typeof(IActorRef), false).SetSurrogate(typeof(SurrogateForIActorRef)); typeModel.Add(typeof(INotificationChannel), false).SetSurrogate(typeof(SurrogateForINotificationChannel)); }
public static void Register(RuntimeTypeModel typeModel) { typeModel.Add(typeof(IRequestTarget), false).SetSurrogate(typeof(SurrogateForIRequestTarget)); typeModel.Add(typeof(INotificationChannel), false).SetSurrogate(typeof(SurrogateForINotificationChannel)); }