forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cc
More file actions
88 lines (72 loc) · 2.63 KB
/
Copy pathcommon.cc
File metadata and controls
88 lines (72 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "plasma/common.h"
#include <random>
#include "plasma/plasma_generated.h"
namespace plasma {
using arrow::Status;
UniqueID UniqueID::from_random() {
UniqueID id;
uint8_t* data = id.mutable_data();
std::random_device engine;
for (int i = 0; i < kUniqueIDSize; i++) {
data[i] = static_cast<uint8_t>(engine());
}
return id;
}
UniqueID UniqueID::from_binary(const std::string& binary) {
UniqueID id;
std::memcpy(&id, binary.data(), sizeof(id));
return id;
}
const uint8_t* UniqueID::data() const { return id_; }
uint8_t* UniqueID::mutable_data() { return id_; }
std::string UniqueID::binary() const {
return std::string(reinterpret_cast<const char*>(id_), kUniqueIDSize);
}
std::string UniqueID::hex() const {
constexpr char hex[] = "0123456789abcdef";
std::string result;
for (int i = 0; i < kUniqueIDSize; i++) {
unsigned int val = id_[i];
result.push_back(hex[val >> 4]);
result.push_back(hex[val & 0xf]);
}
return result;
}
bool UniqueID::operator==(const UniqueID& rhs) const {
return std::memcmp(data(), rhs.data(), kUniqueIDSize) == 0;
}
Status plasma_error_status(int plasma_error) {
switch (plasma_error) {
case PlasmaError_OK:
return Status::OK();
case PlasmaError_ObjectExists:
return Status::PlasmaObjectExists("object already exists in the plasma store");
case PlasmaError_ObjectNonexistent:
return Status::PlasmaObjectNonexistent("object does not exist in the plasma store");
case PlasmaError_OutOfMemory:
return Status::PlasmaStoreFull("object does not fit in the plasma store");
default:
ARROW_LOG(FATAL) << "unknown plasma error code " << plasma_error;
}
return Status::OK();
}
ARROW_EXPORT int ObjectStatusLocal = ObjectStatus_Local;
ARROW_EXPORT int ObjectStatusRemote = ObjectStatus_Remote;
const PlasmaStoreInfo* plasma_config;
} // namespace plasma