29 lines
881 B
C#
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);
|
|
}
|
|
}
|
|
}
|