Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
encoding/protobuf: don't map google.protobuf types
Browse files Browse the repository at this point in the history
(at least not yet)

Issue #5

Change-Id: If8430cf8ec9bb376bcf0c69ec385f1f0d066c4e6
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2374
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Jul 1, 2019
1 parent eae20e0 commit f9bd63e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 36 deletions.
13 changes: 8 additions & 5 deletions encoding/protobuf/testdata/attributes.proto.out.cue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// limitations under the License.
package v1

import "time"
import (
"github.com/golang/protobuf/ptypes/duration"
"github.com/golang/protobuf/ptypes/timestamp"
)

// Attributes represents a set of typed name/value pairs. Many of Mixer's
// API either consume and/or return attributes.
Expand Down Expand Up @@ -77,10 +80,10 @@ Attributes_AttributeValue: {
bytesValue?: bytes @protobuf(6,name=bytes_value)
} | {
// Used for values of type TIMESTAMP
timestampValue?: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
timestampValue?: timestamp.Timestamp @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
} | {
// Used for values of type DURATION
durationValue?: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
durationValue?: duration.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
} | {
// Used for values of type STRING_MAP
stringMapValue?: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
Expand Down Expand Up @@ -116,10 +119,10 @@ CompressedAttributes: {
bools <_>: bool

// Holds attributes of type TIMESTAMP
timestamps <_>: time.Time
timestamps <_>: timestamp.Timestamp

// Holds attributes of type DURATION
durations <_>: time.Duration
durations <_>: duration.Duration

// Holds attributes of type BYTES
bytes <_>: bytes
Expand Down
10 changes: 5 additions & 5 deletions encoding/protobuf/testdata/client_config.proto.out.cue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
package client

import (
"github.com/golang/protobuf/ptypes/duration"
"istio.io/api/mixer/v1"
"time"
)

// Specifies the behavior when the client is unable to connect to Mixer.
Expand All @@ -36,10 +36,10 @@ NetworkFailPolicy: {

// Base time to wait between retries. Will be adjusted by exponential
// backoff and jitter.
baseRetryWait?: time.Duration @protobuf(3,type=google.protobuf.Duration,name=base_retry_wait)
baseRetryWait?: duration.Duration @protobuf(3,type=google.protobuf.Duration,name=base_retry_wait)

// Max time to wait between retries.
maxRetryWait?: time.Duration @protobuf(4,type=google.protobuf.Duration,name=max_retry_wait)
maxRetryWait?: duration.Duration @protobuf(4,type=google.protobuf.Duration,name=max_retry_wait)
}

// Example of single-value enum.
Expand Down Expand Up @@ -108,7 +108,7 @@ TransportConfig: {

// Specify refresh interval to write Mixer client statistics to Envoy share
// memory. If not specified, the interval is 10 seconds.
statsUpdateInterval?: time.Duration @protobuf(5,type=google.protobuf.Duration,name=stats_update_interval)
statsUpdateInterval?: duration.Duration @protobuf(5,type=google.protobuf.Duration,name=stats_update_interval)

// Name of the cluster that will forward check calls to a pool of mixer
// servers. Defaults to "mixer_server". By using different names for
Expand Down Expand Up @@ -183,5 +183,5 @@ TcpClientConfig: {
// Specify report interval to send periodical reports for long TCP
// connections. If not specified, the interval is 10 seconds. This interval
// should not be less than 1 second, otherwise it will be reset to 1 second.
reportInterval?: time.Duration @protobuf(6,type=google.protobuf.Duration,name=report_interval)
reportInterval?: duration.Duration @protobuf(6,type=google.protobuf.Duration,name=report_interval)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// limitations under the License.
package v1

import "time"
import (
"github.com/golang/protobuf/ptypes/duration"
"github.com/golang/protobuf/ptypes/timestamp"
)

// Attributes represents a set of typed name/value pairs. Many of Mixer's
// API either consume and/or return attributes.
Expand Down Expand Up @@ -77,10 +80,10 @@ Attributes_AttributeValue: {
bytesValue?: bytes @protobuf(6,name=bytes_value)
} | {
// Used for values of type TIMESTAMP
timestampValue?: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
timestampValue?: timestamp.Timestamp @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
} | {
// Used for values of type DURATION
durationValue?: time.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
durationValue?: duration.Duration @protobuf(8,type=google.protobuf.Duration,name=duration_value)
} | {
// Used for values of type STRING_MAP
stringMapValue?: Attributes_StringMap @protobuf(9,type=StringMap,name=string_map_value)
Expand Down Expand Up @@ -116,10 +119,10 @@ CompressedAttributes: {
bools <_>: bool

// Holds attributes of type TIMESTAMP
timestamps <_>: time.Time
timestamps <_>: timestamp.Timestamp

// Holds attributes of type DURATION
durations <_>: time.Duration
durations <_>: duration.Duration

// Holds attributes of type BYTES
bytes <_>: bytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
package client

import (
"github.com/golang/protobuf/ptypes/duration"
"istio.io/api/mixer/v1"
"time"
)

// Specifies the behavior when the client is unable to connect to Mixer.
Expand All @@ -35,10 +35,10 @@ NetworkFailPolicy: {

// Base time to wait between retries. Will be adjusted by exponential
// backoff and jitter.
baseRetryWait?: time.Duration @protobuf(3,type=google.protobuf.Duration,name=base_retry_wait)
baseRetryWait?: duration.Duration @protobuf(3,type=google.protobuf.Duration,name=base_retry_wait)

// Max time to wait between retries.
maxRetryWait?: time.Duration @protobuf(4,type=google.protobuf.Duration,name=max_retry_wait)
maxRetryWait?: duration.Duration @protobuf(4,type=google.protobuf.Duration,name=max_retry_wait)
}

// Example of single-value enum.
Expand Down Expand Up @@ -107,7 +107,7 @@ TransportConfig: {

// Specify refresh interval to write Mixer client statistics to Envoy share
// memory. If not specified, the interval is 10 seconds.
statsUpdateInterval?: time.Duration @protobuf(5,type=google.protobuf.Duration,name=stats_update_interval)
statsUpdateInterval?: duration.Duration @protobuf(5,type=google.protobuf.Duration,name=stats_update_interval)

// Name of the cluster that will forward check calls to a pool of mixer
// servers. Defaults to "mixer_server". By using different names for
Expand Down Expand Up @@ -182,5 +182,5 @@ TcpClientConfig: {
// Specify report interval to send periodical reports for long TCP
// connections. If not specified, the interval is 10 seconds. This interval
// should not be less than 1 second, otherwise it will be reset to 1 second.
reportInterval?: time.Duration @protobuf(6,type=google.protobuf.Duration,name=report_interval)
reportInterval?: duration.Duration @protobuf(6,type=google.protobuf.Duration,name=report_interval)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package v1

import (
"github.com/golang/protobuf/ptypes/duration"
"google.golang.org/genproto/googleapis/rpc/status"
"time"
)

// Used to get a thumbs-up/thumbs-down before performing an action.
Expand Down Expand Up @@ -70,7 +70,7 @@ CheckResponse_PreconditionResult: {
status?: __status.Status @protobuf(1,type=google.rpc.Status,"(gogoproto.nullable)=false")

// The amount of time for which this result can be considered valid.
validDuration?: time.Duration @protobuf(2,type=google.protobuf.Duration,name=valid_duration,"(gogoproto.nullable)=false","(gogoproto.stdduration)")
validDuration?: duration.Duration @protobuf(2,type=google.protobuf.Duration,name=valid_duration,"(gogoproto.nullable)=false","(gogoproto.stdduration)")

// The number of uses for which this result can be considered valid.
validUseCount?: int32 @protobuf(3,name=valid_use_count)
Expand All @@ -88,7 +88,7 @@ __status = status
// Expresses the result of a quota allocation.
CheckResponse_QuotaResult: {
// The amount of time for which this result can be considered valid.
validDuration?: time.Duration @protobuf(1,type=google.protobuf.Duration,name=valid_duration,"(gogoproto.nullable)=false","(gogoproto.stdduration)")
validDuration?: duration.Duration @protobuf(1,type=google.protobuf.Duration,name=valid_duration,"(gogoproto.nullable)=false","(gogoproto.stdduration)")

// The amount of granted quota. When `QuotaParams.best_effort` is true, this will be >= 0.
// If `QuotaParams.best_effort` is false, this will be either 0 or >= `QuotaParams.amount`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// limitations under the License.
package status

import "github.com/golang/protobuf/ptypes/any"

// The `Status` type defines a logical error model that is suitable for
// different programming environments, including REST APIs and RPC APIs. It is
// used by [gRPC](https://github.com/grpc). The error model is designed to be:
Expand Down Expand Up @@ -80,5 +82,5 @@ Status: {

// A list of messages that carry the error details. There is a common set of
// message types for APIs to use.
details?: [...] @protobuf(3,type=google.protobuf.Any)
details?: [...any.Any] @protobuf(3,type=google.protobuf.Any)
}
12 changes: 0 additions & 12 deletions encoding/protobuf/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ func (p *protoConverter) mapBuiltinPackage(pos scanner.Position, file string, re
switch file {
case "gogoproto/gogo.proto":

case "google/protobuf/duration.proto":
p.setBuiltin("google.protobuf.Duration", "time.Duration", timePkg)

case "google/protobuf/timestamp.proto":
p.setBuiltin("google.protobuf.Timestamp", "time.Time", timePkg)

case "google/protobuf/any.proto":
p.setBuiltin("google.protobuf.Any", "_", nil)

case "google/protobuf/empty.proto":
p.setBuiltin("google.protobuf.Empty", "{}", nil)

default:
if required {
failf(pos, "import %q not found", file)
Expand Down

0 comments on commit f9bd63e

Please sign in to comment.