Exemplo n.º 1
0
        public static void Initialize(params Assembly[] AdditionalAssemblies)
        {
            if (IsInitialized)
            {
                return;
            }

            List <Assembly> TargetAssemblies = AdditionalAssemblies.ToList();

            TargetAssemblies.Add(typeof(Message).GetTypeInfo().Assembly);

            TypeInfo[] MessageTypes = TargetAssemblies.SelectMany(x => x.ExportedTypes).Select(x => x.GetTypeInfo()).Where(x => x.IsSubclassOf(typeof(Message))).ToArray();

            Dictionary <Type, int> SubTypeCount = new Dictionary <Type, int>();

            for (int i = 0; i < MessageTypes.Length; i++)
            {
                MetaType ProtobufType;

                if (!SubTypeCount.ContainsKey(MessageTypes[i].BaseType))
                {
                    ProtobufType = RuntimeTypeModel.Default.Add(MessageTypes[i].BaseType, true);
                    SubTypeCount[MessageTypes[i].BaseType] = 101;
                }
                else
                {
                    ProtobufType = RuntimeTypeModel.Default[MessageTypes[i].BaseType];
                }

                ProtobufType.AddSubType(SubTypeCount[MessageTypes[i].BaseType], MessageTypes[i].AsType());
                SubTypeCount[MessageTypes[i].BaseType]++;
            }

            IsInitialized = true;
        }
Exemplo n.º 2
0
 public ProtobufValue(ulong value)
     : this()
 {
     this.Type     = ProtobufType.Unsigned;
     this.Unsigned = value;
 }
Exemplo n.º 3
0
 public ProtobufValue(string value)
     : this()
 {
     this.String = value;
     this.Type   = ProtobufType.String;
 }
Exemplo n.º 4
0
 public ProtobufValue(long value)
     : this()
 {
     this.Signed = value;
     this.Type   = ProtobufType.Signed;
 }
Exemplo n.º 5
0
 public ProtobufValue(float value)
     : this()
 {
     this.Float32 = value;
     this.Type    = ProtobufType.Float32;
 }
Exemplo n.º 6
0
 public ProtobufValue(double value)
     : this()
 {
     this.Float64 = value;
     this.Type    = ProtobufType.Float64;
 }
Exemplo n.º 7
0
 public ProtobufValue(bool value)
     : this()
 {
     this.Boolean = value;
     this.Type    = ProtobufType.Boolean;
 }