Files
RobustToolbox/Robust.Shared/Network/Messages/MsgViewVariablesReqSession.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

63 lines
2.1 KiB
C#

using System;
using System.IO;
using Lidgren.Network;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
#nullable disable
namespace Robust.Shared.Network.Messages
{
/// <summary>
/// Sent from client to server to request to open a session.
/// </summary>
public class MsgViewVariablesReqSession : NetMessage
{
#region REQUIRED
public const MsgGroups GROUP = MsgGroups.Command;
public const string NAME = nameof(MsgViewVariablesReqSession);
public MsgViewVariablesReqSession(INetChannel channel) : base(NAME, GROUP) { }
#endregion
/// <summary>
/// An ID the client assigns so it knows which request was accepted/denied through
/// <see cref="MsgViewVariablesOpenSession"/> and <see cref="MsgViewVariablesCloseSession"/>.
/// </summary>
public uint RequestId { get; set; }
/// <summary>
/// A selector that can be used to describe a server object.
/// This isn't BYOND, we don't have consistent \ref references.
/// </summary>
public ViewVariablesObjectSelector Selector { get; set; }
public override void ReadFromBuffer(NetIncomingMessage buffer)
{
RequestId = buffer.ReadUInt32();
var serializer = IoCManager.Resolve<IRobustSerializer>();
var length = buffer.ReadInt32();
using var stream = buffer.ReadAsStream(length);
Selector = serializer.Deserialize<ViewVariablesObjectSelector>(stream);
}
public override void WriteToBuffer(NetOutgoingMessage buffer)
{
buffer.Write(RequestId);
var serializer = IoCManager.Resolve<IRobustSerializer>();
using (var stream = new MemoryStream())
{
serializer.Serialize(stream, Selector);
buffer.Write((int)stream.Length);
buffer.Write(stream.ToArray());
}
}
}
}