protoparse

package
v0.0.0-...-34c5bf1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 7 Imported by: 0

README

protoparse

Protoparse is a library to turn a parsed proto file into something more useable. See tools/protoc-gen-jrpc for an example of how this is used.

Licence

The code is based on https://github.com/golang/protobuf

Go support for Protocol Buffers - Google's data interchange format

Copyright 2010 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.

And on https://github.com/twitchtv/twirp

Copyright 2018 Twitch Interactive, Inc.  All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"). You may not
use this file except in compliance with the License. A copy of the License is
located at

    http://www.apache.org/licenses/LICENSE-2.0

or in the "license" file accompanying this file. This file 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comments

type Comments struct {
	// Leading are the comment lines directly above the line of code
	Leading []string

	// Leading detached are comment lines above
	// the line of code but not directly touching
	LeadingDetached [][]string

	// Trailing are comment lines directly under the line of code
	Trailing []string
}

Comments holds the set of comments associated with an entity

type Field

type Field struct {
	// Name is the name from the proto file e.g. email_address
	Name string

	// Repeated is true if this field has the repeated label
	Repeated bool

	// GoName is the name the field will get in the go struct e.g. EmailAddress
	GoName string

	// TypeName is the name of the type e.g. TYPE_STRING
	TypeName string

	// Type is the message if TypeName == TYPE_MESSAGE
	Type *Message
	// contains filtered or unexported fields
}

Field represents a field within a message

func (*Field) GetExtension

func (f *Field) GetExtension(extension *proto.ExtensionDesc) (interface{}, error)

GetExtension can be used to get custom options set on a field

type File

type File struct {
	// Name is the relative path and filename of the proto file
	Name string

	// ProtoPackage is the name defined in the proto's package statement
	ProtoPackage string

	// GoImportPath is the go import path of the package as defined by the go_package option
	GoImportPath string

	// GoPackage is the name defined by the go_package option
	GoPackage string

	// PackageComments are comments on the package definition
	PackageComments *Comments

	// Imports is the list of go imports this file needs for its service types
	Imports []*Import

	// Services are the services defined in the proto file
	Services []*Service

	// Messages are the messages defined in the proto
	// file and any messages from public imports
	Messages []*Message
	// contains filtered or unexported fields
}

File represents a parsed proto file

func Parse

func Parse(req *plugin_go.CodeGeneratorRequest) ([]*File, error)

Parse turns a CodeGeneratorRequest into a parsed set of Files

func (*File) GetPackageComments

func (f *File) GetPackageComments() *Comments

GetPackageComments is a nil-safe getter for PackageComments

type Import

type Import struct {
	// Alias is the import alias if one is required
	Alias string

	// Path is the path to be imported
	Path string
}

Import describes a go import

type Message

type Message struct {
	// Name is the simple name of the message
	Name string

	// ProtoName is the dot-delimited, fully-
	// qualified protobuf name of the message.
	ProtoName string

	// GoTypeName is the name of the go type generated for this message
	GoTypeName string

	// Comments defines the comments attached to the message
	Comments *Comments

	// Fields are the fields defined in the message
	Fields []*Field

	// File is the file in which the message was defined (or the file
	// in which it was imported in the case of a public import).
	File *File

	// Parent is set if the message definition was nested inside another
	Parent *Message
	// contains filtered or unexported fields
}

Message represents a message type defined in a proto file

func (*Message) GetComments

func (m *Message) GetComments() *Comments

GetComments is a nil-safe getter for Comments

func (*Message) GetExtension

func (m *Message) GetExtension(extension *proto.ExtensionDesc) (interface{}, error)

GetExtension can be used to get custom options set on a message

func (*Message) GetParent

func (m *Message) GetParent() *Message

GetParent is a nil-safe getter for Parent

type Method

type Method struct {
	// Name is the simple name for this method
	Name string

	// InputType is the message defined as the input type
	InputType *Message

	// OutputType is the message defined as the output type
	OutputType *Message

	// Comments defines the comments attached to the method
	Comments *Comments
	// contains filtered or unexported fields
}

Method represents a method defined in a service

func (*Method) GetComments

func (m *Method) GetComments() *Comments

GetComments is a nil-safe getter for Comments

func (*Method) GetExtension

func (m *Method) GetExtension(extension *proto.ExtensionDesc) (interface{}, error)

GetExtension can be used to get custom options set on a method

type Service

type Service struct {
	// Name is the simple name of the service
	Name string

	// Methods are the methods (RPCs) defined in this service
	Methods []*Method

	// Comments defines the comments attached to the service
	Comments *Comments
	// contains filtered or unexported fields
}

Service represents a service definition in a proto file

func (*Service) GetComments

func (s *Service) GetComments() *Comments

GetComments is a nil-safe getter for Comments

func (*Service) GetExtension

func (s *Service) GetExtension(extension *proto.ExtensionDesc) (interface{}, error)

GetExtension can be used to get custom options set on a service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL