![dependabot[bot]](/assets/img/avatar_default.png)
Bumps the golang group with 6 updates in the / directory: | Package | From | To | | --- | --- | --- | | [github.com/Microsoft/hcsshim](https://github.com/Microsoft/hcsshim) | `0.12.7` | `0.12.9` | | [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) | `2.20.2` | `2.22.0` | | [github.com/onsi/gomega](https://github.com/onsi/gomega) | `1.34.2` | `1.36.0` | | [github.com/opencontainers/selinux](https://github.com/opencontainers/selinux) | `1.11.0` | `1.11.1` | | [github.com/safchain/ethtool](https://github.com/safchain/ethtool) | `0.4.1` | `0.5.9` | | [sigs.k8s.io/knftables](https://github.com/kubernetes-sigs/knftables) | `0.0.17` | `0.0.18` | Updates `github.com/Microsoft/hcsshim` from 0.12.7 to 0.12.9 - [Release notes](https://github.com/Microsoft/hcsshim/releases) - [Commits](https://github.com/Microsoft/hcsshim/compare/v0.12.7...v0.12.9) Updates `github.com/onsi/ginkgo/v2` from 2.20.2 to 2.22.0 - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v2.20.2...v2.22.0) Updates `github.com/onsi/gomega` from 1.34.2 to 1.36.0 - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.34.2...v1.36.0) Updates `github.com/opencontainers/selinux` from 1.11.0 to 1.11.1 - [Release notes](https://github.com/opencontainers/selinux/releases) - [Commits](https://github.com/opencontainers/selinux/compare/v1.11.0...v1.11.1) Updates `github.com/safchain/ethtool` from 0.4.1 to 0.5.9 - [Release notes](https://github.com/safchain/ethtool/releases) - [Commits](https://github.com/safchain/ethtool/compare/v0.4.1...v0.5.9) Updates `golang.org/x/sys` from 0.26.0 to 0.27.0 - [Commits](https://github.com/golang/sys/compare/v0.26.0...v0.27.0) Updates `sigs.k8s.io/knftables` from 0.0.17 to 0.0.18 - [Changelog](https://github.com/kubernetes-sigs/knftables/blob/master/CHANGELOG.md) - [Commits](https://github.com/kubernetes-sigs/knftables/compare/v0.0.17...v0.0.18) --- updated-dependencies: - dependency-name: github.com/Microsoft/hcsshim dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: github.com/opencontainers/selinux dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang - dependency-name: github.com/safchain/ethtool dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: sigs.k8s.io/knftables dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang ... Signed-off-by: dependabot[bot] <support@github.com>
101 lines
3.7 KiB
Go
101 lines
3.7 KiB
Go
// Go support for Protocol Buffers - Google's data interchange format
|
|
//
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// https://github.com/golang/protobuf
|
|
//
|
|
// Redistribution and use in source and binary forms, with or without
|
|
// modification, are permitted provided that the following conditions are
|
|
// met:
|
|
//
|
|
// * Redistributions of source code must retain the above copyright
|
|
// notice, this list of conditions and the following disclaimer.
|
|
// * Redistributions in binary form must reproduce the above
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
// in the documentation and/or other materials provided with the
|
|
// distribution.
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
// contributors may be used to endorse or promote products derived from
|
|
// this software without specific prior written permission.
|
|
//
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
package proto
|
|
|
|
// This file implements conversions between google.protobuf.Duration
|
|
// and time.Duration.
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
// Range of a Duration in seconds, as specified in
|
|
// google/protobuf/duration.proto. This is about 10,000 years in seconds.
|
|
maxSeconds = int64(10000 * 365.25 * 24 * 60 * 60)
|
|
minSeconds = -maxSeconds
|
|
)
|
|
|
|
// validateDuration determines whether the Duration is valid according to the
|
|
// definition in google/protobuf/duration.proto. A valid Duration
|
|
// may still be too large to fit into a time.Duration (the range of Duration
|
|
// is about 10,000 years, and the range of time.Duration is about 290).
|
|
func validateDuration(d *duration) error {
|
|
if d == nil {
|
|
return errors.New("duration: nil Duration")
|
|
}
|
|
if d.Seconds < minSeconds || d.Seconds > maxSeconds {
|
|
return fmt.Errorf("duration: %#v: seconds out of range", d)
|
|
}
|
|
if d.Nanos <= -1e9 || d.Nanos >= 1e9 {
|
|
return fmt.Errorf("duration: %#v: nanos out of range", d)
|
|
}
|
|
// Seconds and Nanos must have the same sign, unless d.Nanos is zero.
|
|
if (d.Seconds < 0 && d.Nanos > 0) || (d.Seconds > 0 && d.Nanos < 0) {
|
|
return fmt.Errorf("duration: %#v: seconds and nanos have different signs", d)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// DurationFromProto converts a Duration to a time.Duration. DurationFromProto
|
|
// returns an error if the Duration is invalid or is too large to be
|
|
// represented in a time.Duration.
|
|
func durationFromProto(p *duration) (time.Duration, error) {
|
|
if err := validateDuration(p); err != nil {
|
|
return 0, err
|
|
}
|
|
d := time.Duration(p.Seconds) * time.Second
|
|
if int64(d/time.Second) != p.Seconds {
|
|
return 0, fmt.Errorf("duration: %#v is out of range for time.Duration", p)
|
|
}
|
|
if p.Nanos != 0 {
|
|
d += time.Duration(p.Nanos)
|
|
if (d < 0) != (p.Nanos < 0) {
|
|
return 0, fmt.Errorf("duration: %#v is out of range for time.Duration", p)
|
|
}
|
|
}
|
|
return d, nil
|
|
}
|
|
|
|
// DurationProto converts a time.Duration to a Duration.
|
|
func durationProto(d time.Duration) *duration {
|
|
nanos := d.Nanoseconds()
|
|
secs := nanos / 1e9
|
|
nanos -= secs * 1e9
|
|
return &duration{
|
|
Seconds: secs,
|
|
Nanos: int32(nanos),
|
|
}
|
|
}
|