/// <summary>Helper: put the buffer into a MemoryStream before deserializing</summary> public static Despunch.Data.Building Deserialize(byte[] buffer, Despunch.Data.Building instance) { var ms = Pool.Get <MemoryStream>(); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; Deserialize(ms, instance); Pool.FreeMemoryStream(ref ms); return(instance); }
/// <summary>Takes the remaining content of the stream and deserialze it into the instance.</summary> public static Despunch.Data.Building Deserialize(Stream stream, Despunch.Data.Building instance) { if (instance.links == null) { instance.links = Pool.GetList <Despunch.Data.Link>(); } while (true) { int keyByte = stream.ReadByte(); if (keyByte == -1) { break; } // Optimized reading of known fields with field ID < 16 switch (keyByte) { // Field 1 LengthDelimited case 10: // repeated instance.links.Add(Despunch.Data.Link.DeserializeLengthDelimited(stream)); continue; // Field 2 LengthDelimited case 18: UnityEngine.Vector3Serializer.DeserializeLengthDelimited(stream, ref instance.pos); continue; } var key = global::SilentOrbit.ProtocolBuffers.ProtocolParser.ReadKey((byte)keyByte, stream); // Reading field ID > 16 and unknown field ID/wire type combinations switch (key.Field) { case 0: throw new global::SilentOrbit.ProtocolBuffers.ProtocolBufferException("Invalid field id: 0, something went wrong in the stream"); default: global::SilentOrbit.ProtocolBuffers.ProtocolParser.SkipKey(stream, key); break; } } return(instance); }