bytestream.proto 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // Copyright 2016 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.bytestream;
  16. import "google/api/annotations.proto";
  17. import "google/protobuf/wrappers.proto";
  18. option java_outer_classname = "ByteStreamProto";
  19. option java_package = "com.google.bytestream";
  20. // #### Introduction
  21. //
  22. // The Byte Stream API enables a client to read and write a stream of bytes to
  23. // and from a resource. Resources have names, and these names are supplied in
  24. // the API calls below to identify the resource that is being read from or
  25. // written to.
  26. //
  27. // All implementations of the Byte Stream API export the interface defined here:
  28. //
  29. // * `Read()`: Reads the contents of a resource.
  30. //
  31. // * `Write()`: Writes the contents of a resource. The client can call `Write()`
  32. // multiple times with the same resource and can check the status of the write
  33. // by calling `QueryWriteStatus()`.
  34. //
  35. // #### Service parameters and metadata
  36. //
  37. // The ByteStream API provides no direct way to access/modify any metadata
  38. // associated with the resource.
  39. //
  40. // #### Errors
  41. //
  42. // The errors returned by the service are in the Google canonical error space.
  43. service ByteStream {
  44. // `Read()` is used to retrieve the contents of a resource as a sequence
  45. // of bytes. The bytes are returned in a sequence of responses, and the
  46. // responses are delivered as the results of a server-side streaming RPC.
  47. rpc Read(ReadRequest) returns (stream ReadResponse);
  48. // `Write()` is used to send the contents of a resource as a sequence of
  49. // bytes. The bytes are sent in a sequence of request protos of a client-side
  50. // streaming RPC.
  51. //
  52. // A `Write()` action is resumable. If there is an error or the connection is
  53. // broken during the `Write()`, the client should check the status of the
  54. // `Write()` by calling `QueryWriteStatus()` and continue writing from the
  55. // returned `committed_size`. This may be less than the amount of data the
  56. // client previously sent.
  57. //
  58. // Calling `Write()` on a resource name that was previously written and
  59. // finalized could cause an error, depending on whether the underlying service
  60. // allows over-writing of previously written resources.
  61. //
  62. // When the client closes the request channel, the service will respond with
  63. // a `WriteResponse`. The service will not view the resource as `complete`
  64. // until the client has sent a `WriteRequest` with `finish_write` set to
  65. // `true`. Sending any requests on a stream after sending a request with
  66. // `finish_write` set to `true` will cause an error. The client **should**
  67. // check the `WriteResponse` it receives to determine how much data the
  68. // service was able to commit and whether the service views the resource as
  69. // `complete` or not.
  70. rpc Write(stream WriteRequest) returns (WriteResponse);
  71. // `QueryWriteStatus()` is used to find the `committed_size` for a resource
  72. // that is being written, which can then be used as the `write_offset` for
  73. // the next `Write()` call.
  74. //
  75. // If the resource does not exist (i.e., the resource has been deleted, or the
  76. // first `Write()` has not yet reached the service), this method returns the
  77. // error `NOT_FOUND`.
  78. //
  79. // The client **may** call `QueryWriteStatus()` at any time to determine how
  80. // much data has been processed for this resource. This is useful if the
  81. // client is buffering data and needs to know which data can be safely
  82. // evicted. For any sequence of `QueryWriteStatus()` calls for a given
  83. // resource name, the sequence of returned `committed_size` values will be
  84. // non-decreasing.
  85. rpc QueryWriteStatus(QueryWriteStatusRequest) returns (QueryWriteStatusResponse);
  86. }
  87. // Request object for ByteStream.Read.
  88. message ReadRequest {
  89. // The name of the resource to read.
  90. string resource_name = 1;
  91. // The offset for the first byte to return in the read, relative to the start
  92. // of the resource.
  93. //
  94. // A `read_offset` that is negative or greater than the size of the resource
  95. // will cause an `OUT_OF_RANGE` error.
  96. int64 read_offset = 2;
  97. // The maximum number of `data` bytes the server is allowed to return in the
  98. // sum of all `ReadResponse` messages. A `read_limit` of zero indicates that
  99. // there is no limit, and a negative `read_limit` will cause an error.
  100. //
  101. // If the stream returns fewer bytes than allowed by the `read_limit` and no
  102. // error occurred, the stream includes all data from the `read_offset` to the
  103. // end of the resource.
  104. int64 read_limit = 3;
  105. }
  106. // Response object for ByteStream.Read.
  107. message ReadResponse {
  108. // A portion of the data for the resource. The service **may** leave `data`
  109. // empty for any given `ReadResponse`. This enables the service to inform the
  110. // client that the request is still live while it is running an operation to
  111. // generate more data.
  112. bytes data = 10;
  113. }
  114. // Request object for ByteStream.Write.
  115. message WriteRequest {
  116. // The name of the resource to write. This **must** be set on the first
  117. // `WriteRequest` of each `Write()` action. If it is set on subsequent calls,
  118. // it **must** match the value of the first request.
  119. string resource_name = 1;
  120. // The offset from the beginning of the resource at which the data should be
  121. // written. It is required on all `WriteRequest`s.
  122. //
  123. // In the first `WriteRequest` of a `Write()` action, it indicates
  124. // the initial offset for the `Write()` call. The value **must** be equal to
  125. // the `committed_size` that a call to `QueryWriteStatus()` would return.
  126. //
  127. // On subsequent calls, this value **must** be set and **must** be equal to
  128. // the sum of the first `write_offset` and the sizes of all `data` bundles
  129. // sent previously on this stream.
  130. //
  131. // An incorrect value will cause an error.
  132. int64 write_offset = 2;
  133. // If `true`, this indicates that the write is complete. Sending any
  134. // `WriteRequest`s subsequent to one in which `finish_write` is `true` will
  135. // cause an error.
  136. bool finish_write = 3;
  137. // A portion of the data for the resource. The client **may** leave `data`
  138. // empty for any given `WriteRequest`. This enables the client to inform the
  139. // service that the request is still live while it is running an operation to
  140. // generate more data.
  141. bytes data = 10;
  142. }
  143. // Response object for ByteStream.Write.
  144. message WriteResponse {
  145. // The number of bytes that have been processed for the given resource.
  146. int64 committed_size = 1;
  147. }
  148. // Request object for ByteStream.QueryWriteStatus.
  149. message QueryWriteStatusRequest {
  150. // The name of the resource whose write status is being requested.
  151. string resource_name = 1;
  152. }
  153. // Response object for ByteStream.QueryWriteStatus.
  154. message QueryWriteStatusResponse {
  155. // The number of bytes that have been processed for the given resource.
  156. int64 committed_size = 1;
  157. // `complete` is `true` only if the client has sent a `WriteRequest` with
  158. // `finish_write` set to true, and the server has processed that request.
  159. bool complete = 2;
  160. }