mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Switch to SignalR 5.0 and implement using better API
This commit is contained in:
@ -1,8 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System.Buffers;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
using MessagePack;
|
using MessagePack;
|
||||||
using MessagePack.Formatters;
|
using MessagePack.Formatters;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -11,59 +12,51 @@ namespace osu.Game.Online.API
|
|||||||
{
|
{
|
||||||
public class ModSettingsDictionaryFormatter : IMessagePackFormatter<Dictionary<string, object>>
|
public class ModSettingsDictionaryFormatter : IMessagePackFormatter<Dictionary<string, object>>
|
||||||
{
|
{
|
||||||
public int Serialize(ref byte[] bytes, int offset, Dictionary<string, object> value, IFormatterResolver formatterResolver)
|
public void Serialize(ref MessagePackWriter writer, Dictionary<string, object> value, MessagePackSerializerOptions options)
|
||||||
{
|
{
|
||||||
int startOffset = offset;
|
|
||||||
|
|
||||||
var primitiveFormatter = PrimitiveObjectFormatter.Instance;
|
var primitiveFormatter = PrimitiveObjectFormatter.Instance;
|
||||||
|
|
||||||
offset += MessagePackBinary.WriteArrayHeader(ref bytes, offset, value.Count);
|
writer.WriteArrayHeader(value.Count);
|
||||||
|
|
||||||
foreach (var kvp in value)
|
foreach (var kvp in value)
|
||||||
{
|
{
|
||||||
offset += MessagePackBinary.WriteString(ref bytes, offset, kvp.Key);
|
var stringBytes = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(kvp.Key));
|
||||||
|
writer.WriteString(in stringBytes);
|
||||||
|
|
||||||
switch (kvp.Value)
|
switch (kvp.Value)
|
||||||
{
|
{
|
||||||
case Bindable<double> d:
|
case Bindable<double> d:
|
||||||
offset += primitiveFormatter.Serialize(ref bytes, offset, d.Value, formatterResolver);
|
primitiveFormatter.Serialize(ref writer, d.Value, options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Bindable<float> f:
|
case Bindable<float> f:
|
||||||
offset += primitiveFormatter.Serialize(ref bytes, offset, f.Value, formatterResolver);
|
primitiveFormatter.Serialize(ref writer, f.Value, options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Bindable<bool> b:
|
case Bindable<bool> b:
|
||||||
offset += primitiveFormatter.Serialize(ref bytes, offset, b.Value, formatterResolver);
|
primitiveFormatter.Serialize(ref writer, b.Value, options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException("A setting was of a type not supported by the messagepack serialiser", nameof(bytes));
|
// fall back for non-bindable cases.
|
||||||
|
primitiveFormatter.Serialize(ref writer, kvp.Value, options);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return offset - startOffset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, object> Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
|
public Dictionary<string, object> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||||
{
|
{
|
||||||
int startOffset = offset;
|
|
||||||
|
|
||||||
var output = new Dictionary<string, object>();
|
var output = new Dictionary<string, object>();
|
||||||
|
|
||||||
int itemCount = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
|
int itemCount = reader.ReadArrayHeader();
|
||||||
offset += readSize;
|
|
||||||
|
|
||||||
for (int i = 0; i < itemCount; i++)
|
for (int i = 0; i < itemCount; i++)
|
||||||
{
|
{
|
||||||
var key = MessagePackBinary.ReadString(bytes, offset, out readSize);
|
output[reader.ReadString()] =
|
||||||
offset += readSize;
|
PrimitiveObjectFormatter.Instance.Deserialize(ref reader, options);
|
||||||
|
|
||||||
output[key] = PrimitiveObjectFormatter.Instance.Deserialize(bytes, offset, formatterResolver, out readSize);
|
|
||||||
offset += readSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readSize = offset - startOffset;
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,12 @@
|
|||||||
<ItemGroup Label="Package References">
|
<ItemGroup Label="Package References">
|
||||||
<PackageReference Include="DiffPlex" Version="1.6.3" />
|
<PackageReference Include="DiffPlex" Version="1.6.3" />
|
||||||
<PackageReference Include="Humanizer" Version="2.8.26" />
|
<PackageReference Include="Humanizer" Version="2.8.26" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.11" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="5.0.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="3.1.10" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="5.0.2" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.NETCore.Targets" Version="3.1.0" />
|
<PackageReference Include="Microsoft.NETCore.Targets" Version="3.1.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="ppy.osu.Framework" Version="2021.128.0" />
|
<PackageReference Include="ppy.osu.Framework" Version="2021.128.0" />
|
||||||
|
Reference in New Issue
Block a user