From 1380717ebb5b51da488736df8cd30484ecc62532 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 3 Feb 2021 20:19:27 +0900 Subject: [PATCH] Use PrimitiveObjectFormatter to simplify code --- .../API/ModSettingsDictionaryFormatter.cs | 43 +++---------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/osu.Game/Online/API/ModSettingsDictionaryFormatter.cs b/osu.Game/Online/API/ModSettingsDictionaryFormatter.cs index 1b381e7c98..3dd8bff61b 100644 --- a/osu.Game/Online/API/ModSettingsDictionaryFormatter.cs +++ b/osu.Game/Online/API/ModSettingsDictionaryFormatter.cs @@ -15,6 +15,8 @@ namespace osu.Game.Online.API { int startOffset = offset; + var primitiveFormatter = PrimitiveObjectFormatter.Instance; + offset += MessagePackBinary.WriteArrayHeader(ref bytes, offset, value.Count); foreach (var kvp in value) @@ -24,15 +26,15 @@ namespace osu.Game.Online.API switch (kvp.Value) { case Bindable d: - offset += MessagePackBinary.WriteDouble(ref bytes, offset, d.Value); + offset += primitiveFormatter.Serialize(ref bytes, offset, d.Value, formatterResolver); break; case Bindable f: - offset += MessagePackBinary.WriteSingle(ref bytes, offset, f.Value); + offset += primitiveFormatter.Serialize(ref bytes, offset, f.Value, formatterResolver); break; case Bindable b: - offset += MessagePackBinary.WriteBoolean(ref bytes, offset, b.Value); + offset += primitiveFormatter.Serialize(ref bytes, offset, b.Value, formatterResolver); break; default: @@ -57,39 +59,8 @@ namespace osu.Game.Online.API var key = MessagePackBinary.ReadString(bytes, offset, out readSize); offset += readSize; - switch (MessagePackBinary.GetMessagePackType(bytes, offset)) - { - case MessagePackType.Float: - { - // could be either float or double... - // see https://github.com/msgpack/msgpack/blob/master/spec.md#serialization-type-to-format-conversion - switch (MessagePackCode.ToFormatName(bytes[offset])) - { - case "float 32": - output[key] = MessagePackBinary.ReadSingle(bytes, offset, out readSize); - offset += readSize; - break; - - case "float 64": - output[key] = MessagePackBinary.ReadDouble(bytes, offset, out readSize); - offset += readSize; - break; - - default: - throw new ArgumentException("A setting was of a type not supported by the messagepack deserialiser", nameof(bytes)); - } - - break; - } - - case MessagePackType.Boolean: - output[key] = MessagePackBinary.ReadBoolean(bytes, offset, out readSize); - offset += readSize; - break; - - default: - throw new ArgumentException("A setting was of a type not supported by the messagepack deserialiser", nameof(bytes)); - } + output[key] = PrimitiveObjectFormatter.Instance.Deserialize(bytes, offset, formatterResolver, out readSize); + offset += readSize; } readSize = offset - startOffset;