mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Make sure we never generate a payload ID of 0.
PiperOrigin-RevId: 632210716
This commit is contained in:
committed by
Copybara-Service
parent
3f1a6d63d1
commit
5d6735371b
@@ -81,6 +81,7 @@ cc_library(
|
||||
"//internal/platform:util",
|
||||
"//proto:connections_enums_cc_proto",
|
||||
"@com_google_absl//absl/functional:any_invocable",
|
||||
"@com_google_absl//absl/random",
|
||||
"@com_google_absl//absl/types:variant",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -17,16 +17,17 @@
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
|
||||
#include "absl/random/random.h"
|
||||
#include "connections/payload_type.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/file.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/prng.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -138,7 +139,11 @@ void Payload::SetOffset(size_t offset) {
|
||||
size_t Payload::GetOffset() { return offset_; }
|
||||
|
||||
// Generate Payload Id; to be passed to outgoing file constructor.
|
||||
Payload::Id Payload::GenerateId() { return Prng().NextInt64(); }
|
||||
Payload::Id Payload::GenerateId() {
|
||||
absl::BitGen bitgen;
|
||||
return absl::Uniform<Payload::Id>(absl::IntervalOpenClosed, bitgen, 0,
|
||||
std::numeric_limits<Payload::Id>::max());
|
||||
}
|
||||
|
||||
PayloadType Payload::FindType() const {
|
||||
return static_cast<PayloadType>(content_.index());
|
||||
|
||||
Reference in New Issue
Block a user