create
This commit is contained in:
82
Pods/gRPC-C++/src/cpp/util/byte_buffer_cc.cc
generated
Normal file
82
Pods/gRPC-C++/src/cpp/util/byte_buffer_cc.cc
generated
Normal file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2015 gRPC authors.
|
||||
//
|
||||
// Licensed 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 <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include <grpc/byte_buffer.h>
|
||||
#include <grpc/byte_buffer_reader.h>
|
||||
#include <grpc/grpc.h>
|
||||
#include <grpc/impl/compression_types.h>
|
||||
#include <grpc/slice.h>
|
||||
#include <grpcpp/support/byte_buffer.h>
|
||||
#include <grpcpp/support/slice.h>
|
||||
#include <grpcpp/support/status.h>
|
||||
|
||||
namespace grpc {
|
||||
|
||||
Status ByteBuffer::TrySingleSlice(Slice* slice) const {
|
||||
if (!buffer_) {
|
||||
return Status(StatusCode::FAILED_PRECONDITION, "Buffer not initialized");
|
||||
}
|
||||
if ((buffer_->type == GRPC_BB_RAW) &&
|
||||
(buffer_->data.raw.compression == GRPC_COMPRESS_NONE) &&
|
||||
(buffer_->data.raw.slice_buffer.count == 1)) {
|
||||
grpc_slice internal_slice = buffer_->data.raw.slice_buffer.slices[0];
|
||||
*slice = Slice(internal_slice, Slice::ADD_REF);
|
||||
return Status::OK;
|
||||
} else {
|
||||
return Status(StatusCode::FAILED_PRECONDITION,
|
||||
"Buffer isn't made up of a single uncompressed slice.");
|
||||
}
|
||||
}
|
||||
|
||||
Status ByteBuffer::DumpToSingleSlice(Slice* slice) const {
|
||||
if (!buffer_) {
|
||||
return Status(StatusCode::FAILED_PRECONDITION, "Buffer not initialized");
|
||||
}
|
||||
grpc_byte_buffer_reader reader;
|
||||
if (!grpc_byte_buffer_reader_init(&reader, buffer_)) {
|
||||
return Status(StatusCode::INTERNAL,
|
||||
"Couldn't initialize byte buffer reader");
|
||||
}
|
||||
grpc_slice s = grpc_byte_buffer_reader_readall(&reader);
|
||||
*slice = Slice(s, Slice::STEAL_REF);
|
||||
grpc_byte_buffer_reader_destroy(&reader);
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status ByteBuffer::Dump(std::vector<Slice>* slices) const {
|
||||
slices->clear();
|
||||
if (!buffer_) {
|
||||
return Status(StatusCode::FAILED_PRECONDITION, "Buffer not initialized");
|
||||
}
|
||||
grpc_byte_buffer_reader reader;
|
||||
if (!grpc_byte_buffer_reader_init(&reader, buffer_)) {
|
||||
return Status(StatusCode::INTERNAL,
|
||||
"Couldn't initialize byte buffer reader");
|
||||
}
|
||||
grpc_slice s;
|
||||
while (grpc_byte_buffer_reader_next(&reader, &s)) {
|
||||
slices->push_back(Slice(s, Slice::STEAL_REF));
|
||||
}
|
||||
grpc_byte_buffer_reader_destroy(&reader);
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
} // namespace grpc
|
||||
28
Pods/gRPC-C++/src/cpp/util/status.cc
generated
Normal file
28
Pods/gRPC-C++/src/cpp/util/status.cc
generated
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2015 gRPC authors.
|
||||
//
|
||||
// Licensed 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 <memory>
|
||||
|
||||
#include <grpcpp/support/status.h>
|
||||
|
||||
namespace grpc {
|
||||
|
||||
const Status& Status::OK = Status();
|
||||
const Status& Status::CANCELLED = Status(StatusCode::CANCELLED, "");
|
||||
|
||||
} // namespace grpc
|
||||
27
Pods/gRPC-C++/src/cpp/util/string_ref.cc
generated
Normal file
27
Pods/gRPC-C++/src/cpp/util/string_ref.cc
generated
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2015 gRPC authors.
|
||||
//
|
||||
// Licensed 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 <stddef.h>
|
||||
|
||||
#include <grpcpp/support/string_ref.h>
|
||||
|
||||
namespace grpc {
|
||||
|
||||
const size_t string_ref::npos = static_cast<size_t>(-1);
|
||||
|
||||
} // namespace grpc
|
||||
79
Pods/gRPC-C++/src/cpp/util/time_cc.cc
generated
Normal file
79
Pods/gRPC-C++/src/cpp/util/time_cc.cc
generated
Normal file
@@ -0,0 +1,79 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2015 gRPC authors.
|
||||
//
|
||||
// Licensed 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 <chrono>
|
||||
#include <cstdint>
|
||||
|
||||
#include <grpc/support/time.h>
|
||||
#include <grpcpp/support/time.h>
|
||||
|
||||
// IWYU pragma: no_include <ratio>
|
||||
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::nanoseconds;
|
||||
using std::chrono::seconds;
|
||||
using std::chrono::system_clock;
|
||||
|
||||
namespace grpc {
|
||||
|
||||
void Timepoint2Timespec(const system_clock::time_point& from,
|
||||
gpr_timespec* to) {
|
||||
system_clock::duration deadline = from.time_since_epoch();
|
||||
seconds secs = duration_cast<seconds>(deadline);
|
||||
if (from == system_clock::time_point::max() ||
|
||||
secs.count() >= gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec ||
|
||||
secs.count() < 0) {
|
||||
*to = gpr_inf_future(GPR_CLOCK_REALTIME);
|
||||
return;
|
||||
}
|
||||
nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs);
|
||||
to->tv_sec = static_cast<int64_t>(secs.count());
|
||||
to->tv_nsec = static_cast<int32_t>(nsecs.count());
|
||||
to->clock_type = GPR_CLOCK_REALTIME;
|
||||
}
|
||||
|
||||
void TimepointHR2Timespec(const high_resolution_clock::time_point& from,
|
||||
gpr_timespec* to) {
|
||||
high_resolution_clock::duration deadline = from.time_since_epoch();
|
||||
seconds secs = duration_cast<seconds>(deadline);
|
||||
if (from == high_resolution_clock::time_point::max() ||
|
||||
secs.count() >= gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec ||
|
||||
secs.count() < 0) {
|
||||
*to = gpr_inf_future(GPR_CLOCK_REALTIME);
|
||||
return;
|
||||
}
|
||||
nanoseconds nsecs = duration_cast<nanoseconds>(deadline - secs);
|
||||
to->tv_sec = static_cast<int64_t>(secs.count());
|
||||
to->tv_nsec = static_cast<int32_t>(nsecs.count());
|
||||
to->clock_type = GPR_CLOCK_REALTIME;
|
||||
}
|
||||
|
||||
system_clock::time_point Timespec2Timepoint(gpr_timespec t) {
|
||||
if (gpr_time_cmp(t, gpr_inf_future(t.clock_type)) == 0) {
|
||||
return system_clock::time_point::max();
|
||||
}
|
||||
t = gpr_convert_clock_type(t, GPR_CLOCK_REALTIME);
|
||||
system_clock::time_point tp;
|
||||
tp += duration_cast<system_clock::time_point::duration>(seconds(t.tv_sec));
|
||||
tp +=
|
||||
duration_cast<system_clock::time_point::duration>(nanoseconds(t.tv_nsec));
|
||||
return tp;
|
||||
}
|
||||
|
||||
} // namespace grpc
|
||||
Reference in New Issue
Block a user