bytestream.proto 7.4 KB

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