XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension

【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension

修复XFEBuffer协议中UnPackBuffer方法不能分割Buffer的bug

75d7ba2
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

1 个文件 +21 -21
Modified XFE各类拓展/BufferExtension.cs +21 -21
@@ -99,7 +99,7 @@ namespace XFE各类拓展
99 99 }
100 100 for (int i = index; i < newBuffer.Length; i++)
101 101 {
102 newBuffer[i] = buffer[i];
102 newBuffer[i] = buffer[i - (targetBuffer.Length - originBuffer.Length) * indexes.Length];
103 103 }
104 104 return newBuffer;
105 105 }
@@ -142,7 +142,7 @@ namespace XFE各类拓展
142 142 var packedBuffer = new List<byte>();
143 143 for (int i = 0; i < buffers.Count; i++)
144 144 {
145 if (i != 0 && i != buffers.Count - 1)
145 if (i != 0)
146 146 packedBuffer.AddRange(new List<byte> { 0x01, 0x02, 0x03 });
147 147 packedBuffer.AddRange(buffers[i].Replace(new byte[] { 0x02, 0x03 }, new byte[] { 0x02, 0x02, 0x03 }).ToList());
148 148 }
@@ -171,10 +171,10 @@ namespace XFE各类拓展
171 171 /// <returns></returns>
172 172 public static List<byte[]> UnPackBuffer(this byte[] buffer)
173 173 {
174 var unPackedBuffers = buffer.Split(new byte[] { 0x01, 0x02, 0x03 });
175 foreach (var unPackedBuffer in unPackedBuffers)
174 var unPackedBuffers = new List<byte[]>();
175 foreach (var unPackedBuffer in buffer.Split(new byte[] { 0x01, 0x02, 0x03 }))
176 176 {
177 unPackedBuffer.Replace(new byte[] { 0x02, 0x02, 0x03 }, new byte[] { 0x02, 0x03 });
177 unPackedBuffers.Add(unPackedBuffer.Replace(new byte[] { 0x02, 0x02, 0x03 }, new byte[] { 0x02, 0x03 }));
178 178 }
179 179 return unPackedBuffers;
180 180 }
@@ -184,7 +184,7 @@ namespace XFE各类拓展
184 184 /// </summary>
185 185 public class XFEBuffer
186 186 {
187 private Dictionary<string, byte[]> xFEBuffer;
187 private Dictionary<string, byte[]> bufferDictionary;
188 188 private List<byte[]> headerBuffers;
189 189 /// <summary>
190 190 /// 长度
@@ -193,7 +193,7 @@ namespace XFE各类拓展
193 193 {
194 194 get
195 195 {
196 return xFEBuffer.Count;
196 return bufferDictionary.Count;
197 197 }
198 198 }
199 199 /// <summary>
@@ -205,11 +205,11 @@ namespace XFE各类拓展
205 205 {
206 206 get
207 207 {
208 return xFEBuffer[header];
208 return bufferDictionary[header];
209 209 }
210 210 set
211 211 {
212 xFEBuffer[header] = value;
212 bufferDictionary[header] = value;
213 213 }
214 214 }
215 215 /// <summary>
@@ -234,7 +234,7 @@ namespace XFE各类拓展
234 234 {
235 235 if (i % 2 == 0)
236 236 {
237 xFEBuffer.xFEBuffer.Add(Encoding.UTF8.GetString(buffers[i]), buffers[i + 1]);
237 xFEBuffer.bufferDictionary.Add(Encoding.UTF8.GetString(buffers[i]), buffers[i + 1]);
238 238 xFEBuffer.headerBuffers.Add(buffers[i]);
239 239 }
240 240 }
@@ -247,7 +247,7 @@ namespace XFE各类拓展
247 247 /// <param name="buffer">Buffer</param>
248 248 public void Add(string header, byte[] buffer)
249 249 {
250 xFEBuffer.Add(header, buffer);
250 bufferDictionary.Add(header, buffer);
251 251 headerBuffers.Add(Encoding.UTF8.GetBytes(header));
252 252 headerBuffers.Add(buffer);
253 253 }
@@ -262,7 +262,7 @@ namespace XFE各类拓展
262 262 throw new XFEExtensionException("头和Buffer必须成对输入");
263 263 for (int i = 0; i < @params.Length; i += 2)
264 264 {
265 xFEBuffer.Add(@params[i].ToString(), (byte[])@params[i + 1]);
265 bufferDictionary.Add(@params[i].ToString(), (byte[])@params[i + 1]);
266 266 headerBuffers.Add(Encoding.UTF8.GetBytes(@params[i].ToString()));
267 267 headerBuffers.Add((byte[])@params[i + 1]);
268 268 }
@@ -273,7 +273,7 @@ namespace XFE各类拓展
273 273 /// <param name="header">头</param>
274 274 public void Remove(string header)
275 275 {
276 xFEBuffer.Remove(header);
276 bufferDictionary.Remove(header);
277 277 headerBuffers.Remove(Encoding.UTF8.GetBytes(header));
278 278 }
279 279 /// <summary>
@@ -282,8 +282,8 @@ namespace XFE各类拓展
282 282 /// <param name="index"></param>
283 283 public void RemoveAt(int index)
284 284 {
285 var header = xFEBuffer.Keys.ToArray()[index];
286 xFEBuffer.Remove(header);
285 var header = bufferDictionary.Keys.ToArray()[index];
286 bufferDictionary.Remove(header);
287 287 headerBuffers.Remove(Encoding.UTF8.GetBytes(header));
288 288 }
289 289 /// <summary>
@@ -291,7 +291,7 @@ namespace XFE各类拓展
291 291 /// </summary>
292 292 public void Clear()
293 293 {
294 xFEBuffer.Clear();
294 bufferDictionary.Clear();
295 295 headerBuffers.Clear();
296 296 }
297 297 /// <summary>
@@ -301,7 +301,7 @@ namespace XFE各类拓展
301 301 /// <returns></returns>
302 302 public bool Contains(string header)
303 303 {
304 return xFEBuffer.ContainsKey(header);
304 return bufferDictionary.ContainsKey(header);
305 305 }
306 306 /// <summary>
307 307 /// 获取Buffer
@@ -310,7 +310,7 @@ namespace XFE各类拓展
310 310 /// <returns></returns>
311 311 public byte[] GetBuffer(string header)
312 312 {
313 return xFEBuffer[header];
313 return bufferDictionary[header];
314 314 }
315 315 /// <summary>
316 316 /// 获取头
@@ -318,14 +318,14 @@ namespace XFE各类拓展
318 318 /// <returns></returns>
319 319 public string[] GetHeaders()
320 320 {
321 return xFEBuffer.Keys.ToArray();
321 return bufferDictionary.Keys.ToArray();
322 322 }
323 323 /// <summary>
324 324 /// XFE的二进制数组协议
325 325 /// </summary>
326 326 public XFEBuffer()
327 327 {
328 xFEBuffer = new Dictionary<string, byte[]>();
328 bufferDictionary = new Dictionary<string, byte[]>();
329 329 }
330 330 /// <summary>
331 331 /// XFE的二进制数组协议
@@ -338,7 +338,7 @@ namespace XFE各类拓展
338 338 throw new XFEExtensionException("头和Buffer必须成对输入");
339 339 for (int i = 0; i < @params.Length; i += 2)
340 340 {
341 xFEBuffer.Add(@params[i].ToString(), (byte[])@params[i + 1]);
341 bufferDictionary.Add(@params[i].ToString(), (byte[])@params[i + 1]);
342 342 headerBuffers.Add(Encoding.UTF8.GetBytes(@params[i].ToString()));
343 343 headerBuffers.Add((byte[])@params[i + 1]);
344 344 }