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);
        }
        public static Ray DeserializeLengthDelimited(Stream stream, ref Ray instance, bool isDelta)
        {
            long position = (long)ProtocolParser.ReadUInt32(stream);

            position += stream.Position;
            while (stream.Position < position)
            {
                int num = stream.ReadByte();
                if (num == -1)
                {
                    throw new EndOfStreamException();
                }
                if (num == 10)
                {
                    Vector3 vector3 = instance.origin;
                    instance.origin = Vector3Serialized.DeserializeLengthDelimited(stream, ref vector3, isDelta);
                }
                else if (num == 18)
                {
                    Vector3 vector31 = instance.direction;
                    instance.direction = Vector3Serialized.DeserializeLengthDelimited(stream, ref vector31, isDelta);
                }
                else
                {
                    Key key = ProtocolParser.ReadKey((byte)num, stream);
                    if (key.Field == 0)
                    {
                        throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                    }
                    ProtocolParser.SkipKey(stream, key);
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
Beispiel #3
0
 public static void SerializeLengthDelimited(Stream stream, Vector3 instance)
 {
     byte[] bytes = Vector3Serialized.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }