// // NameStringConverter.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using NosSmooth.Packets.Common; using NosSmooth.Packets.Converters.Basic; using Remora.Results; namespace NosSmooth.Packets.Converters.Common; /// /// Converter of . /// public class NameStringConverter : BaseTypeConverter { /// public override Result Serialize(NameString? obj, PacketStringBuilder builder) { if (obj is null) { builder.Append("-"); return Result.FromSuccess(); } builder.Append(obj.PacketName); return Result.FromSuccess(); } /// public override Result Deserialize(PacketStringEnumerator stringEnumerator) { var tokenResult = stringEnumerator.GetNextToken(); if (!tokenResult.IsSuccess) { return Result.FromError(tokenResult); } if (tokenResult.Entity.Token == "-") { return Result.FromSuccess(null); } return NameString.FromPacket(tokenResult.Entity.Token); } }