-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C#] Add infrastructure to support more wire protocols (#496)
* Add BackendProvider concept to support backend other than FasterKV. Add protocol byte to binary protocol to enable support for more protocols in the future. * Fix some typos and add some comments * add .idea to gitignore * Add constructor overload to avoid API change, tweaks to serialization performance. * remove unused import * Cleanup & minor perf improvements Co-authored-by: Tianyu Li <t-litianyu@microsoft.com> Co-authored-by: Badrish Chandramouli <badrishc@microsoft.com>
- Loading branch information
1 parent
8c0c6e1
commit ef016eb
Showing
14 changed files
with
240 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,3 +193,8 @@ packages/ | |
*.lib | ||
nativebin/ | ||
/cs/**/launchSettings.json | ||
|
||
# JetBrains | ||
cs/.idea/ | ||
cs/remote/.idea | ||
cs/libdpr/.idea |
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,31 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace FASTER.common | ||
{ | ||
/// <summary> | ||
/// Header for message batch | ||
/// Header for message batch (Little Endian server) | ||
/// [4 byte seqNo][1 byte protocol][3 byte numMessages] | ||
/// </summary> | ||
[StructLayout(LayoutKind.Explicit, Size = 8)] | ||
public unsafe struct BatchHeader | ||
public struct BatchHeader | ||
{ | ||
/// <summary> | ||
/// Size | ||
/// </summary> | ||
public const int Size = 8; | ||
|
||
/// <summary> | ||
/// Sequence number for batch | ||
/// Sequence number. | ||
/// </summary> | ||
[FieldOffset(0)] | ||
public int seqNo; | ||
public int SeqNo; | ||
|
||
/// <summary> | ||
/// Number of messsages packed in batch | ||
/// Lower-order 8 bits are protocol type, higher-order 24 bits are num messages. | ||
/// </summary> | ||
[FieldOffset(4)] | ||
public int numMessages; | ||
private int numMessagesAndProtocolType; | ||
|
||
/// <summary> | ||
/// Number of messages packed in batch | ||
/// </summary> | ||
public int NumMessages | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get => (int)((uint)numMessagesAndProtocolType >> 8); | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
set { numMessagesAndProtocolType = (value << 8) | (numMessagesAndProtocolType & 0xFF); } | ||
} | ||
|
||
/// <summary> | ||
/// Wire protocol this batch is written in | ||
/// </summary> | ||
public WireFormat Protocol | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get => (WireFormat)(numMessagesAndProtocolType & 0xFF); | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
set { numMessagesAndProtocolType = (numMessagesAndProtocolType & ~0xFF) | ((int)value & 0xFF); } | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
cs/remote/src/FASTER.server/WireFormat.cs → cs/remote/src/FASTER.common/WireFormat.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
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
Oops, something went wrong.