-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor to include interface and mock example (#129)
- Loading branch information
1 parent
adcbfbf
commit 15cfeeb
Showing
5 changed files
with
172 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace OpenTracing.Propagation | ||
{ | ||
/// <summary> | ||
/// A <see cref="IBinary"/> carrier for use with <see cref="ITracer.Extract{TCarrier}"/> only. It cannot be mutated, only read. | ||
/// </summary> | ||
/// <seealso cref="ITracer.Extract{TCarrier}"/> | ||
public class BinaryExtractAdapter : IBinary | ||
{ | ||
private readonly MemoryStream _stream; | ||
|
||
public BinaryExtractAdapter(MemoryStream stream) | ||
{ | ||
_stream = stream; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Set(MemoryStream stream) | ||
{ | ||
throw new NotSupportedException($"{nameof(BinaryExtractAdapter)} should only be used with {nameof(ITracer)}.{nameof(ITracer.Extract)}"); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public MemoryStream Get() | ||
{ | ||
return _stream; | ||
} | ||
} | ||
} |
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,32 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace OpenTracing.Propagation | ||
{ | ||
/// <summary> | ||
/// A <see cref="IBinary"/> carrier for use with <see cref="ITracer.Inject{TCarrier}"/> only. It cannot be read, only set. | ||
/// </summary> | ||
/// <seealso cref="ITracer.Extract{TCarrier}"/> | ||
public class BinaryInjectAdapter : IBinary | ||
{ | ||
private MemoryStream _stream; | ||
|
||
public BinaryInjectAdapter(MemoryStream stream) | ||
{ | ||
_stream = stream; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Set(MemoryStream stream) | ||
{ | ||
_stream = stream; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public MemoryStream Get() | ||
{ | ||
throw new NotSupportedException($"{nameof(BinaryInjectAdapter)} should only be used with {nameof(ITracer)}.{nameof(ITracer.Inject)}"); | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace OpenTracing.Propagation | ||
{ | ||
/// <summary> | ||
/// <see cref="IBinary"/> is a built-in carrier for <see cref="ITracer.Inject{TCarrier}"/> and | ||
/// <see cref="ITracer.Extract{TCarrier}"/>. IBinary implementations allow for the reading and writing of arbitrary streams. | ||
/// </summary> | ||
/// <seealso cref="ITracer.Inject{TCarrier}"/> | ||
/// <seealso cref="ITracer.Extract{TCarrier}"/> | ||
public interface IBinary | ||
{ | ||
/// <summary> | ||
/// Sets the backing MemoryStream of an <see cref="IBinary"/> store. | ||
/// </summary> | ||
/// <param name="stream">A memory-backed stream.</param> | ||
void Set(MemoryStream stream); | ||
|
||
/// <summary> | ||
/// Gets the backing MemoryStream of an <see cref="IBinary"/> store. | ||
/// </summary> | ||
/// <returns></returns> | ||
MemoryStream Get(); | ||
} | ||
} |