mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
[JNI] Refactor Payload and PayloadId/PayloadType
PiperOrigin-RevId: 640490438
This commit is contained in:
committed by
Copybara-Service
parent
37327e79f3
commit
334ef7a3e1
@@ -34,7 +34,7 @@ namespace connections {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string getFileName(const std::string& s) {
|
||||
std::string FormatFileName(const std::string& s) {
|
||||
std::string s_copy(s);
|
||||
std::replace(s_copy.begin(), s_copy.end(), '\\',
|
||||
'/'); // replace all '\\' to '/'
|
||||
@@ -66,13 +66,7 @@ Payload::Payload(const ByteArray& bytes)
|
||||
|
||||
Payload::Payload(InputFile input_file)
|
||||
: id_(std::hash<std::string>()(input_file.GetFilePath())),
|
||||
file_name_(getFileName(input_file.GetFilePath())),
|
||||
type_(PayloadType::kFile),
|
||||
content_(std::move(input_file)) {}
|
||||
|
||||
Payload::Payload(Id id, InputFile input_file)
|
||||
: id_(id),
|
||||
file_name_(getFileName(input_file.GetFilePath())),
|
||||
file_name_(FormatFileName(input_file.GetFilePath())),
|
||||
type_(PayloadType::kFile),
|
||||
content_(std::move(input_file)) {}
|
||||
|
||||
@@ -94,6 +88,12 @@ Payload::Payload(Id id, ByteArray&& bytes)
|
||||
Payload::Payload(Id id, const ByteArray& bytes)
|
||||
: id_(id), type_(PayloadType::kBytes), content_(bytes) {}
|
||||
|
||||
Payload::Payload(Id id, InputFile input_file)
|
||||
: id_(id),
|
||||
file_name_(FormatFileName(input_file.GetFilePath())),
|
||||
type_(PayloadType::kFile),
|
||||
content_(std::move(input_file)) {}
|
||||
|
||||
Payload::Payload(Id id, std::string parent_folder, std::string file_name,
|
||||
InputFile input_file)
|
||||
: id_(id),
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
// TODO(edwinwu) : re-number kFile(3->2) and kStream(2->3) to align with Android
|
||||
// platform. Need to test for other platforms handled this to avoid side effect.
|
||||
enum class PayloadType { kUnknown = 0, kBytes = 1, kFile = 2, kStream = 3 };
|
||||
enum PayloadDirection {
|
||||
UNKNOWN_DIRECTION_PAYLOAD = 0,
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "connections/payload.h"
|
||||
#include "connections/strategy.h"
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "sharing/nearby_connections_service.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user