forked from aloisdg/Ether.Network
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from Eastrall/feature/receive
Change receive process
- Loading branch information
Showing
9 changed files
with
30 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,20 @@ | ||
using System.IO; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Ether.Network.Packets | ||
{ | ||
internal sealed class NetPacketProcessor : IPacketProcessor | ||
{ | ||
/// <summary> | ||
/// Gets the <see cref="NetPacket"/> header size. | ||
/// </summary> | ||
/// <inheritdoc /> | ||
public int HeaderSize => sizeof(int); | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether the <see cref="NetPacket"/> header should be put in front of the buffer. | ||
/// </summary> | ||
/// <inheritdoc /> | ||
public bool IncludeHeader => false; | ||
|
||
/// <summary> | ||
/// Gets the <see cref="NetPacket"/> length size. | ||
/// </summary> | ||
/// <param name="buffer">Incoming buffer</param> | ||
/// <returns>Packet length</returns> | ||
public int GetLength(byte[] buffer) | ||
{ | ||
var packetLength = 0; | ||
/// <inheritdoc /> | ||
public int GetMessageLength(byte[] buffer) => BitConverter.ToInt32(buffer.Take(HeaderSize).ToArray(), 0); | ||
|
||
using (var memoryStream = new MemoryStream(buffer)) | ||
using (var binaryReader = new BinaryReader(memoryStream)) | ||
packetLength = binaryReader.ReadInt32(); | ||
|
||
return packetLength; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a <see cref="NetPacket"/> instance. | ||
/// </summary> | ||
/// <param name="buffer">Input buffer</param> | ||
/// <returns></returns> | ||
/// <inheritdoc /> | ||
public INetPacketStream CreatePacket(byte[] buffer) => new NetPacket(buffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters