mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* 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
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using System;
|
|
using System.Buffers;
|
|
using System.IO;
|
|
using JetBrains.Annotations;
|
|
using Lidgren.Network;
|
|
using Robust.Shared.Interfaces.Network;
|
|
using Robust.Shared.Network;
|
|
|
|
namespace Robust.Shared.Serialization
|
|
{
|
|
|
|
/// <summary>
|
|
/// The meat of the string-exchange handshake sandwich. Sent by the
|
|
/// server after the client requests an updated copy of the mapping.
|
|
/// Contains the updated string mapping.
|
|
/// </summary>
|
|
/// <seealso cref="RobustMappedStringSerializer.NetworkInitialize"/>
|
|
[UsedImplicitly]
|
|
internal class MsgRobustMappedStringsSerializerStrings : NetMessage
|
|
{
|
|
|
|
public MsgRobustMappedStringsSerializerStrings(INetChannel ch)
|
|
: base(nameof(MsgRobustMappedStringsSerializerStrings), MsgGroups.Core)
|
|
{
|
|
}
|
|
|
|
public int PackageSize { get; set; }
|
|
|
|
/// <value>
|
|
/// The raw bytes of the string mapping held by the server.
|
|
/// </value>
|
|
public byte[]? Package { get; set; }
|
|
|
|
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
|
{
|
|
PackageSize = buffer.ReadVariableInt32();
|
|
buffer.ReadBytes(Package = new byte[PackageSize]);
|
|
}
|
|
|
|
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
|
{
|
|
if (Package == null)
|
|
{
|
|
throw new InvalidOperationException("Package has not been specified.");
|
|
}
|
|
|
|
buffer.WriteVariableInt32(Package.Length);
|
|
var start = buffer.LengthBytes;
|
|
buffer.Write(Package);
|
|
var added = buffer.LengthBytes - start;
|
|
if (added != Package.Length)
|
|
{
|
|
throw new InvalidOperationException("Not all of the bytes were written to the message.");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|