Comments (6)
Actually, sorry, I think this is protoc generating this warning. Disregard!
from protobuf-swift.
Reopening because after I resolved the imports it did indeed fail (at compile time) with:
GogoRoot.sharedInstance.registerAllExtensions(extensionRegistry)
Unresolved identifier.
I'm not sure this is expected or not?
from protobuf-swift.
When google protoc compiler sees an unknown value, it stopped and part of the file is not generated - why this error occurs.
Give an example .proto file where it is repeated? The import file should be re-generated.
from protobuf-swift.
Taking the proto example from here:
package test;
import "code.google.com/p/gogoprotobuf/gogoproto/gogo.proto";
message A {
optional string Description = 1 [(gogoproto.nullable) = false];
optional int64 Number = 2 [(gogoproto.nullable) = false];
optional bytes Id = 3 [(gogoproto.customtype) = "code.google.com/p/gogoprotobuf/test/custom.Uuid", (gogoproto.nullable) = false];
}
Results in the following generated Swift code (no errors). Note the line GogoRoot.sharedInstance.registerAllExtensions(extensionRegistry)
.
// Generated by the protocol buffer compiler. DO NOT EDIT!
import Foundation
import ProtocolBuffers
struct HelloRoot {
static var sharedInstance : HelloRoot {
struct Static {
static let instance : HelloRoot = HelloRoot()
}
return Static.instance
}
var extensionRegistry:ExtensionRegistry
init() {
extensionRegistry = ExtensionRegistry()
registerAllExtensions(extensionRegistry)
GogoRoot.sharedInstance.registerAllExtensions(extensionRegistry)
}
func registerAllExtensions(registry:ExtensionRegistry) {
}
}
func == (lhs: A, rhs: A) -> Bool {
if (lhs === rhs) {
return true
}
var fieldCheck:Bool = (lhs.hashValue == rhs.hashValue)
fieldCheck = fieldCheck && (lhs.hasDescription == rhs.hasDescription) && (!lhs.hasDescription || lhs.description == rhs.description)
fieldCheck = fieldCheck && (lhs.hasNumber == rhs.hasNumber) && (!lhs.hasNumber || lhs.number == rhs.number)
fieldCheck = fieldCheck && (lhs.hasId == rhs.hasId) && (!lhs.hasId || lhs.id == rhs.id)
return (fieldCheck && (lhs.unknownFields == rhs.unknownFields))
}
final class A : GeneratedMessage {
private(set) var hasDescription:Bool = false
private(set) var description:String = ""
private(set) var hasNumber:Bool = false
private(set) var number:Int64 = Int64(0)
private(set) var hasId:Bool = false
private(set) var id:Array<Byte> = [Byte]()
required internal init() {
super.init()
}
override internal func isInitialized() -> Bool {
return true
}
override internal func writeToCodedOutputStream(output:CodedOutputStream) {
if hasDescription {
output.writeString(1, value:description)
}
if hasNumber {
output.writeInt64(2, value:number)
}
if hasId {
output.writeData(3, value:id)
}
unknownFields.writeToCodedOutputStream(output)
}
override internal func serializedSize() -> Int32 {
var size:Int32 = memoizedSerializedSize
if size != -1 {
return size
}
size = 0
if hasDescription {
size += WireFormat.computeStringSize(1, value:description)
}
if hasNumber {
size += WireFormat.computeInt64Size(2, value:number)
}
if hasId {
size += WireFormat.computeDataSize(3, value:id)
}
size += unknownFields.serializedSize()
memoizedSerializedSize = size
return size
}
internal class func parseFromData(data:[Byte]) -> A {
return A.builder().mergeFromData(data).build()
}
internal class func parseFromData(data:[Byte], extensionRegistry:ExtensionRegistry) -> A {
return A.builder().mergeFromData(data, extensionRegistry:extensionRegistry).build()
}
internal class func parseFromInputStream(input:NSInputStream) -> A {
return A.builder().mergeFromInputStream(input).build()
}
internal class func parseFromInputStream(input:NSInputStream, extensionRegistry:ExtensionRegistry) ->A {
return A.builder().mergeFromInputStream(input, extensionRegistry:extensionRegistry).build()
}
internal class func parseFromCodedInputStream(input:CodedInputStream) -> A {
return A.builder().mergeFromCodedInputStream(input).build()
}
internal class func parseFromCodedInputStream(input:CodedInputStream, extensionRegistry:ExtensionRegistry) -> A {
return A.builder().mergeFromCodedInputStream(input, extensionRegistry:extensionRegistry).build()
}
internal class func builder() -> ABuilder {
return A.classBuilder() as ABuilder
}
internal func builder() -> ABuilder {
return classBuilder() as ABuilder
}
internal override class func classBuilder() -> MessageBuilder {
return ABuilder()
}
internal override func classBuilder() -> MessageBuilder {
return A.builder()
}
internal func toBuilder() -> ABuilder {
return A.builderWithPrototype(self)
}
internal class func builderWithPrototype(prototype:A) -> ABuilder {
return A.builder().mergeFrom(prototype)
}
override internal func writeDescriptionTo(inout output:String, indent:String) {
if hasDescription {
output += "\(indent) description: \(description) \n"
}
if hasNumber {
output += "\(indent) number: \(number) \n"
}
if hasId {
output += "\(indent) id: \(id) \n"
}
unknownFields.writeDescriptionTo(&output, indent:indent)
}
override internal var hashValue:Int {
get {
var hashCode:Int = 7
if hasDescription {
hashCode = (hashCode &* 31) &+ description.hashValue
}
if hasNumber {
hashCode = (hashCode &* 31) &+ number.hashValue
}
if hasId {
for value in id {
hashCode = (hashCode &* 31) &+ value.hashValue
}
}
hashCode = (hashCode &* 31) &+ unknownFields.hashValue
return hashCode
}
}
//Meta information declaration start
override internal class func className() -> String {
return "A"
}
override internal func className() -> String {
return "A"
}
override internal func classMetaType() -> GeneratedMessage.Type {
return A.self
}
//Meta information declaration end
}
final class ABuilder : GeneratedMessageBuilder {
private var builderResult:A
required override internal init () {
builderResult = A()
super.init()
}
var hasDescription:Bool {
get {
return builderResult.hasDescription
}
}
var description:String {
get {
return builderResult.description
}
set (value) {
builderResult.hasDescription = true
builderResult.description = value
}
}
func clearDescription() -> ABuilder{
builderResult.hasDescription = false
builderResult.description = ""
return self
}
var hasNumber:Bool {
get {
return builderResult.hasNumber
}
}
var number:Int64 {
get {
return builderResult.number
}
set (value) {
builderResult.hasNumber = true
builderResult.number = value
}
}
func clearNumber() -> ABuilder{
builderResult.hasNumber = false
builderResult.number = Int64(0)
return self
}
var hasId:Bool {
get {
return builderResult.hasId
}
}
var id:Array<Byte> {
get {
return builderResult.id
}
set (value) {
builderResult.hasId = true
builderResult.id = value
}
}
func clearId() -> ABuilder{
builderResult.hasId = false
builderResult.id = [Byte]()
return self
}
override internal var internalGetResult:GeneratedMessage {
get {
return builderResult
}
}
internal override func clear() -> ABuilder {
builderResult = A()
return self
}
internal override func clone() -> ABuilder {
return A.builderWithPrototype(builderResult)
}
internal override func build() -> A {
checkInitialized()
return buildPartial()
}
internal func buildPartial() -> A {
var returnMe:A = builderResult
return returnMe
}
func mergeFrom(other:A) -> ABuilder {
if (other == A()) {
return self
}
if other.hasDescription {
description = other.description
}
if other.hasNumber {
number = other.number
}
if other.hasId {
id = other.id
}
mergeUnknownFields(other.unknownFields)
return self
}
internal override func mergeFromCodedInputStream(input:CodedInputStream) ->ABuilder {
return mergeFromCodedInputStream(input, extensionRegistry:ExtensionRegistry())
}
internal override func mergeFromCodedInputStream(input:CodedInputStream, extensionRegistry:ExtensionRegistry) -> ABuilder {
var unknownFieldsBuilder:UnknownFieldSetBuilder = UnknownFieldSet.builderWithUnknownFields(self.unknownFields)
while (true) {
var tag = input.readTag()
switch tag {
case 0:
self.unknownFields = unknownFieldsBuilder.build()
return self
case 10 :
description = input.readString()
case 16 :
number = input.readInt64()
case 26 :
id = input.readData()
default:
if (!parseUnknownField(input,unknownFields:unknownFieldsBuilder, extensionRegistry:extensionRegistry, tag:tag)) {
unknownFields = unknownFieldsBuilder.build()
return self
}
}
}
}
}
//Class extensions: NSData
internal extension A {
class func parseFromNSData(data:NSData) -> A {
var bytes = [Byte](count: data.length, repeatedValue: 0)
data.getBytes(&bytes)
return A.builder().mergeFromData(bytes).build()
}
class func parseFromNSData(data:NSData, extensionRegistry:ExtensionRegistry) -> A {
var bytes = [Byte](count: data.length, repeatedValue: 0)
data.getBytes(&bytes)
return A.builder().mergeFromData(bytes, extensionRegistry:extensionRegistry).build()
}
}
// @@protoc_insertion_point(global_scope)
from protobuf-swift.
Now everything is clear. You need to compile the file «code.google.com/p/gogoprotobuf/gogoproto/gogo.proto» and add it to xcode project. This file describes extensions. All imported files must be compiled and added to the project.
In gogoproto folder I compiled file example.proto, gogo.proto, descriptor.proto. I put them in one folder.
All compiled.
Read about the "import" at documentation: https://developers.google.com/protocol-buffers/
example.proto
package test;
import "gogo.proto";
option (gogoproto.gostring_all) = true;
option (gogoproto.equal_all) = true;
option (gogoproto.verbose_equal_all) = true;
option (gogoproto.goproto_stringer_all) = false;
option (gogoproto.stringer_all) = true;
option (gogoproto.populate_all) = true;
option (gogoproto.testgen_all) = true;
option (gogoproto.benchgen_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.unmarshaler_all) = true;
message A {
option (gogoproto.face) = true;
option (gogoproto.goproto_getters) = false;
optional string Description = 1 [(gogoproto.nullable) = false];
optional int64 Number = 2 [(gogoproto.nullable) = false];
optional bytes Id = 3 [(gogoproto.customtype) = "code.google.com/p/gogoprotobuf/test.Uuid", (gogoproto.nullable) = false];
}
message B {
option (gogoproto.description) = true;
optional A A = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
repeated bytes G = 2 [(gogoproto.customtype) = "code.google.com/p/gogoprotobuf/test/custom.Uint128", (gogoproto.nullable) = false];
}
message C {
optional int64 size = 1 [(gogoproto.customname) = "MySize"];
}
message U {
option (gogoproto.onlyone) = true;
optional A A = 1;
optional B B = 2;
}
message E {
option (gogoproto.goproto_extensions_map) = false;
extensions 1 to max;
}
gogo.proto
package gogoproto;
import "descriptor.proto";
extend google.protobuf.EnumOptions {
optional bool goproto_enum_prefix = 62001;
optional bool goproto_enum_stringer = 62021;
optional bool enum_stringer = 62022;
}
extend google.protobuf.FileOptions {
optional bool goproto_getters_all = 63001;
optional bool goproto_enum_prefix_all = 63002;
optional bool goproto_stringer_all = 63003;
optional bool verbose_equal_all = 63004;
optional bool face_all = 63005;
optional bool gostring_all = 63006;
optional bool populate_all = 63007;
optional bool stringer_all = 63008;
optional bool onlyone_all = 63009;
optional bool equal_all = 63013;
optional bool description_all = 63014;
optional bool testgen_all = 63015;
optional bool benchgen_all = 63016;
optional bool marshaler_all = 63017;
optional bool unmarshaler_all = 63018;
optional bool bufferto_all = 63019;
optional bool sizer_all = 63020;
optional bool goproto_enum_stringer_all = 63021;
optional bool enum_stringer_all = 63022;
optional bool unsafe_marshaler_all = 63023;
optional bool unsafe_unmarshaler_all = 63024;
optional bool goproto_extensions_map_all = 63025;
}
extend google.protobuf.MessageOptions {
optional bool goproto_getters = 64001;
optional bool goproto_stringer = 64003;
optional bool verbose_equal = 64004;
optional bool face = 64005;
optional bool gostring = 64006;
optional bool populate = 64007;
optional bool stringer = 67008;
optional bool onlyone = 64009;
optional bool equal = 64013;
optional bool description = 64014;
optional bool testgen = 64015;
optional bool benchgen = 64016;
optional bool marshaler = 64017;
optional bool unmarshaler = 64018;
optional bool bufferto = 64019;
optional bool sizer = 64020;
optional bool unsafe_marshaler = 64023;
optional bool unsafe_unmarshaler = 64024;
optional bool goproto_extensions_map = 64025;
}
extend google.protobuf.FieldOptions {
optional bool nullable = 65001;
optional bool embed = 65002;
optional string customtype = 65003;
optional string customname = 65004;
optional string jsontag = 65005;
optional string moretags = 65006;
}
and descriptor.proto
from protobuf-swift.
Aaah, I didn't realise I had to individually compile imports. Thanks for the help!
from protobuf-swift.
Related Issues (20)
- Error in Xcode10 HOT 1
- Build fails with protobuf 3.6.0 HOT 2
- If a number is 0 this property will missing HOT 1
- XCode 10/swift 4.2 compilation errors HOT 3
- Build error on Xcode beta 5 HOT 2
- convert array ro json
- UnsafeRawPointer(&buffer+bufferPos) Ambiguous use of 'init' HOT 4
- configuare.ac
- new function to `delimitedData`
- Build time error HOT 1
- protobuf test program failed to link
- Message Field extensions
- protobuf2.6,swift 3.0 ,version Number
- Question : Codable
- [Question] Use RawValue enum when formatting to JSON
- protocol buffer build.sh error and show “protobuf test program failed to link” HOT 4
- Install failed
- Why the GeneratedMessageProtocol tip error
- Xcode 12.0 BETA 4 HOT 5
- Xcode12 build failure - Generic parameter 'Element' could not be inferred HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-swift.