Code Monkey home page Code Monkey logo

Comments (4)

hadashiA avatar hadashiA commented on July 4, 2024

I would only comment on the code you posted,

var array = CustomSongsDataList.ToArray();

Make sure this is an array of ExtraSongSerializedData.

If possible, could you provide a minimal sample that works?
(The above code is not executable, and the type of CustomSongsDataList is unknown.
That way we may be able to investigate a bit further.

from memorypack.

Meivyn avatar Meivyn commented on July 4, 2024

What I currently use is this, which also produces the same error

using System.Collections.Concurrent;
using System.ComponentModel;
using System.Diagnostics;
using MemoryPack;
using MemoryPack.Streaming;
using Newtonsoft.Json;

namespace ConsoleApp
{
    internal class Program
    {
        private static ConcurrentDictionary<string, ExtraSongData> CustomSongsData = new();
        private static string DataPath = "SongCoreExtraData.json";

        private static async Task Main(string[] args)
        {
            var json = await File.ReadAllTextAsync(DataPath);
            CustomSongsData = JsonConvert.DeserializeObject<ConcurrentDictionary<string, ExtraSongData>>(json)!;

            await MemoryPack();
        }

        private static async Task MemoryPack()
        {
            var startTime = Stopwatch.GetTimestamp();
            await using var fileStream = File.Open("data.json", FileMode.Create);

            await MemoryPackStreamingSerializer.SerializeAsync(fileStream, CustomSongsData.Count, CustomSongsData);
            Console.WriteLine($"Serialization: {CustomSongsData.Count} entries in {Stopwatch.GetElapsedTime(startTime)}");

            fileStream.Position = 0;
            startTime = Stopwatch.GetTimestamp();

            CustomSongsData.Clear();
            await foreach (var pair in MemoryPackStreamingSerializer.DeserializeAsync<KeyValuePair<string, ExtraSongData>>(fileStream))
            {
                CustomSongsData.TryAdd(pair.Key, pair.Value);
            }
            Console.WriteLine($"Deserialization: {CustomSongsData.Count} entries in {Stopwatch.GetElapsedTime(startTime)}");
        }
    }

    [MemoryPackable]
    public partial class ExtraSongData
    {
        public string[] _genreTags;
        public Contributor[] contributors;
        public string _customEnvironmentName;
        public string _customEnvironmentHash;
        public DifficultyData[] _difficulties;
        public string _defaultCharacteristic = null;

        public ColorScheme[] _colorSchemes;
        public string[] _environmentNames;

        public CharacteristicDetails[] _characteristicDetails;
    }

    [MemoryPackable]
    public partial class MapColor
    {
        public float r;
        public float g;
        public float b;

        [DefaultValue(1)]
        public float a = 1f;
    }

    [MemoryPackable]
    public partial class Contributor
    {
        public string _role;
        public string _name;
        public string _iconPath;
    }

    [MemoryPackable]
    public partial class ColorScheme
    {
        public bool useOverride;
        public string colorSchemeId;
        public MapColor? saberAColor;
        public MapColor? saberBColor;
        public MapColor? environmentColor0;
        public MapColor? environmentColor1;
        public MapColor? obstaclesColor;
        public MapColor? environmentColor0Boost;
        public MapColor? environmentColor1Boost;
        public MapColor? environmentColorW;
        public MapColor? environmentColorWBoost;
    }

    [MemoryPackable]
    public partial class RequirementData
    {
        public string[] _requirements;
        public string[] _suggestions;
        public string[] _warnings;
        public string[] _information;
    }

    [MemoryPackable]
    public partial class CharacteristicDetails
    {
        public string _beatmapCharacteristicName;
        public string? _characteristicLabel;
        public string? _characteristicIconFilePath = null;
    }

    [MemoryPackable]
    public partial class DifficultyData
    {
        public string _beatmapCharacteristicName;
        public BeatmapDifficulty _difficulty;
        public string _difficultyLabel;
        public RequirementData additionalDifficultyData;
        public MapColor? _colorLeft;
        public MapColor? _colorRight;
        public MapColor? _envColorLeft;
        public MapColor? _envColorRight;
        public MapColor? _envColorWhite;
        public MapColor? _envColorLeftBoost;
        public MapColor? _envColorRightBoost;
        public MapColor? _envColorWhiteBoost;
        public MapColor? _obstacleColor;
        public int? _beatmapColorSchemeIdx;
        public int? _environmentNameIdx;

        //PinkCore Port
        public bool? _oneSaber;
        public bool? _showRotationNoteSpawnLines;
        //Tags
        public string[] _styleTags;
    }
}

SongCoreExtraData.json

from memorypack.

hadashiA avatar hadashiA commented on July 4, 2024

Thank you for the reproduction code.

I have looked into it and it seems that your data has very long strings, over about 15KB.
(e.g. _difficultyLabel.)

Since the default buffer size is 8KB, the buffer would overflow.

Check the argument for MemoryPackStreamingSerializer.DeserializeAsync.

The following seems to work:

MemoryPackStreamingSerializer.DeserializeAsync<ExtraSongData>(fileStream, bufferAtLeast: 65536, readMinimumSize: 65536))

bufferAtLeast is the minimum buffer required. It must be longer than the maximum length of the utf8 encoding of your string. Try specifying a larger value.

from memorypack.

Meivyn avatar Meivyn commented on July 4, 2024

I did try to specify a larger buffer already... but I guess it wasn't big enough. Thanks for taking the time to look into it, I appreciate it.

from memorypack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.