cast.cpp 922 B

1234567891011121314151617181920212223
  1. #include <library/cpp/protobuf/interop/cast.h>
  2. #include <google/protobuf/duration.pb.h>
  3. #include <google/protobuf/timestamp.pb.h>
  4. #include <google/protobuf/util/time_util.h>
  5. namespace NProtoInterop {
  6. google::protobuf::Duration CastToProto(TDuration duration) {
  7. return google::protobuf::util::TimeUtil::MicrosecondsToDuration(duration.MicroSeconds());
  8. }
  9. google::protobuf::Timestamp CastToProto(TInstant instant) {
  10. return google::protobuf::util::TimeUtil::MicrosecondsToTimestamp(instant.MicroSeconds());
  11. }
  12. TDuration CastFromProto(const google::protobuf::Duration& duration) {
  13. return TDuration::MicroSeconds(google::protobuf::util::TimeUtil::DurationToMicroseconds(duration));
  14. }
  15. TInstant CastFromProto(const google::protobuf::Timestamp& timestamp) {
  16. return TInstant::MicroSeconds(google::protobuf::util::TimeUtil::TimestampToMicroseconds(timestamp));
  17. }
  18. }