Пример #1
0
        protected internal override DateTimeOffset UnpackFromCore(Unpacker unpacker)
        {
            if (unpacker.IsArrayHeader)
            {
                if (UnpackHelpers.GetItemsCount(unpacker) != 2)
                {
                    SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(DateTimeOffset), 2);
                }

                long ticks;
                if (!unpacker.ReadInt64(out ticks))
                {
                    SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
                }

                short offsetMinutes;
                if (!unpacker.ReadInt16(out offsetMinutes))
                {
                    SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
                }

                return(new DateTimeOffset(DateTime.FromBinary(ticks), TimeSpan.FromMinutes(offsetMinutes)));
            }
            else
            {
                return(MessagePackConvert.ToDateTimeOffset(unpacker.LastReadData.AsInt64()));
            }
        }
        protected internal override Vector2 UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector2), 2);
            }

            var length = unpacker.LastReadData.AsInt64();

            if (length != 2)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector2), 2);
            }

            float x;

            if (!unpacker.ReadSingle(out x))
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }

            float y;

            if (!unpacker.ReadSingle(out y))
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            return(new Vector2(x, y));
        }
Пример #3
0
        protected internal override Complex UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Complex), 2);
            }

            long length = UnpackHelpers.GetItemsCount(unpacker);

            if (length != 2)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Complex), 2);
            }

            double real, imaginary;

            if (!unpacker.ReadDouble(out real))
            {
                SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
            }


            if (!unpacker.ReadDouble(out imaginary))
            {
                SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker);
            }

            return(new Complex(real, imaginary));
        }
        protected internal override async Task <Vector2> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector2), 2);
            }

            var length = unpacker.LastReadData.AsInt64();

            if (length != 2)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector2), 2);
            }

            var x = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!x.Success)
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }

            var y = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!y.Success)
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            return(new Vector2(x.Value, y.Value));
        }
        protected internal override async Task <Matrix3x2> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6);
            }

            var length = unpacker.LastReadData.AsInt64();

            if (length != 6)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6);
            }

            var m11 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m11.Success)
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }

            var m12 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m12.Success)
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }

            var m21 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m21.Success)
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }

            var m22 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m22.Success)
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }

            var m31 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m31.Success)
            {
                SerializationExceptions.ThrowMissingItem(4, unpacker);
            }

            var m32 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m32.Success)
            {
                SerializationExceptions.ThrowMissingItem(5, unpacker);
            }


            return(new Matrix3x2(m11.Value, m12.Value, m21.Value, m22.Value, m31.Value, m32.Value));
        }
        protected internal override Matrix3x2 UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6);
            }

            var length = unpacker.LastReadData.AsInt64();

            if (length != 6)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6);
            }

            float m11;

            if (!unpacker.ReadSingle(out m11))
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }

            float m12;

            if (!unpacker.ReadSingle(out m12))
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }

            float m21;

            if (!unpacker.ReadSingle(out m21))
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }

            float m22;

            if (!unpacker.ReadSingle(out m22))
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }

            float m31;

            if (!unpacker.ReadSingle(out m31))
            {
                SerializationExceptions.ThrowMissingItem(4, unpacker);
            }

            float m32;

            if (!unpacker.ReadSingle(out m32))
            {
                SerializationExceptions.ThrowMissingItem(5, unpacker);
            }


            return(new Matrix3x2(m11, m12, m21, m22, m31, m32));
        }
        protected internal override async Task <Version> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4);
            }

            long length = unpacker.LastReadData.AsInt64();

            if (length != 4)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4);
            }

            var major = await unpacker.ReadInt32Async(cancellationToken).ConfigureAwait(false);

            if (!major.Success)
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }

            var minor = await unpacker.ReadInt32Async(cancellationToken).ConfigureAwait(false);

            if (!minor.Success)
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }

            var build = await unpacker.ReadInt32Async(cancellationToken).ConfigureAwait(false);

            if (!build.Success)
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }

            var revision = await unpacker.ReadInt32Async(cancellationToken).ConfigureAwait(false);

            if (!revision.Success)
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }

            if (build.Value < 0 && revision.Value < 0)
            {
                return(new Version(major.Value, minor.Value));
            }
            else if (revision.Value < 0)
            {
                return(new Version(major.Value, minor.Value, build.Value));
            }

            return(new Version(major.Value, minor.Value, build.Value, revision.Value));
        }
        protected internal override Quaternion UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Quaternion), 4);
            }

            var length = UnpackHelpers.GetItemsCount(unpacker);

            if (length != 4)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Quaternion), 4);
            }


            float x;

            if (!unpacker.ReadSingle(out x))
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }


            float y;

            if (!unpacker.ReadSingle(out y))
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            float z;

            if (!unpacker.ReadSingle(out z))
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }


            float w;

            if (!unpacker.ReadSingle(out w))
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }



            return(new Quaternion(x, y, z, w));
        }
        protected internal override async Task <Plane> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Plane), 4);
            }

            var length = unpacker.LastReadData.AsInt64();

            if (length != 4)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Plane), 4);
            }


            var normal_X = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!normal_X.Success)
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }


            var normal_Y = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!normal_Y.Success)
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            var normal_Z = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!normal_Z.Success)
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }


            var d = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!d.Success)
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }



            return(new Plane(normal_X.Value, normal_Y.Value, normal_Z.Value, d.Value));
        }
        protected internal override Plane UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Plane), 4);
            }

            var length = UnpackHelpers.GetItemsCount(unpacker);

            if (length != 4)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Plane), 4);
            }


            float normal_X;

            if (!unpacker.ReadSingle(out normal_X))
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }


            float normal_Y;

            if (!unpacker.ReadSingle(out normal_Y))
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            float normal_Z;

            if (!unpacker.ReadSingle(out normal_Z))
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }


            float d;

            if (!unpacker.ReadSingle(out d))
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }



            return(new Plane(normal_X, normal_Y, normal_Z, d));
        }
        protected internal override Version UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4);
            }

            long length = UnpackHelpers.GetItemsCount(unpacker);

            if (length != 4)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4);
            }

            int major, minor, build, revision;

            if (!unpacker.ReadInt32(out major))
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }

            if (!unpacker.ReadInt32(out minor))
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }

            if (!unpacker.ReadInt32(out build))
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }

            if (!unpacker.ReadInt32(out revision))
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }

            if (build < 0 && revision < 0)
            {
                return(new Version(major, minor));
            }
            else if (revision < 0)
            {
                return(new Version(major, minor, build));
            }

            return(new Version(major, minor, build, revision));
        }
        protected internal override Vector3 UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector3), 3);
            }

            var length = UnpackHelpers.GetItemsCount(unpacker);

            if (length != 3)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector3), 3);
            }


            float x;

            if (!unpacker.ReadSingle(out x))
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }


            float y;

            if (!unpacker.ReadSingle(out y))
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }


            float z;

            if (!unpacker.ReadSingle(out z))
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }



            return(new Vector3(x, y, z));
        }
        protected internal override async Task <Matrix4x4> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16);
            }

            var length = unpacker.LastReadData.AsInt64();

            if (length != 16)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16);
            }

            var m11 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m11.Success)
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }

            var m12 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m12.Success)
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }

            var m13 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m13.Success)
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }

            var m14 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m14.Success)
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }

            var m21 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m21.Success)
            {
                SerializationExceptions.ThrowMissingItem(4, unpacker);
            }

            var m22 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m22.Success)
            {
                SerializationExceptions.ThrowMissingItem(5, unpacker);
            }

            var m23 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m23.Success)
            {
                SerializationExceptions.ThrowMissingItem(6, unpacker);
            }

            var m24 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m24.Success)
            {
                SerializationExceptions.ThrowMissingItem(7, unpacker);
            }

            var m31 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m31.Success)
            {
                SerializationExceptions.ThrowMissingItem(8, unpacker);
            }

            var m32 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m32.Success)
            {
                SerializationExceptions.ThrowMissingItem(9, unpacker);
            }

            var m33 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m33.Success)
            {
                SerializationExceptions.ThrowMissingItem(10, unpacker);
            }

            var m34 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m34.Success)
            {
                SerializationExceptions.ThrowMissingItem(11, unpacker);
            }

            var m41 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m41.Success)
            {
                SerializationExceptions.ThrowMissingItem(12, unpacker);
            }

            var m42 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m42.Success)
            {
                SerializationExceptions.ThrowMissingItem(13, unpacker);
            }

            var m43 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m43.Success)
            {
                SerializationExceptions.ThrowMissingItem(14, unpacker);
            }

            var m44 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false);

            if (!m44.Success)
            {
                SerializationExceptions.ThrowMissingItem(15, unpacker);
            }


            return(new Matrix4x4(m11.Value, m12.Value, m13.Value, m14.Value, m21.Value, m22.Value, m23.Value, m24.Value, m31.Value, m32.Value, m33.Value, m34.Value, m41.Value, m42.Value, m43.Value, m44.Value));
        }
        protected internal override Matrix4x4 UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsArrayHeader)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16);
            }

            var length = unpacker.LastReadData.AsInt64();

            if (length != 16)
            {
                SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16);
            }

            float m11;

            if (!unpacker.ReadSingle(out m11))
            {
                SerializationExceptions.ThrowMissingItem(0, unpacker);
            }

            float m12;

            if (!unpacker.ReadSingle(out m12))
            {
                SerializationExceptions.ThrowMissingItem(1, unpacker);
            }

            float m13;

            if (!unpacker.ReadSingle(out m13))
            {
                SerializationExceptions.ThrowMissingItem(2, unpacker);
            }

            float m14;

            if (!unpacker.ReadSingle(out m14))
            {
                SerializationExceptions.ThrowMissingItem(3, unpacker);
            }

            float m21;

            if (!unpacker.ReadSingle(out m21))
            {
                SerializationExceptions.ThrowMissingItem(4, unpacker);
            }

            float m22;

            if (!unpacker.ReadSingle(out m22))
            {
                SerializationExceptions.ThrowMissingItem(5, unpacker);
            }

            float m23;

            if (!unpacker.ReadSingle(out m23))
            {
                SerializationExceptions.ThrowMissingItem(6, unpacker);
            }

            float m24;

            if (!unpacker.ReadSingle(out m24))
            {
                SerializationExceptions.ThrowMissingItem(7, unpacker);
            }

            float m31;

            if (!unpacker.ReadSingle(out m31))
            {
                SerializationExceptions.ThrowMissingItem(8, unpacker);
            }

            float m32;

            if (!unpacker.ReadSingle(out m32))
            {
                SerializationExceptions.ThrowMissingItem(9, unpacker);
            }

            float m33;

            if (!unpacker.ReadSingle(out m33))
            {
                SerializationExceptions.ThrowMissingItem(10, unpacker);
            }

            float m34;

            if (!unpacker.ReadSingle(out m34))
            {
                SerializationExceptions.ThrowMissingItem(11, unpacker);
            }

            float m41;

            if (!unpacker.ReadSingle(out m41))
            {
                SerializationExceptions.ThrowMissingItem(12, unpacker);
            }

            float m42;

            if (!unpacker.ReadSingle(out m42))
            {
                SerializationExceptions.ThrowMissingItem(13, unpacker);
            }

            float m43;

            if (!unpacker.ReadSingle(out m43))
            {
                SerializationExceptions.ThrowMissingItem(14, unpacker);
            }

            float m44;

            if (!unpacker.ReadSingle(out m44))
            {
                SerializationExceptions.ThrowMissingItem(15, unpacker);
            }


            return(new Matrix4x4(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44));
        }