Files
RobustToolbox/Robust.Shared/ContentPack/ResourceManager.SingleStreamLoader.cs
Tyler Young 0d52def877 Have RobustSerializer use a shared string dictionary (#1117)
* implements shared string dictionary and handshake from net-code-2

* fix unit test

switch to szr sawmill

* try to silence some warnings around ZipEntry

* rebase and use system zip instead of icsharplib

fix rebase artifacts

* Update Robust.Shared/Interfaces/GameObjects/IComponentFactory.cs

* Update Robust.Shared/Serialization/RobustSerializer.MappedStringSerializer.cs

* Update Robust.Shared/Serialization/RobustSerializer.MappedStringSerializer.cs

* Apply suggestions from code review

* Apply suggestions from code review

* Update Robust.Shared/Serialization/RobustSerializer.cs

* since no longer gathering from paths, make string splitting more robust

* make string gathering ignore strings under 4 chars long

make string gathering yet more robust

* add limit to size of mapped strings

* add more string data to feed into shared string dictionary from YAML files

add JSON importer but don't parse RSI metadata yet

fix typo that breaks nulls in MappedStringSerializer

minor refactoring

make string splitting more robust

add WriteUnsignedInt / ReadUnsignedInt for validating WriteCompressedUnsignedInt / ReadCompressedUnsignedInt aren't bogus

* comment out some log statements

* minor refactor, reorder logging

add null check due to smart typing NRT checks

* Add doc comments, readability improvements to MappedStringSerializer

The protocol, handshake, and internal logic are now more documented.

The main area that could still be improved is the documentation of how
the cache system works, but the code is readable enough for now that it
isn't immediately necessary.

* add documentation, organization

* update some more doc comments

* add flows to doc comment for NetworkInitialize

* more documentation and organization

* more docs

* instead of retrieving INetManager by IoC, assign when NetworkInitialize is invoked

* "document" the regex

* Update Robust.Shared/Network/NetManager.cs

* add missing check for LockMappedStrings

* Update Robust.Shared/Serialization/RobustSerializer.MappedStringSerializer.cs

Co-authored-by: ComicIronic <comicironic@gmail.com>

* change to warning instead of throw for unlocked string mapping

Co-authored-by: ComicIronic <comicironic@gmail.com>
2020-06-12 04:09:55 +02:00

58 lines
1.6 KiB
C#

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Robust.Shared.Utility;
namespace Robust.Shared.ContentPack
{
internal partial class ResourceManager
{
private class SingleStreamLoader : IContentRoot
{
private readonly MemoryStream _stream;
private readonly ResourcePath _resourcePath;
public SingleStreamLoader(MemoryStream stream, ResourcePath resourcePath)
{
_stream = stream;
_resourcePath = resourcePath;
}
public void Mount()
{
// Nothing to do here I'm pretty sure.
}
public bool TryGetFile(ResourcePath relPath, [NotNullWhen(true)] out Stream? stream)
{
if (relPath == _resourcePath)
{
stream = new MemoryStream();
lock (_stream)
{
_stream.CopyTo(stream);
}
stream.Position = 0;
return true;
}
stream = default;
return false;
}
public IEnumerable<ResourcePath> FindFiles(ResourcePath path)
{
if (_resourcePath.TryRelativeTo(path, out var relative))
{
yield return _resourcePath;
}
}
public IEnumerable<string> GetRelativeFilePaths()
{
yield return _resourcePath.ToString();
}
}
}
}