-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
18 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
29 changes: 29 additions & 0 deletions
29
src/dotnetCampus.Ipc/Utils/Extensions/IpcMessageExtension.cs
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using dotnetCampus.Ipc.Messages; | ||
|
||
namespace dotnetCampus.Ipc.Utils.Extensions; | ||
|
||
static class IpcMessageExtension | ||
{ | ||
public static IpcMessage Skip(this IpcMessage ipcMessage, int length) | ||
{ | ||
return new IpcMessage(ipcMessage.Tag, new IpcMessageBody(ipcMessage.Body.Buffer, | ||
ipcMessage.Body.Start + length, | ||
ipcMessage.Body.Length - length)); | ||
} | ||
|
||
public static bool TryReadBusinessHeader(this in IpcMessage ipcMessage, out ulong header) | ||
{ | ||
var length = sizeof(ulong); | ||
if (ipcMessage.Body.Length < length) | ||
{ | ||
header = 0; | ||
return false; | ||
} | ||
else | ||
{ | ||
header = BitConverter.ToUInt64(ipcMessage.Body.Buffer, ipcMessage.Body.Start); | ||
return true; | ||
} | ||
} | ||
} |