Ejemplo n.º 1
0
 protected internal override T UnpackFromCore(Unpacker unpacker)
 {
     return
         (TypeInfoEncoder.Decode(
              unpacker,
              // ReSharper disable once ConvertClosureToMethodGroup
              u => TypeInfoEncoder.DecodeRuntimeTypeInfo(u),                      // Lamda capture is more efficient.
              (t, u) => ( T )this.GetActualTypeSerializer(t).UnpackFrom(u)
              ));
 }
 protected internal override T UnpackFromCore(Unpacker unpacker)
 {
     return
         (TypeInfoEncoder.Decode(
              unpacker,
              // Currently, lamda is more efficient than method group.
              // ReSharper disable once ConvertClosureToMethodGroup
              c => this.GetTypeFromCode(c),
              (t, u) => ( T )this.GetActualTypeSerializer(t).UnpackFrom(u)
              ));
 }
        protected internal override T UnpackFromCore(Unpacker unpacker)
        {
            // It is not reasonable to identify other forms.
            if (!unpacker.IsArrayHeader || UnpackHelpers.GetItemsCount(unpacker) != 3)
            {
                throw SerializationExceptions.NewUnknownTypeEmbedding();
            }

            using (var subTreeUnpacker = unpacker.ReadSubtree())
            {
                if (!subTreeUnpacker.Read())
                {
                    throw SerializationExceptions.NewUnexpectedEndOfStream();
                }
                var header = subTreeUnpacker.LastReadData.AsMessagePackExtendedTypeObject();
                if (header.TypeCode != this.OwnerContext.TypeEmbeddingSettings.TypeEmbeddingIdentifier)
                {
                    throw new SerializationException(
                              String.Format(CultureInfo.CurrentCulture, "Unknown extension type {0}.", header.TypeCode)
                              );
                }

                if (header.Body.Length != TypeInfoEncodingBytes.RawCompressed.Length ||
                    header.Body[0] != TypeInfoEncodingBytes.RawCompressed[0])
                {
                    throw new SerializationException("Unknown type info encoding type.");
                }

                if (!subTreeUnpacker.Read())
                {
                    throw SerializationExceptions.NewUnexpectedEndOfStream();
                }

                var objectType = TypeInfoEncoder.Decode(subTreeUnpacker);

                if (!subTreeUnpacker.Read())
                {
                    throw SerializationExceptions.NewUnexpectedEndOfStream();
                }

                return(( T )this.GetActualTypeSerializer(objectType).UnpackFrom(subTreeUnpacker));
            }
        }
Ejemplo n.º 4
0
        protected internal override T UnpackFromCore(Unpacker unpacker)
        {
            return
                (TypeInfoEncoder.Decode(
                     unpacker,
                     u =>
            {
                var typeCode = u.LastReadData.AsString();

                RuntimeTypeHandle typeHandle;
                if (!this._typeHandleMap.TryGetValue(typeCode, out typeHandle))
                {
                    throw new SerializationException(
                        String.Format(CultureInfo.CurrentCulture, "Unknown type {0}.", StringEscape.ForDisplay(typeCode))
                        );
                }

                return Type.GetTypeFromHandle(typeHandle);
            },
                     (t, u) => ( T )this.GetActualTypeSerializer(t).UnpackFrom(u)
                     ));
        }