/// <summary>Helper: Serialize into a MemoryStream and return its byte array</summary>
        public static byte[] SerializeToBytes(Vector3 instance)
        {
            var ms = Pool.Get <MemoryStream>();

            Serialize(ms, instance);
            var arr = ms.ToArray();

            Pool.FreeMemoryStream(ref ms);
            return(arr);
        }
        /// <summary>Helper: put the buffer into a MemoryStream before deserializing</summary>
        public static UnityEngine.Vector3 Deserialize(byte[] buffer, ref UnityEngine.Vector3 instance)
        {
            var ms = Pool.Get <MemoryStream>();

            ms.Write(buffer, 0, buffer.Length);
            ms.Position = 0;
            Deserialize(ms, ref instance);
            Pool.FreeMemoryStream(ref ms);
            return(instance);
        }
Beispiel #3
0
        public static void Serialize(Stream stream, Vector3 instance)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            stream.WriteByte(13);
            ProtocolParser.WriteSingle(stream, instance.x);
            stream.WriteByte(21);
            ProtocolParser.WriteSingle(stream, instance.y);
            stream.WriteByte(29);
            ProtocolParser.WriteSingle(stream, instance.z);
            Pool.FreeMemoryStream(ref memoryStream);
        }
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, Vector3 instance)
        {
            var msField = Pool.Get <MemoryStream>();

            // Key for field: 1, Fixed32
            stream.WriteByte(13);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteSingle(stream, instance.x);
            // Key for field: 2, Fixed32
            stream.WriteByte(21);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteSingle(stream, instance.y);
            // Key for field: 3, Fixed32
            stream.WriteByte(29);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteSingle(stream, instance.z);
            Pool.FreeMemoryStream(ref msField);
        }
        public static void Serialize(Stream stream, Ray instance)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            stream.WriteByte(10);
            memoryStream.SetLength((long)0);
            Vector3Serialized.Serialize(memoryStream, instance.origin);
            uint length = (uint)memoryStream.Length;

            ProtocolParser.WriteUInt32(stream, length);
            stream.Write(memoryStream.GetBuffer(), 0, (int)length);
            stream.WriteByte(18);
            memoryStream.SetLength((long)0);
            Vector3Serialized.Serialize(memoryStream, instance.direction);
            uint num = (uint)memoryStream.Length;

            ProtocolParser.WriteUInt32(stream, num);
            stream.Write(memoryStream.GetBuffer(), 0, (int)num);
            Pool.FreeMemoryStream(ref memoryStream);
        }
Beispiel #6
0
        public static void SerializeDelta(Stream stream, Vector3 instance, Vector3 previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.x != previous.x)
            {
                stream.WriteByte(13);
                ProtocolParser.WriteSingle(stream, instance.x);
            }
            if (instance.y != previous.y)
            {
                stream.WriteByte(21);
                ProtocolParser.WriteSingle(stream, instance.y);
            }
            if (instance.z != previous.z)
            {
                stream.WriteByte(29);
                ProtocolParser.WriteSingle(stream, instance.z);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
        public static void SerializeDelta(Stream stream, Vector3 instance, Vector3 previous)
        {
            var msField = Pool.Get <MemoryStream>();

            if (instance.x != previous.x)
            {
                // Key for field: 1, Fixed32
                stream.WriteByte(13);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteSingle(stream, instance.x);
            }
            if (instance.y != previous.y)
            {
                // Key for field: 2, Fixed32
                stream.WriteByte(21);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteSingle(stream, instance.y);
            }
            if (instance.z != previous.z)
            {
                // Key for field: 3, Fixed32
                stream.WriteByte(29);
                global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteSingle(stream, instance.z);
            }
            Pool.FreeMemoryStream(ref msField);
        }