Files
RobustToolbox/Robust.Shared/Network/Messages/MsgViewVariablesReqData.cs
Tyler Young faff0797bf Make Lidgren Use Spans & Shared Pool (#1140)
* make lidgren use spans everywhere where it can

convert custom pooling to shared array pool impl

add unit tests for read/write

add native socket extensions to socket so we can legit pass spans for SendTo/ReceiveFrom

bump version in lidgren csproj

replace some random "% 8" w/ "& 7"

more minor nullability hacks to fix static analysis complaints

made receiving packets use span

minor native sockets refactor to use pinvoke

add read/write constrained/prealloc'd bit stream impl to lidgren and update usages

fixed missing stream cleanup

remove outstanding stream cleanup since it refs buffer thru the class, can't read some other buf

apply suggestions from code review

remove unsafe cruft

* add tests to gh actions

* make stats use interpolation in tostring and remove m_bytesAllocated since it's all in the shared pool now

* this pr still open so fuck it

stats, human readability, faster BitsToHold methods

* add api compatible version of ReadBytes

* rename ReadOnlyStreamWrapper -> ReadOnlyWrapperStream

rename WriteOnlyStreamWrapper -> WriteOnlyWrapperStream

add AppendViaStream, AppenderStream impl

add and update documentation on read/write bytes methods

also fix some goofs
2020-06-24 04:09:20 +02:00

68 lines
2.2 KiB
C#

using System.IO;
using Lidgren.Network;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
#nullable disable
namespace Robust.Shared.Network.Messages
{
/// <summary>
/// Sent client to server to request data from the server.
/// </summary>
public class MsgViewVariablesReqData : NetMessage
{
#region REQUIRED
public const MsgGroups GROUP = MsgGroups.Command;
public const string NAME = nameof(MsgViewVariablesReqData);
public MsgViewVariablesReqData(INetChannel channel) : base(NAME, GROUP)
{
}
#endregion
/// <summary>
/// The request ID that will be sent in <see cref="MsgViewVariablesRemoteData"/> to
/// identify this request among multiple potentially concurrent ones.
/// </summary>
public uint RequestId { get; set; }
/// <summary>
/// The session ID for the session to read the data from.
/// </summary>
public uint SessionId { get; set; }
/// <summary>
/// A metadata object that can be used by the server to know what data is being requested.
/// </summary>
public ViewVariablesRequest RequestMeta { get; set; }
public override void ReadFromBuffer(NetIncomingMessage buffer)
{
RequestId = buffer.ReadUInt32();
SessionId = buffer.ReadUInt32();
var serializer = IoCManager.Resolve<IRobustSerializer>();
var length = buffer.ReadInt32();
using var stream = buffer.ReadAsStream(length);
RequestMeta = serializer.Deserialize<ViewVariablesRequest>(stream);
}
public override void WriteToBuffer(NetOutgoingMessage buffer)
{
buffer.Write(RequestId);
buffer.Write(SessionId);
var serializer = IoCManager.Resolve<IRobustSerializer>();
using (var stream = new MemoryStream())
{
serializer.Serialize(stream, RequestMeta);
buffer.Write((int)stream.Length);
buffer.Write(stream.ToArray());
}
}
}
}