Support payload offsets

Support sending a file or stream payload from a non-zero offset.
This allows the clients to resume a transfer. Upper layers should use
this feature only when both sides support it.

PiperOrigin-RevId: 385137570
This commit is contained in:
Janusz Sobczak
2021-07-16 06:52:45 -07:00
committed by Copybara-Service
parent a8fe61d846
commit ed511f962d
14 changed files with 293 additions and 15 deletions
+15 -4
View File
@@ -89,17 +89,28 @@ class Payload {
// Returns Payload type.
Type GetType() const { return type_; }
// Sets the payload offset in bytes
void SetOffset(size_t offset) {
CHECK(type_ == Type::kFile || type_ == Type::kStream);
InputFile* file = AsFile();
if (file != nullptr) {
CHECK(offset < file->GetTotalSize());
}
offset_ = offset;
}
size_t GetOffset() { return offset_; }
// Generate Payload Id; to be passed to outgoing file constructor.
static Id GenerateId() { return Prng().NextInt64(); }
private:
Type FindType(const Content& content) const {
return static_cast<Type>(content_.index());
}
Type FindType() const { return static_cast<Type>(content_.index()); }
Content content_;
Id id_{GenerateId()};
Type type_{FindType(content_)};
Type type_{FindType()};
size_t offset_{0};
};
} // namespace connections