| Index: third_party/grpc/src/csharp/Grpc.Core/Status.cs
|
| diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs b/third_party/grpc/src/csharp/Grpc.Core/Status.cs
|
| similarity index 51%
|
| copy from third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs
|
| copy to third_party/grpc/src/csharp/Grpc.Core/Status.cs
|
| index b19962794b0d052b467fd2007fd09ad1d7fe6d54..6bd8dc820bede9c8eadab9e4970cecc48723d373 100644
|
| --- a/third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs
|
| +++ b/third_party/grpc/src/csharp/Grpc.Core/Status.cs
|
| @@ -1,7 +1,6 @@
|
| -#region Copyright notice and license
|
| -// Protocol Buffers - Google's data interchange format
|
| -// Copyright 2008 Google Inc. All rights reserved.
|
| -// https://developers.google.com/protocol-buffers/
|
| +#region Copyright notice and license
|
| +// Copyright 2015, Google Inc.
|
| +// All rights reserved.
|
| //
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| @@ -30,50 +29,67 @@
|
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| #endregion
|
|
|
| -using System;
|
| +using Grpc.Core.Utils;
|
|
|
| -namespace Google.Protobuf
|
| +namespace Grpc.Core
|
| {
|
| /// <summary>
|
| - /// Provides a utility routine to copy small arrays much more quickly than Buffer.BlockCopy
|
| + /// Represents RPC result, which consists of <see cref="StatusCode"/> and an optional detail string.
|
| /// </summary>
|
| - internal static class ByteArray
|
| + public struct Status
|
| {
|
| /// <summary>
|
| - /// The threshold above which you should use Buffer.BlockCopy rather than ByteArray.Copy
|
| + /// Default result of a successful RPC. StatusCode=OK, empty details message.
|
| /// </summary>
|
| - private const int CopyThreshold = 12;
|
| + public static readonly Status DefaultSuccess = new Status(StatusCode.OK, "");
|
|
|
| /// <summary>
|
| - /// Determines which copy routine to use based on the number of bytes to be copied.
|
| + /// Default result of a cancelled RPC. StatusCode=Cancelled, empty details message.
|
| /// </summary>
|
| - internal static void Copy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count)
|
| + public static readonly Status DefaultCancelled = new Status(StatusCode.Cancelled, "");
|
| +
|
| + readonly StatusCode statusCode;
|
| + readonly string detail;
|
| +
|
| + /// <summary>
|
| + /// Creates a new instance of <c>Status</c>.
|
| + /// </summary>
|
| + /// <param name="statusCode">Status code.</param>
|
| + /// <param name="detail">Detail.</param>
|
| + public Status(StatusCode statusCode, string detail)
|
| {
|
| - if (count > CopyThreshold)
|
| - {
|
| - Buffer.BlockCopy(src, srcOffset, dst, dstOffset, count);
|
| - }
|
| - else
|
| + this.statusCode = statusCode;
|
| + this.detail = detail;
|
| + }
|
| +
|
| + /// <summary>
|
| + /// Gets the gRPC status code. OK indicates success, all other values indicate an error.
|
| + /// </summary>
|
| + public StatusCode StatusCode
|
| + {
|
| + get
|
| {
|
| - int stop = srcOffset + count;
|
| - for (int i = srcOffset; i < stop; i++)
|
| - {
|
| - dst[dstOffset++] = src[i];
|
| - }
|
| + return statusCode;
|
| }
|
| }
|
|
|
| /// <summary>
|
| - /// Reverses the order of bytes in the array
|
| + /// Gets the detail.
|
| /// </summary>
|
| - internal static void Reverse(byte[] bytes)
|
| + public string Detail
|
| {
|
| - for (int first = 0, last = bytes.Length - 1; first < last; first++, last--)
|
| + get
|
| {
|
| - byte temp = bytes[first];
|
| - bytes[first] = bytes[last];
|
| - bytes[last] = temp;
|
| + return detail;
|
| }
|
| }
|
| +
|
| + /// <summary>
|
| + /// Returns a <see cref="System.String"/> that represents the current <see cref="Grpc.Core.Status"/>.
|
| + /// </summary>
|
| + public override string ToString()
|
| + {
|
| + return string.Format("Status(StatusCode={0}, Detail=\"{1}\")", statusCode, detail);
|
| + }
|
| }
|
| -}
|
| +}
|
|
|