mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
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:
committed by
Copybara-Service
parent
a8fe61d846
commit
ed511f962d
+15
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user