OLD | NEW |
(Empty) | |
| 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 |
| 15 syntax = "proto3"; |
| 16 |
| 17 package google.bytestream; |
| 18 |
| 19 // #### Introduction |
| 20 // |
| 21 // The Byte Stream API enables a client to read and write a stream of bytes to |
| 22 // and from a resource. Resources have names, and these names are supplied in |
| 23 // the API calls below to identify the resource that is being read from or |
| 24 // written to. |
| 25 // |
| 26 // All implementations of the Byte Stream API export the interface defined here: |
| 27 // |
| 28 // * `Read()`: Reads the contents of a resource. |
| 29 // |
| 30 // * `Write()`: Writes the contents of a resource. The client can call `Write()` |
| 31 // multiple times with the same resource and can check the status of the write |
| 32 // by calling `QueryWriteStatus()`. |
| 33 // |
| 34 // #### Service parameters and metadata |
| 35 // |
| 36 // The ByteStream API provides no direct way to access/modify any metadata |
| 37 // associated with the resource. |
| 38 // |
| 39 // #### Errors |
| 40 // |
| 41 // The errors returned by the service are in the Google canonical error space. |
| 42 service ByteStream { |
| 43 // `Read()` is used to retrieve the contents of a resource as a sequence |
| 44 // of bytes. The bytes are returned in a sequence of responses, and the |
| 45 // responses are delivered as the results of a server-side streaming RPC. |
| 46 rpc Read(ReadRequest) returns (stream ReadResponse); |
| 47 |
| 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 |
| 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) returns (QueryWriteStatusRespons
e); |
| 87 } |
| 88 |
| 89 // Request object for ByteStream.Read. |
| 90 message ReadRequest { |
| 91 // The name of the resource to read. |
| 92 string resource_name = 1; |
| 93 |
| 94 // The offset for the first byte to return in the read, relative to the start |
| 95 // of the resource. |
| 96 // |
| 97 // A `read_offset` that is negative or greater than the size of the resource |
| 98 // will cause an `OUT_OF_RANGE` error. |
| 99 int64 read_offset = 2; |
| 100 |
| 101 // The maximum number of `data` bytes the server is allowed to return in the |
| 102 // sum of all `ReadResponse` messages. A `read_limit` of zero indicates that |
| 103 // there is no limit, and a negative `read_limit` will cause an error. |
| 104 // |
| 105 // If the stream returns fewer bytes than allowed by the `read_limit` and no |
| 106 // error occurred, the stream includes all data from the `read_offset` to the |
| 107 // end of the resource. |
| 108 int64 read_limit = 3; |
| 109 } |
| 110 |
| 111 // Response object for ByteStream.Read. |
| 112 message ReadResponse { |
| 113 // A portion of the data for the resource. The service **may** leave `data` |
| 114 // empty for any given `ReadResponse`. This enables the service to inform the |
| 115 // client that the request is still live while it is running an operation to |
| 116 // generate more data. |
| 117 bytes data = 10; |
| 118 } |
| 119 |
| 120 // Request object for ByteStream.Write. |
| 121 message WriteRequest { |
| 122 // The name of the resource to write. This **must** be set on the first |
| 123 // `WriteRequest` of each `Write()` action. If it is set on subsequent calls, |
| 124 // it **must** match the value of the first request. |
| 125 string resource_name = 1; |
| 126 |
| 127 // The offset from the beginning of the resource at which the data should be |
| 128 // written. It is required on all `WriteRequest`s. |
| 129 // |
| 130 // In the first `WriteRequest` of a `Write()` action, it indicates |
| 131 // the initial offset for the `Write()` call. The value **must** be equal to |
| 132 // the `committed_size` that a call to `QueryWriteStatus()` would return. |
| 133 // |
| 134 // On subsequent calls, this value **must** be set and **must** be equal to |
| 135 // the sum of the first `write_offset` and the sizes of all `data` bundles |
| 136 // sent previously on this stream. |
| 137 // |
| 138 // An incorrect value will cause an error. |
| 139 int64 write_offset = 2; |
| 140 |
| 141 // If `true`, this indicates that the write is complete. Sending any |
| 142 // `WriteRequest`s subsequent to one in which `finish_write` is `true` will |
| 143 // cause an error. |
| 144 bool finish_write = 3; |
| 145 |
| 146 // A portion of the data for the resource. The client **may** leave `data` |
| 147 // empty for any given `WriteRequest`. This enables the client to inform the |
| 148 // service that the request is still live while it is running an operation to |
| 149 // generate more data. |
| 150 bytes data = 10; |
| 151 } |
| 152 |
| 153 // Response object for ByteStream.Write. |
| 154 message WriteResponse { |
| 155 // The number of bytes that have been processed for the given resource. |
| 156 int64 committed_size = 1; |
| 157 } |
| 158 |
| 159 // Request object for ByteStream.QueryWriteStatus. |
| 160 message QueryWriteStatusRequest { |
| 161 // The name of the resource whose write status is being requested. |
| 162 string resource_name = 1; |
| 163 } |
| 164 |
| 165 // Response object for ByteStream.QueryWriteStatus. |
| 166 message QueryWriteStatusResponse { |
| 167 // The number of bytes that have been processed for the given resource. |
| 168 int64 committed_size = 1; |
| 169 |
| 170 // `complete` is `true` only if the client has sent a `WriteRequest` with |
| 171 // `finish_write` set to true, and the server has processed that request. |
| 172 bool complete = 2; |
| 173 } |
OLD | NEW |