2013-06-25 42 views
2

有沒有一種將protobuf編譯與go build命令集成的好方法?使用Go工具編譯Protobuf

+0

請參閱[G +](https://plus.google.com/115983116618286597159/posts/7sE4HhXq15Q)。 –

+0

您有沒有看過https://code.google.com/p/goprotobuf/? – Intermernet

+0

我有點希望能讓我繼續使用'go build'的解決方案,但這可能是不可能的。 –

回答

2

goprotobuf「爲Google的協議緩衝區提供Go支持,採用庫和協議編譯器插件的形式」。

goprotobuf圖書館的README有一些很好的信息。

https://code.google.com/p/goprotobuf/source/browse/README#106

考慮文件test.proto,含

package example; 

    enum FOO { X = 17; }; 

    message Test { 
     required string label = 1; 
     optional int32 type = 2 [default=77]; 
     repeated int64 reps = 3; 
     optional group OptionalGroup = 4 { 
     required string RequiredField = 5; 
     } 
    } 

要建立從test.proto和其他一些圍棋文件的包,寫一個Makefile這樣:

include $(GOROOT)/src/Make.$(GOARCH) 

    TARG=path/to/example 
    GOFILES=\ 
     test.pb.go\ 
     other.go 

    include $(GOROOT)/src/Make.pkg 
    include $(GOROOT)/src/pkg/code.google.com/p/goprotobuf/Make.protobuf