Files
RobustToolbox/Robust.Shared/Serialization/Messages/MsgRobustMappedStringsSerializerServerHandshake.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

56 lines
1.6 KiB
C#

using System;
using JetBrains.Annotations;
using Lidgren.Network;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Network;
namespace Robust.Shared.Serialization
{
/// <summary>
/// The server part of the string-exchange handshake. Sent as the
/// first message in the handshake. Tells the client the hash of
/// the current string mapping, so the client can check if it has
/// a local copy.
/// </summary>
/// <seealso cref="RobustMappedStringSerializer.NetworkInitialize"/>
[UsedImplicitly]
internal class MsgRobustMappedStringsSerializerServerHandshake : NetMessage
{
public MsgRobustMappedStringsSerializerServerHandshake(INetChannel ch)
: base(nameof(MsgRobustMappedStringsSerializerServerHandshake), MsgGroups.Core)
{
}
/// <value>
/// The hash of the current string mapping held by the server.
/// </value>
public byte[]? Hash { get; set; }
public override void ReadFromBuffer(NetIncomingMessage buffer)
{
var len = buffer.ReadVariableInt32();
if (len > 64)
{
throw new InvalidOperationException("Hash too long.");
}
buffer.ReadBytes(Hash = new byte[len]);
}
public override void WriteToBuffer(NetOutgoingMessage buffer)
{
if (Hash == null)
{
throw new InvalidOperationException("Package has not been specified.");
}
buffer.WriteVariableInt32(Hash.Length);
buffer.Write(Hash);
}
}
}