Files
lserp_cs_6.0/插件库/Lskj.AgentBridge/BridgeUtf8Codec.cs
T
2026-08-14 14:28:28 +08:00

29 lines
881 B
C#

using System;
using System.Text;
namespace Lskj.AgentBridge
{
/// <summary>
/// The bridge protocol is UTF-8 without replacement fallbacks. Silently
/// normalizing malformed bytes or unmatched UTF-16 surrogates could change
/// identifiers or business text after a caller calculated its binding.
/// </summary>
internal static class BridgeUtf8Codec
{
private static readonly Encoding StrictUtf8 =
new UTF8Encoding(false, true);
internal static string Decode(byte[] source)
{
if (source == null) throw new ArgumentNullException("source");
return StrictUtf8.GetString(source);
}
internal static byte[] Encode(string source)
{
if (source == null) throw new ArgumentNullException("source");
return StrictUtf8.GetBytes(source);
}
}
}