From 14e95107c987c52444dbc84b52c825314ef55538 Mon Sep 17 00:00:00 2001 From: ALEXTANGXIAO <574809918@qq.com> Date: Tue, 5 Sep 2023 23:57:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8ByteBuf=E6=B6=88?= =?UTF-8?q?=E9=99=A4=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 服务器ByteBuf消除警告 --- DotNet/Logic/src/Config/Core/ByteBuf.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/DotNet/Logic/src/Config/Core/ByteBuf.cs b/DotNet/Logic/src/Config/Core/ByteBuf.cs index 2a4a5236..564e2680 100644 --- a/DotNet/Logic/src/Config/Core/ByteBuf.cs +++ b/DotNet/Logic/src/Config/Core/ByteBuf.cs @@ -40,6 +40,7 @@ namespace Bright.Serialization public sealed class ByteBuf : ICloneable, IEquatable { +#pragma warning disable CS8618 public ByteBuf() { Bytes = Array.Empty(); @@ -76,6 +77,7 @@ namespace Bright.Serialization { return new ByteBuf(bytes, 0, bytes.Length); } +#pragma warning restore CS8618 public void Replace(byte[] bytes) { @@ -1015,20 +1017,24 @@ namespace Bright.Serialization return ((long)((ulong)x >> 1) ^ ((x & 1) << 63)); } - public void WriteString(string x) + public void WriteString(string? x) { var n = x != null ? Encoding.UTF8.GetByteCount(x) : 0; WriteSize(n); if (n > 0) { EnsureWrite(n); - Encoding.UTF8.GetBytes(x, 0, x.Length, Bytes, WriterIndex); + if (x != null) + { + Encoding.UTF8.GetBytes(x, 0, x.Length, this.Bytes, this.WriterIndex); + } + WriterIndex += n; } } // byte[], [start, end) - public static Func StringCacheFinder { get; set; } + public static Func? StringCacheFinder { get; set; } public string ReadString() { @@ -1056,14 +1062,14 @@ namespace Bright.Serialization } } - public void WriteBytes(byte[] x) + public void WriteBytes(byte[]? x) { var n = x != null ? x.Length : 0; WriteSize(n); if (n > 0) { EnsureWrite(n); - x.CopyTo(Bytes, WriterIndex); + x?.CopyTo(Bytes, WriterIndex); WriterIndex += n; } } @@ -1485,12 +1491,12 @@ namespace Bright.Serialization return string.Join(".", datas); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { return (obj is ByteBuf other) && Equals(other); } - public bool Equals(ByteBuf other) + public bool Equals(ByteBuf? other) { if (other == null) {