package protobuf
import "cuelang.org/go/encoding/protobuf"
Package protobuf defines functionality for parsing protocol buffer definitions and instances.
Index ¶
Examples ¶
Functions ¶
func Parse ¶
Parse parses a single proto file and returns its contents translated to a CUE file. If src is not nil, it will use this as the contents of the file. It may be a string, []byte or io.Reader. Otherwise Parse will open the given file name at the fully qualified path.
Parse assumes the proto file compiles with protoc and may not report an error if it does not. Imports are resolved using the paths defined in Config.
The following field options are supported:
(cue.val) string CUE constraint for this field. The string may refer to other fields in a message definition. (cue.opt) FieldOptions required bool Defines the field is required. Use with caution.
Example¶
Code:play
package main import ( "log" "os" "path/filepath" "cuelang.org/go/cue/format" "cuelang.org/go/encoding/protobuf" ) func main() { cwd, _ := os.Getwd() var paths = []string{} paths = append(paths, cwd) paths = append(paths, filepath.Join(cwd, "testdata")) f, err := protobuf.Parse("examples/basic/basic.proto", nil, &protobuf.Config{ Paths: paths, }) if err != nil { log.Fatal(err, "") } format.Node(os.Stdout, f) }
Output:
// Package basic is just that: basic. package basic // This is my type. MyType: { stringValue?: string @protobuf(1,name=string_value) // just any 'ole string // A method must start with a capital letter. method?: [...string] @protobuf(2) method?: [...=~"^[A-Z]"] }
Types ¶
type Config ¶
type Config struct { Paths []string }
Config specifies the environment into which to parse a proto definition file.
Source Files ¶
errors.go parse.go protobuf.go types.go util.go
- Version
- v0.0.3
- Published
- Jun 26, 2019
- Platform
- linux/amd64
- Imports
- 15 packages
- Last checked
- 2 minutes ago –
Tools for package owners.