github.com/cosmos/cosmos-proto@v1.0.0-beta.3/features/fastreflection/fast_plugin.go (about)

     1  package fastreflection
     2  
     3  import (
     4  	"github.com/cosmos/cosmos-proto/generator"
     5  	"google.golang.org/protobuf/compiler/protogen"
     6  )
     7  
     8  func init() {
     9  	generator.RegisterFeature("fast", func(gen *generator.GeneratedFile, _ *protogen.Plugin) generator.FeatureGenerator {
    10  		return fastReflectionFeature{
    11  			GeneratedFile: gen,
    12  			Stable:        false,
    13  			once:          false,
    14  		}
    15  	})
    16  }
    17  
    18  type fastReflectionFeature struct {
    19  	*generator.GeneratedFile
    20  	Stable, once bool
    21  }
    22  
    23  type fastGenerator struct {
    24  	*generator.GeneratedFile
    25  	file    *protogen.File
    26  	message *protogen.Message
    27  
    28  	Stable   bool
    29  	typeName string
    30  	err      error
    31  }
    32  
    33  func newGenerator(f *protogen.File, g *generator.GeneratedFile, message *protogen.Message) *fastGenerator {
    34  	return &fastGenerator{
    35  		GeneratedFile: g,
    36  		file:          f,
    37  		message:       message,
    38  		Stable:        true,
    39  		typeName:      fastReflectionTypeName(message),
    40  		err:           nil,
    41  	}
    42  }
    43  
    44  func (g fastReflectionFeature) GenerateFile(file *protogen.File, _ *protogen.Plugin) bool {
    45  	for _, msg := range file.Messages {
    46  		GenProtoMessage(file, g.GeneratedFile, msg)
    47  	}
    48  	return true // only do this once
    49  }
    50  
    51  func (g fastReflectionFeature) GenerateHelpers() {
    52  	// no helpers needed here yet
    53  }