[
https://issues.apache.org/jira/browse/TINKERPOP-3161?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18020777#comment-18020777
]
ASF GitHub Bot commented on TINKERPOP-3161:
-------------------------------------------
andreachild commented on code in PR #3206:
URL: https://github.com/apache/tinkerpop/pull/3206#discussion_r2353750963
##########
gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphBinary/StreamExtensions.cs:
##########
@@ -59,6 +59,31 @@ public static async Task<byte> ReadByteAsync(this Stream
stream, CancellationTok
return readBuffer[0];
}
+ /// <summary>
+ /// Asynchronously writes a <see cref="sbyte"/> to a <see
cref="Stream"/>.
+ /// </summary>
+ /// <param name="stream">The <see cref="Stream"/> to write the <see
cref="sbyte"/> to.</param>
+ /// <param name="value">The <see cref="sbyte"/> to write.</param>
+ /// <param name="cancellationToken">The token to cancel the operation.
The default value is None.</param>
+ public static async Task WriteSByteAsync(this Stream stream, sbyte
value,
+ CancellationToken cancellationToken = default)
+ {
+ await stream.WriteAsync(new[] {(byte)value}, 0, 1,
cancellationToken).ConfigureAwait(false);
+ }
+
+ /// <summary>
+ /// Asynchronously reads a <see cref="sbyte"/> from a <see
cref="Stream"/>.
+ /// </summary>
+ /// <param name="stream">The <see cref="Stream"/> to read from.</param>
+ /// <param name="cancellationToken">The token to cancel the operation.
The default value is None.</param>
+ /// <returns>The read <see cref="sbyte"/>.</returns>
+ public static async Task<sbyte> ReadSByteAsync(this Stream stream,
CancellationToken cancellationToken = default)
+ {
+ var readBuffer = new byte[1];
+ await stream.ReadAsync(readBuffer, 0, 1,
cancellationToken).ConfigureAwait(false);
+ return (sbyte)readBuffer[0];
+ }
+
Review Comment:
Can this delegate to existing ReadByteAsync?
```suggestion
public static async Task<sbyte> ReadSByteAsync(this Stream stream,
CancellationToken cancellationToken = default)
{
return (sbyte)await
stream.ReadByteAsync(cancellationToken).ConfigureAwait(false);
}
```
> Switched to signed bytes in .net
> --------------------------------
>
> Key: TINKERPOP-3161
> URL: https://issues.apache.org/jira/browse/TINKERPOP-3161
> Project: TinkerPop
> Issue Type: Improvement
> Components: dotnet
> Affects Versions: 3.7.3
> Reporter: Cole Greer
> Priority: Critical
> Labels: breaking
>
> The `Byte` type in our serializers represents a signed 8-bit integer (as this
> is what byte in Java represents), however this currently maps to `byte` in
> .net, which is an unsigned value. The .net serializers should be updated to
> use `sbyte` instead, to be consistent with the rest of TinkerPop.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)