static string ConvertBackToGenericArgsString(string Tags)
        {
            if (TagToGenericArgsCache.TryGetValue(Tags, out var CachedResult))
            {
                return(CachedResult);
            }

            var Args = Tags.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            var Result = new StringBuilder();

            bool First = true;

            foreach (var Arg in Args)
            {
                if (First)
                {
                    First = false;
                }
                else
                {
                    Result.Append(',');
                }

                Result.Append('[');
                var Type = BondSerializationUtil.ParseTypeIdentifierString(Arg);
                Result.Append(Type.AssemblyQualifiedName);
                Result.Append(']');
            }

            TagToGenericArgsCache.TryAdd(Tags, Result.ToString());
            GenericArgsToTagCache.TryAdd(Result.ToString(), Tags);

            return(Result.ToString());
        }
        static string ParseAndConvertGenericArgsString(string genericArgs)
        {
            if (GenericArgsToTagCache.TryGetValue(genericArgs, out var CachedResult))
            {
                return(CachedResult);
            }

            StringBuilder Result = new StringBuilder();

            int  start = 0, idx, stack = 0;
            bool inside = false;

            for (idx = 0; idx < genericArgs.Length; ++idx)
            {
                if (inside)
                {
                    switch (genericArgs[idx])
                    {
                    case '[':
                        ++stack;
                        break;

                    case ']':
                        --stack;
                        if (stack == 0)
                        {
                            var typeName = genericArgs.Substring(start, idx - start - 1);
                            var type     = Type.GetType(typeName);
                            if (Result.Length > 0)
                            {
                                Result.Append(',');
                            }
                            Result.Append(BondSerializationUtil.GetTypeIdentifierString(type));

                            inside = false;
                        }
                        break;
                    }
                }
                else
                {
                    if (genericArgs[idx] == '[')
                    {
                        inside = true;
                        stack  = 1;
                        start  = idx + 1;
                    }
                }
            }

            GenericArgsToTagCache.TryAdd(genericArgs, Result.ToString());
            TagToGenericArgsCache.TryAdd(Result.ToString(), genericArgs);

            return(Result.ToString());
        }
        public static IGenericSerializable FromByteArray(ArraySegment <byte> Data)
        {
            if (Data.Count == 0)
            {
                return(null);
            }

            var Ref  = (SerializationGenericReference)BondSerializer.Deserialize(typeof(SerializationGenericReference), new ArraySegmentReaderStream(Data));
            var Type = BondSerializationUtil.ParseTypeIdentifierString(Ref.Type);

            return((IGenericSerializable)BondSerializer.Deserialize(Type, new MemoryStream(Ref.Data.ToArray())));
        }
        // TODO: It would be AWESOME if we could just store this class directly, but
        // unfortunately, Bond's type aliases allow only primitive types to be aliased.
        // We should check to see if we can add support for custom types in Bond's source,
        // but for now, we're forced to do a double serialization here.
        public static ArraySegment <byte> ToByteArray(IGenericSerializable Serializable)
        {
            if (Serializable == null)
            {
                return(default(ArraySegment <byte>));
            }

            var Type   = Serializable.GetType();
            var Result = new SerializationGenericReference(0)
            {
                Type = BondSerializationUtil.GetTypeIdentifierString(Type),
                Data = BondSerializer.Serialize(Serializable)
            };

            return(BondSerializer.Serialize(Result));
        }
Example #5
0
 public string GetTypeString(string OrleansTypeString, Type Type)
 {
     return(BondSerializationUtil.GetTypeIdentifierString(Type));
 }
Example #6
0
 public void Init(IProviderRuntime ProviderRuntime)
 {
     BondSerializationUtil.Initialize(ProviderRuntime.ServiceProvider);
 }