Google ProtocolBuffers for Apple Swift

Overview

Protocol Buffers for Swift

Build Status Carthage compatible Version Platform

An implementation of Protocol Buffers in Swift.

Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. This project is based on an implementation of Protocol Buffers from Google. See the Google protobuf project for more information.

Required Protocol Buffers 3.0

How To Install Protobuf Compiler on Linux(Ubuntu 14.04)

1.wget https://github.com/google/protobuf/archive/v3.2.0.tar.gz

2.tar xzf v3.2.0.tar.gz

3.cd protobuf-3.2.0/

4.sudo apt-get install autoreconf automake libtool make

5../autogen.sh

6../configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib

7.sudo make && sudo make install

8.cd .. && wget https://github.com/alexeyxo/protobuf-swift/archive/3.0.9.tar.gz && tar xzf 3.0.9.tar.gz && cd protobuf-swift-3.0.9

9../script/build.sh && swift build

How To Install Protobuf Compiler from Homebrew

1.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.brew install protobuf-swift

How To Install Protobuf Compiler

1.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.brew install automake

3.brew install libtool

4.brew install protobuf

5.git clone [email protected]:alexeyxo/protobuf-swift.git

6../scripts/build.sh

Add ./src/ProtocolBuffers/ProtocolBuffers.xcodeproj in your project.

Cocoapods

Podfile:

use_frameworks!
pod 'ProtocolBuffers-Swift'

Installation via Carthage

Cartfile:

github "alexeyxo/protobuf-swift"

Compile ".proto" files.

protoc  person.proto --swift_out="./"

Serializing

syntax = "proto2";
message Person {
    required int32 id = 1;
    required string name = 2;
    optional string email = 3;
}
let personBuilder = Person.Builder()
personBuilder.id = 123
personBuilder.name = "Bob"
personBuilder.email = "[email protected]"
let person = try! personBuilder.build()
print(person)

person.data() //return NSData

Chaining

syntax = "proto2";
message Perfomance
{
  required int32 ints = 1;
  required int64 ints64 = 2;
  required double doubles = 3;
  required float floats  = 4;
  optional string str  = 5;
  optional bytes bytes  = 6;
  optional string description = 7;
}
var originalBuilder = ProtoPerfomance.Builder()
originalBuilder.setInts(Int32(32))
               .setInts64(Int64(64))
               .setDoubles(Double(12.12))
               .setFloats(Float(123.123))
               .setStr("string")
let original = originalBuilder.build()

Sub Builders

syntax = "proto2";
message Foo {
  optional int32 val = 1;
  // some other fields.
}

message Bar {
  optional Foo foo = 1;
  // some other fields.
}

message Baz {
  optional Bar bar = 1;
  // some other fields.
}
var builder = baz.toBuilder()
builder.getBarBuilder().getFooBuilder().setVal(10)
baz = builder.build()

Maps(ProtocolBuffers 3.0)

syntax = "proto3";
message MapMessageValue
{
    int32 valueInMapMessage = 1;
}

message MessageContainsMap
{

  enum EnumMapValue
  {
    FirstValueEnum = 0;
    SecondValueEnum = 1;
  }

  map<int32,int32> map_int32_int32= 1;
  map<int64,int64> map_int64_int64= 2;
  map<string,string> map_string_string = 3;
  map<string,bytes> map_string_bytes = 4;
  map<string,MapMessageValue> map_string_message = 5;
  map<int32,EnumMapValue> map_int32_enum = 6;

}
final internal class MessageContainsMap : GeneratedMessage, GeneratedMessageProtocol, Hashable {
    ...
    private(set) var mapInt32Int32:Dictionary<Int32,Int32> = Dictionary<Int32,Int32>()
    private(set) var mapInt64Int64:Dictionary<Int64,Int64> = Dictionary<Int64,Int64>()

    private(set) var mapStringString:Dictionary<String,String> = Dictionary<String,String>()
    private(set) var mapStringBytes:Dictionary<String,NSData> = Dictionary<String,NSData>()
    private(set) var mapInt32Enum:Dictionary<Int32,MessageContainsMap.EnumMapValue> = Dictionary<Int32,MessageContainsMap.EnumMapValue>()
    ...
}

JSON(proto3)

let personBuilder = Person.builder()
personBuilder.id = 123
personBuilder.name = "Bob"
personBuilder.email = "[email protected]"
let person = personBuilder.build()
let jsonData = person.toJSON() //return NSData
let jsonDictionaryObject:Dictionary<String,AnyObject> = person.encode()
let personFromJson = Person.fromJSON(jsonData) //Person

Deserializing

var person = Person.parseFromData(bytes) // from NSData

Using Oneof

syntax = "proto3";
message SubMessage {
    string str = 1;
}

message SampleMessage {
  oneof test_oneof {
     string name = 4;
     int32 id = 5;
     SubMessage mes = 6;
  }
}
var sm = SampleMessage.Builder()
sm.name = "Alex"
sm.id = 123
println(ss.build()) //->  id: 123

Nested Types

syntax = "proto3";
message SearchResponse {
    message Result {
        string url = 1;
        string title = 2;
        repeated string snippets = 3;
    }
    repeated Result result = 1;
}
var builderResult = SearchResponse.Result.Builder()
builderResult.url = "http://protobuf.axo.io"
builderResult.title = "Protocol Bufers Apple Swift"
var searchRespons = SearchResponse.builder()
searchRespons.result += [builderResult.build()]
println(searchRespons.build())

Packages

syntax = "proto2";
package FooBar;
message Perfomance
{
  required int32 ints = 1;
  required int64 ints64 = 2;
  required double doubles = 3;
  required float floats  = 4;
  optional string str  = 5;
  optional bytes bytes  = 6;
  optional string description = 7;
}
public extension FooBar {
  ...
  final public class Perfomance : GeneratedMessage, GeneratedMessageProtocol {
    ...
  }

}

Custom Options

import "google/protobuf/descriptor.proto";

package google.protobuf;

enum AccessControl {
  InternalEntities = 0;
  PublicEntities = 1;
}
message SwiftFileOptions {

  optional string class_prefix = 1;
  optional AccessControl entities_access_control = 2 [default = PublicEntities];
  optional bool compile_for_framework = 3 [default = true];
}

message SwiftMessageOptions {
  optional bool generate_error_type = 1 [default = false];
}

message SwiftEnumOptions {
  optional bool generate_error_type = 1 [default = false];
}

extend google.protobuf.FileOptions {
  optional SwiftFileOptions swift_file_options = 5092014;
}

extend google.protobuf.MessageOptions {
  optional SwiftMessageOptions swift_message_options = 5092014;
}

extend google.protobuf.EnumOptions {
  optional SwiftEnumOptions swift_enum_options = 5092015;
}

option (.google.protobuf.swift_file_options).compile_for_framework = false;
option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities;

At now protobuf-swift's compiler is supporting custom options.

  1. Class Prefix
  2. Access Control
  3. Error Types
  4. Compile for framework

If you have use custom options, you need to add:

import 'google/protobuf/swift-descriptor.proto';

in your .proto files.

Class prefix

This option needs to generate class names with prefix.

Example:

import 'google/protobuf/swift-descriptor.proto';

option (.google.protobuf.swift_file_options).class_prefix = "Proto";

message NameWithPrefix
{
  optional string str = 1;
}

Generated class has a name:

final internal class ProtoNameWithPrefix : GeneratedMessage

Access control

option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities;

All generated classes marks as internal by default. If you want mark as public, you can use entities_access_control option.

option (.google.protobuf.swift_file_options).entities_access_control = PublicEntities;

message MessageWithCustomOption
{
  optional string str = 1;
}

Generated class and all fields are marked a public:

final public class MessageWithCustomOption : GeneratedMessage

Generate enum/message conforming to "Error" protocol

option (.google.protobuf.swift_enum_options).generate_error_type = true;

Example

import 'google/protobuf/swift-descriptor.proto';

enum ServiceError {
  option (.google.protobuf.swift_enum_options).generate_error_type = true;
  BadRequest = 0;
  InternalServerError = 1;
}

message UserProfile {
    message Request {
        required string userId = 1;
    }
    message Response {
        optional UserProfile profile = 1;
        optional ServiceError error = 2;
        optional Exception exception = 3;
    }

     message Exception {
        option (.google.protobuf.swift_message_options).generate_error_type = true;
        required int32 errorCode = 1;
        required string errorDescription = 2;
    }
    
    optional string firstName = 1;
    optional string lastName = 2;
    optional string avatarUrl = 3;
}
public enum ServiceError:Error, RawRepresentable, CustomDebugStringConvertible, CustomStringConvertible {
  public typealias RawValue = Int32

  case badRequest
  case internalServerError

  public init?(rawValue: RawValue) {
    switch rawValue {
    case 0: self = .badRequest
    case 1: self = .internalServerError
    default: return nil
    }
  }

  public var rawValue: RawValue {
    switch self {
    case .badRequest: return 0
    case .internalServerError: return 1
    }
  }

  public func throwException() throws {
    throw self
  }

  public var debugDescription:String { return getDescription() }
  public var description:String { return getDescription() }
  private func getDescription() -> String { 
    switch self {
    case .badRequest: return ".badRequest"
    case .internalServerError: return ".internalServerError"
    }
  }
}
func generateException()throws {
    let user = UserProfile.Response.Builder()
    user.error = .internalServerError
    let data = try user.build().data()
    let userError = try UserProfile.Response.parseFrom(data:data)
    if userError.hasError {
        throw userError.error //userError.error.throwException()
    }
}

do {
    try generateException()
} catch let err as ServiceError where err == .internalServerError {
    XCTAssertTrue(true)
} catch {
    XCTAssertTrue(false)
}

func throwExceptionMessage() throws {
  let exception = UserProfile.Exception.Builder()
  exception.errorCode = 403
  exception.errorDescription = "Bad Request"
  let exc = try exception.build()
  let data = try UserProfile.Response.Builder().setException(exc).build().data()
  let userError = try UserProfile.Response.parseFrom(data:data)
  if userError.hasException {
      throw userError.exception
  }
}

do {
    try throwExceptionMessage()
} catch let err as UserProfile.Exception {
    print(err)
    XCTAssertTrue(true)
} catch {
    XCTAssertTrue(false)
}
  

Compile for framework

option (.google.protobuf.swift_file_options).compile_for_framework = false;

This option deletes the string import ProtocolBuffers of the generated files.

If you will need some other options, write me. I will add them.

Utilities (ProtocolBuffers 3.0)

Added well-known type protos (any.proto, empty.proto, timestamp.proto, duration.proto, etc.). Users can import and use these protos just like regular proto files. Addtional runtime support will be added for them in future releases (in the form of utility helper functions, or having them replaced by language specific types in generated code).

Any

message Any {
  // A URL/resource name whose content describes the type of the
  // serialized message.
  //
  // For URLs which use the schema `http`, `https`, or no schema, the
  // following restrictions and interpretations apply:
  //
  // * If no schema is provided, `https` is assumed.
  // * The last segment of the URL's path must represent the fully
  //   qualified name of the type (as in `path/google.protobuf.Duration`).
  // * An HTTP GET on the URL must yield a [google.protobuf.Type][google.protobuf.Type]
  //   value in binary format, or produce an error.
  // * Applications are allowed to cache lookup results based on the
  //   URL, or have them precompiled into a binary to avoid any
  //   lookup. Therefore, binary compatibility needs to be preserved
  //   on changes to types. (Use versioned type names to manage
  //   breaking changes.)
  //
  // Schemas other than `http`, `https` (or the empty schema) might be
  // used with implementation specific semantics.
  //
  // Types originating from the `google.*` package
  // namespace should use `type.googleapis.com/full.type.name` (without
  // schema and path). A type service will eventually become available which
  // serves those URLs (projected Q2/15).
  string type_url = 1;

  // Must be valid serialized data of the above specified type.
  bytes value = 2;
}
Google.Protobuf.Any()

API

message Api {
  // The fully qualified name of this api, including package name
  // followed by the api's simple name.
  string name = 1;

  // The methods of this api, in unspecified order.
  repeated Method methods = 2;

  // Any metadata attached to the API.
  repeated Option options = 3;

  // A version string for this api. If specified, must have the form
  // `major-version.minor-version`, as in `1.10`. If the minor version
  // is omitted, it defaults to zero. If the entire version field is
  // empty, the major version is derived from the package name, as
  // outlined below. If the field is not empty, the version in the
  // package name will be verified to be consistent with what is
  // provided here.
  //
  // The versioning schema uses [semantic
  // versioning](http://semver.org) where the major version number
  // indicates a breaking change and the minor version an additive,
  // non-breaking change. Both version numbers are signals to users
  // what to expect from different versions, and should be carefully
  // chosen based on the product plan.
  //
  // The major version is also reflected in the package name of the
  // API, which must end in `v<major-version>`, as in
  // `google.feature.v1`. For major versions 0 and 1, the suffix can
  // be omitted. Zero major versions must only be used for
  // experimental, none-GA apis.
  //
  // See also: [design doc](http://go/api-versioning).
  //
  //
  string version = 4;

  // Source context for the protocol buffer service represented by this
  // message.
  SourceContext source_context = 5;
}

// Method represents a method of an api.
message Method {
  // The simple name of this method.
  string name = 1;

  // A URL of the input message type.
  string request_type_url = 2;

  // If true, the request is streamed.
  bool request_streaming = 3;

  // The URL of the output message type.
  string response_type_url = 4;

  // If true, the response is streamed.
  bool response_streaming = 5;

  // Any metadata attached to the method.
  repeated Option options = 6;
}
Google.Protobuf.Api()

Duration

message Duration {
  // Signed seconds of the span of time. Must be from -315,576,000,000
  // to +315,576,000,000 inclusive.
  int64 seconds = 1;

  // Signed fractions of a second at nanosecond resolution of the span
  // of time. Durations less than one second are represented with a 0
  // `seconds` field and a positive or negative `nanos` field. For durations
  // of one second or more, a non-zero value for the `nanos` field must be
  // of the same sign as the `seconds` field. Must be from -999,999,999
  // to +999,999,999 inclusive.
  int32 nanos = 2;
}
Google.Protobuf.Duration()

Empty

message Empty {
}
Google.Protobuf.Empty()

Field Mask

message FieldMask {
  // The set of field mask paths.
  repeated string paths = 1;
}
Google.Protobuf.FieldMask()

Source context

message SourceContext {
  // The path-qualified name of the .proto file that contained the associated
  // protobuf element.  For example: `"google/protobuf/source.proto"`.
  string file_name = 1;
}
Google.Protobuf.SourceContext()

Struct

message Struct {
  // Map of dynamically typed values.
  map<string, Value> fields = 1;
}

// `Value` represents a dynamically typed value which can be either
// null, a number, a string, a boolean, a recursive struct value, or a
// list of values. A producer of value is expected to set one of that
// variants, absence of any variant indicates an error.
message Value {
  oneof kind {
    // Represents a null value.
    NullValue null_value = 1;

    // Represents a double value.
    double number_value = 2;

    // Represents a string value.
    string string_value = 3;

    // Represents a boolean value.
    bool bool_value = 4;

    // Represents a structured value.
    Struct struct_value = 5;

    // Represents a repeated `Value`.
    ListValue list_value = 6;
  }
}

// `ListValue` is a wrapper around a repeated field of values.
message ListValue {
  // Repeated field of dynamically typed values.
  repeated Value values = 1;
}

// `NullValue` is a singleton enumeration to represent the null
// value for the `Value` type union.
enum NullValue {
  // Null value.
  NULL_VALUE = 0;
}
Google.Protobuf.Struct()

Timestamp

message Timestamp {
  // Represents seconds of UTC time since Unix epoch
  // 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to
  // 9999-12-31T23:59:59Z inclusive.
  int64 seconds = 1;

  // Non-negative fractions of a second at nanosecond resolution. Negative
  // second values with fractions must still have non-negative nanos values
  // that count forward in time. Must be from 0 to 999,999,999
  // inclusive.
  int32 nanos = 2;
}
Google.Protobuf.Timestamp()

Type

message Type {
  // The fully qualified message name.
  string name = 1;

  // The list of fields.
  repeated Field fields = 2;

  // The list of oneof definitions.
  // The list of oneofs declared in this Type
  repeated string oneofs = 3;

  // The proto options.
  repeated Option options = 4;

  // The source context.
  SourceContext source_context = 5;
}

// Field represents a single field of a message type.
message Field {
  // Kind represents a basic field type.
  enum Kind {
    // Field type unknown.
    TYPE_UNKNOWN = 0;

    // Field type double.
    TYPE_DOUBLE = 1;

    // Field type float.
    TYPE_FLOAT = 2;

    // Field type int64.
    TYPE_INT64 = 3;

    // Field type uint64.
    TYPE_UINT64 = 4;

    // Field type int32.
    TYPE_INT32 = 5;

    // Field type fixed64.
    TYPE_FIXED64 = 6;

    // Field type fixed32.
    TYPE_FIXED32 = 7;

    // Field type bool.
    TYPE_BOOL = 8;

    // Field type string.
    TYPE_STRING = 9;

    // Field type message.
    TYPE_MESSAGE = 11;

    // Field type bytes.
    TYPE_BYTES = 12;

    // Field type uint32.
    TYPE_UINT32 = 13;

    // Field type enum.
    TYPE_ENUM = 14;

    // Field type sfixed32.
    TYPE_SFIXED32 = 15;

    // Field type sfixed64.
    TYPE_SFIXED64 = 16;

    // Field type sint32.
    TYPE_SINT32 = 17;

    // Field type sint64.
    TYPE_SINT64 = 18;
  }

  // Cardinality represents whether a field is optional, required, or
  // repeated.
  enum Cardinality {
    // The field cardinality is unknown. Typically an error condition.
    CARDINALITY_UNKNOWN = 0;

    // For optional fields.
    CARDINALITY_OPTIONAL = 1;

    // For required fields. Not used for proto3.
    CARDINALITY_REQUIRED = 2;

    // For repeated fields.
    CARDINALITY_REPEATED = 3;
  }

  // The field kind.
  Kind kind = 1;

  // The field cardinality, i.e. optional/required/repeated.
  Cardinality cardinality = 2;

  // The proto field number.
  int32 number = 3;

  // The field name.
  string name = 4;

  // The type URL (without the scheme) when the type is MESSAGE or ENUM,
  // such as `type.googleapis.com/google.protobuf.Empty`.
  string type_url = 6;

  // Index in Type.oneofs. Starts at 1. Zero means no oneof mapping.
  int32 oneof_index = 7;

  // Whether to use alternative packed wire representation.
  bool packed = 8;

  // The proto options.
  repeated Option options = 9;
}

// Enum type definition.
message Enum {
  // Enum type name.
  string name = 1;

  // Enum value definitions.
  repeated EnumValue enumvalue = 2;

  // Proto options for the enum type.
  repeated Option options = 3;

  // The source context.
  SourceContext source_context = 4;
}

// Enum value definition.
message EnumValue {
  // Enum value name.
  string name = 1;

  // Enum value number.
  int32 number = 2;

  // Proto options for the enum value.
  repeated Option options = 3;
}

// Proto option attached to messages/fields/enums etc.
message Option {
  // Proto option name.
  string name = 1;

  // Proto option value.
  Any value = 2;
}
Google.Protobuf.Type()
...

Wrappers

// Wrapper message for double.
message DoubleValue {
  // The double value.
  double value = 1;
}

// Wrapper message for float.
message FloatValue {
  // The float value.
  float value = 1;
}

// Wrapper message for int64.
message Int64Value {
  // The int64 value.
  int64 value = 1;
}

// Wrapper message for uint64.
message UInt64Value {
  // The uint64 value.
  uint64 value = 1;
}

// Wrapper message for int32.
message Int32Value {
  // The int32 value.
  int32 value = 1;
}

// Wrapper message for uint32.
message UInt32Value {
  // The uint32 value.
  uint32 value = 1;
}

// Wrapper message for bool.
message BoolValue {
  // The bool value.
  bool value = 1;
}

// Wrapper message for string.
message StringValue {
  // The string value.
  string value = 1;
}

// Wrapper message for bytes.
message BytesValue {
  // The bytes value.
  bytes value = 1;
}
Google.Protobuf.StringValue()

Credits

Developer - Alexey Khokhlov

Google Protocol Buffers - Cyrus Najmabadi, Sergey Martynov, Kenton Varda, Sanjay Ghemawat, Jeff Dean, and others

Comments
  • Problem with Swift 2

    Problem with Swift 2

    Hi! Install with pod instruction pod 'ProtocolBuffers-Swift', :git => 'https://github.com/alexeyxo/protobuf-swift.git', :branch => 'ProtoBuf3.0-Swift2.0'

    Generate proto.swift file from .proto file

    When build project got a many errors like this: Call can throw, but it is not marked with 'try' and the error is not handled Redundant conformance of 'Method' to protocol 'Hashable'

    All this errors from my proto.swift file

    What I'm doing wrong?

    question 
    opened by kiokumicu 18
  • Build.sh error

    Build.sh error

    It says this : checking google/protobuf/stubs/common.h usability... no checking google/protobuf/stubs/common.h presence... no checking for google/protobuf/stubs/common.h... no configure: error: ERROR: protobuf headers are required.

    You must either install protobuf from google, or if you have it installed in a custom location you must add '-Iincludedir' to CXXFLAGS and '-Llibdir' to LDFLAGS.

    If you did not specify a prefix when installing protobuf, try './configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib' In some 64-bit environments, try LDFLAGS=-L/usr/local/lib64.

    i downloaded the zip , extracted it to desktop.

    Can you please help me?

    opened by GianiVersace 16
  • no member named 'GetEmptyStringAlreadyInited'

    no member named 'GetEmptyStringAlreadyInited'

    Following the directions in the README, I get to step 6, ./build.sh and it does not successfully complete. A partial stack trace I am getting is included below. If you would like the entire trace let me know, it's rather lengthy and seems like it just repeats the same message anyways.

    Result of protoc --version is libprotoc 2.5.0. Installed all of those tools listed in the README through homebrew. Any other info you need let me know.

    make[2]: *** [swift_primitive_field.o] Error 1
    ./google/protobuf/descriptor.pb.h:2840:50: error: no member named 'GetEmptyStringAlreadyInited' in namespace 'google::protobuf::internal'
      if (package_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    ./google/protobuf/descriptor.pb.h:2848:50: error: no member named 'GetEmptyStringAlreadyInited' in namespace 'google::protobuf::internal'
      if (package_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    ./google/protobuf/descriptor.pb.h:2856:50: error: no member named 'GetEmptyStringAlreadyInited' in namespace 'google::protobuf::internal'
      if (package_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    ./google/protobuf/descriptor.pb.h:2864:50: error: no member named 'GetEmptyStringAlreadyInited' in namespace 'google::protobuf::internal'
      if (package_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    ./google/protobuf/descriptor.pb.h:2872:50: error: no member named 'GetEmptyStringAlreadyInited' in namespace 'google::protobuf::internal'
      if (package_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    ./google/protobuf/descriptor.pb.h:2876:75: error: no member named 'GetEmptyStringAlreadyInited' in namespace 'google::protobuf::internal'
        package_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    20 errors generated.
    make[2]: *** [swift_file.o] Error 1
    20 errors generated.
    make[2]: *** [swift_extension.o] Error 1
    make[1]: *** [all-recursive] Error 1
    make: *** [all] Error 2
    
    help wanted 
    opened by jault3 15
  • Swift on Linux

    Swift on Linux

    I have this strange behavior. Why after I use parseFromData I always get "Foundation.NSString" instead of the real string?

    let p = try CommonClasses.Test.Builder()
    p.client = "test"
    p.id = 1
    print(p.client) // outputs: test
    print(p.id) // outputs: 1
    
    let s = try CommonClasses.Test.parseFromData(p.build().data())
    print(s.client) // outputs: Foundation.NSString
    print(s.id) // outputs: 1
    

    My proto file:

    package CommonClasses;
    
    message Test {
    required string client = 1;
    required int32 id = 1;
    }
    
    
    enhancement swift2.2 swift3.0 
    opened by openm1nd 12
  • Nested protobufs aren't working properly

    Nested protobufs aren't working properly

    I have the following directory structure:

    protobufs
    └── services
        ├── organization
        │   ├── actions
        │   │   ├── create_organization.proto
        │   │   └── get_organization.proto
        │   └── containers
        │       ├── organization.proto
        │       └── team.proto
        └── profile
            ├── actions
            │   └── get_extended_profile.proto
            └── containers
                └── profile.proto
    
    7 directories, 6 files
    

    The protobufs compile to swift, but the files fail to build. It looks like some of the internal extension lines are misconfigured:

    internal extension Main.Services.Organization{internal struct Containers {.Organization {}}} and internal extension Main.Services{internal struct Profile {.Actions{internal struct GetExtendedProfile {}}}}

    I can send you a zip of the directory to test with.

    bug high priority 
    opened by mwildehahn 12
  • Getting error

    Getting error "Method does not override any method from its superclass" from generated output when using maps

    Hey,

    Thanks for creating this project!

    I have a simple message definition with map types like so:

    syntax = "proto3";
    
    message ParticipantWrapper {
      map<string, Participant> participant = 1;
    }
    
    message Participant {
      uint32 id = 1;
      string name = 2;
    }
    

    When I compile it (using the Protobuf3.0-Swift2.0 branch), the generated output shows many errors with "Method does not override any method from its superclass". I don't think I've used any reserved keywords so it does not appear to be related to #34. Idea idea what the problem could be?

    question 
    opened by DeepAnchor 10
  • More descriptive error messages

    More descriptive error messages

    When something fails to parse, I get the following error:

    Error: Error Domain=ProtocolBuffers.ProtocolBuffersError Code=1 "(null)"
    

    This really doesn't help very much. Is there some way to get more descriptive error output?

    question 
    opened by paralin 10
  • Terminating app due to uncaught exception 'OutOfSpace', reason: ''

    Terminating app due to uncaught exception 'OutOfSpace', reason: ''

    I do the unit test of my codes, but it terminates with no reason. It seems to occur in the message.data() which will serializing this message. I do message.data() in another thread(not main thread), but I'm sure the message is correct cause I print all message before message.data(). The stack trace is as follow:

    2015-05-29 17:26:22.670 xctest[37514:895701] *** Terminating app due to uncaught exception 'OutOfSpace', reason: ''
    *** First throw call stack:
    (
        0   CoreFoundation                      0x0000000104475c65 __exceptionPreprocess + 165
        1   libobjc.A.dylib                     0x000000010410ebb7 objc_exception_throw + 45
        2   CoreFoundation                      0x00000001044758a9 -[NSException raise] + 9
        3   ProtocolBuffers                     0x0000000107cd968d _TFC15ProtocolBuffers17CodedOutputStream5flushfS0_FT_T_ + 429
        4   ProtocolBuffers                     0x0000000107cd97e8 _TFC15ProtocolBuffers17CodedOutputStream12writeRawBytefS0_FT4byteVSs5UInt8_T_ + 120
        5   ProtocolBuffers                     0x0000000107cdb859 _TFC15ProtocolBuffers17CodedOutputStream16writeRawVarint32fS0_FVSs5Int32T_ + 105
        6   ProtocolBuffers                     0x0000000107cda81d _TFC15ProtocolBuffers17CodedOutputStream17writeMessageNoTagfS0_FPS_7Message_T_ + 109
        7   ProtocolBuffers                     0x0000000107cda911 _TFC15ProtocolBuffers17CodedOutputStream12writeMessagefS0_FTVSs5Int325valuePS_7Message__T_ + 145
        8   bdiloggerTests                      0x0000000107a2907f _TFC14bdiloggerTests10BDIPayload24writeToCodedOutputStreamfS0_FC15ProtocolBuffers17CodedOutputStreamT_ + 1375
        9   ProtocolBuffers                     0x0000000107cc904c _TFC15ProtocolBuffers15AbstractMessage4datafS0_FT_CSo6NSData + 268
        10  bdiloggerTests                      0x0000000107a3eed1 _TFC14bdiloggerTests15PersistentStore18writeHitToDatabasefS0_FTCS_17BDIPayloadBuilder7logTimeVSs5Int64_T_ + 289
        11  bdiloggerTests                      0x0000000107a3e8cb _TFC14bdiloggerTests15PersistentStore6putHitfS0_FTCS_17BDIPayloadBuilder7logTimeVSs5Int64_T_ + 155
        12  bdiloggerTests                      0x0000000107a86142 _TFFC14bdiloggerTests17ULoggerThreadImpl4sendFS0_FGSqCS_17BDIPayloadBuilder_T_U_FT_T_ + 850
        13  bdiloggerTests                      0x0000000107a861a6 _TFFC14bdiloggerTests17ULoggerThreadImpl13queueToThreadFS0_FFT_T_T_U_FT_T_ + 38
        14  bdiloggerTests                      0x00000001079a1b67 _TTRXFo__dT__XFdCb__dT__ + 39
        15  libdispatch.dylib                   0x00000001056f6f16 _dispatch_call_block_and_release + 12
        16  libdispatch.dylib                   0x0000000105711964 _dispatch_client_callout + 8
        17  libdispatch.dylib                   0x00000001056fbcb4 _dispatch_queue_drain + 435
        18  libdispatch.dylib                   0x00000001056fb9a3 _dispatch_queue_invoke + 217
        19  libdispatch.dylib                   0x00000001056fdc85 _dispatch_root_queue_drain + 534
        20  libdispatch.dylib                   0x00000001056fed59 _dispatch_worker_thread3 + 98
        21  libsystem_pthread.dylib             0x0000000105a7a637 _pthread_wqthread + 729
        22  libsystem_pthread.dylib             0x0000000105a7840d start_wqthread + 13
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb) 
    

    Is this a bug or something I didn't notice? ps. I build an framework instead of an app.

    invalid 
    opened by jamesweb1 9
  • parser repeated has something wrong in proto3

    parser repeated has something wrong in proto3

    protoc
    $ brew update
    $ brew install protobuf --devel --verbose
    ...
    $ protoc --version
    libprotoc 3.0.0
    
    protobuf-swift
    $ git clone https://github.com/alexeyxo/protobuf-swift
    $ git checkout -b ProtoBuf3.0-Swift2.0 origin/ProtoBuf3.0-Swift2.0
    $ ./scripts/build.sh
    
    Cocoapods
    pod 'ProtocolBuffers-Swift', :git => 'https://github.com/alexeyxo/protobuf-swift', :branch => 'ProtoBuf3.0-Swift2.0'
    

    protobuf define
    syntax = "proto3";
    
    package Test;
    option java_multiple_files  = false;
    option java_outer_classname = "TestProto";
    option java_package         = "com.test.protobuf";
    option csharp_namespace     = "Test.Protobuf";
    option objc_class_prefix    = "PBM";
    
    message Home {
        repeated bool door = 1;
    }
    
    swift parser
    do {
        let homeBuilder = Test.Home.getBuilder()
        homeBuilder.setDoor([true, false, true, false])
        let home = try homeBuilder.build()
        let homeData = home.data()
        let home2 = try Test.Home.parseFromData(homeData)
    
        print("home:\(home)")
        print("home2: \(home2)")
    
    } catch {
        print("catch \(error)")
    }
    
    output
    home: door[0]: true
     door[1]: false
     door[2]: true
     door[3]: false
    
    home2: 1: 1
    1: 0
    1: 1
    1: 0
    

    Debugger

    bug protobuf3.0 
    opened by langyanduan 8
  • Errors while trying to build protobuf-swift 2.2

    Errors while trying to build protobuf-swift 2.2

    I'm trying to install the Protobuf compiler but I am getting build errors.

    First I tried to install via Homebrew:

    shane@rmbp > protoc --version
    libprotoc 3.0.0
    shane@rmbp > brew install protobuf-swift
    ==> Downloading https://github.com/alexeyxo/protobuf-swift/archive/2.2.tar.gz
    Already downloaded: /Library/Caches/Homebrew/protobuf-swift-2.2.tar.gz
    ==> ./autogen.sh
    ==> ./configure --prefix=/usr/local/Cellar/protobuf-swift/2.2
    ==> make
     ^
    3 errors generated.
    make[2]: *** [swift_message_field.o] Error 1
    make[1]: *** [all-recursive] Error 1
    make: *** [all] Error 2
    

    Next I checked out tag 2.2 from the repository and tried to build it:

    shane@rmbp > git checkout tags/2.2
    HEAD is now at 4cfef1b... WatchOS deployment target
    shane@rmbp > git status
    HEAD detached at 2.2
    nothing to commit, working directory clean
    shane@rmbp > ./scripts/build.sh &> ~/Desktop/build.log
    

    Here are the contents of build.log:

    + ./autogen.sh
    + mkdir -p m4
    + autoreconf -f -i -Wall
    glibtoolize: putting auxiliary files in '.'.
    glibtoolize: copying file './ltmain.sh'
    glibtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
    glibtoolize: copying file 'm4/libtool.m4'
    glibtoolize: copying file 'm4/ltoptions.m4'
    glibtoolize: copying file 'm4/ltsugar.m4'
    glibtoolize: copying file 'm4/ltversion.m4'
    glibtoolize: copying file 'm4/lt~obsolete.m4'
    configure.ac:13: installing './compile'
    configure.ac:10: installing './missing'
    src/compiler/Makefile.am: installing './depcomp'
    + rm -rf autom4te.cache configure.ac~ config.h.in~
    + ./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib
    checking build system type... x86_64-apple-darwin15.0.0
    checking host system type... x86_64-apple-darwin15.0.0
    checking target system type... x86_64-apple-darwin15.0.0
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for a thread-safe mkdir -p... ./install-sh -c -d
    checking for gawk... no
    checking for mawk... no
    checking for nawk... no
    checking for awk... awk
    checking whether make sets $(MAKE)... yes
    checking whether make supports nested variables... yes
    checking for gcc... gcc
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
    checking for suffix of executables... 
    checking whether we are cross compiling... no
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether gcc accepts -g... yes
    checking for gcc option to accept ISO C89... none needed
    checking whether gcc understands -c and -o together... yes
    checking for style of include used by make... GNU
    checking dependency style of gcc... gcc3
    checking for g++... g++
    checking whether we are using the GNU C++ compiler... yes
    checking whether g++ accepts -g... yes
    checking dependency style of g++... gcc3
    checking C++ compiler flags...... use user-supplied: -I/usr/local/include
    configure: WARNING: Libtool does not cope well with whitespace in `pwd`
    checking how to print strings... printf
    checking for a sed that does not truncate output... /usr/bin/sed
    checking for grep that handles long lines and -e... /usr/bin/grep
    checking for egrep... /usr/bin/grep -E
    checking for fgrep... /usr/bin/grep -F
    checking for ld used by gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
    checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
    checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm
    checking the name lister (/usr/bin/nm) interface... BSD nm
    checking whether ln -s works... yes
    checking the maximum length of command line arguments... 196608
    checking how to convert x86_64-apple-darwin15.0.0 file names to x86_64-apple-darwin15.0.0 format... func_convert_file_noop
    checking how to convert x86_64-apple-darwin15.0.0 file names to toolchain format... func_convert_file_noop
    checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
    checking for objdump... no
    checking how to recognize dependent libraries... pass_all
    checking for dlltool... no
    checking how to associate runtime and link libraries... printf %s\n
    checking for ar... ar
    checking for archiver @FILE support... no
    checking for strip... strip
    checking for ranlib... ranlib
    checking command to parse /usr/bin/nm output from gcc object... ok
    checking for sysroot... no
    checking for a working dd... /bin/dd
    checking how to truncate binary pipes... /bin/dd bs=4096 count=1
    checking for mt... no
    checking if : is a manifest tool... no
    checking for dsymutil... dsymutil
    checking for nmedit... nmedit
    checking for lipo... lipo
    checking for otool... otool
    checking for otool64... no
    checking for -single_module linker flag... yes
    checking for -exported_symbols_list linker flag... yes
    checking for -force_load linker flag... yes
    checking how to run the C preprocessor... gcc -E
    checking for ANSI C header files... yes
    checking for sys/types.h... yes
    checking for sys/stat.h... yes
    checking for stdlib.h... yes
    checking for string.h... yes
    checking for memory.h... yes
    checking for strings.h... yes
    checking for inttypes.h... yes
    checking for stdint.h... yes
    checking for unistd.h... yes
    checking for dlfcn.h... yes
    checking for objdir... .libs
    checking if gcc supports -fno-rtti -fno-exceptions... yes
    checking for gcc option to produce PIC... -fno-common -DPIC
    checking if gcc PIC flag -fno-common -DPIC works... yes
    checking if gcc static flag -static works... no
    checking if gcc supports -c -o file.o... yes
    checking if gcc supports -c -o file.o... (cached) yes
    checking whether the gcc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
    checking dynamic linker characteristics... darwin15.0.0 dyld
    checking how to hardcode library paths into programs... immediate
    checking whether stripping libraries is possible... yes
    checking if libtool supports shared libraries... yes
    checking whether to build shared libraries... yes
    checking whether to build static libraries... yes
    checking how to run the C++ preprocessor... g++ -E
    checking for ld used by g++... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
    checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
    checking whether the g++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
    checking for g++ option to produce PIC... -fno-common -DPIC
    checking if g++ PIC flag -fno-common -DPIC works... yes
    checking if g++ static flag -static works... no
    checking if g++ supports -c -o file.o... yes
    checking if g++ supports -c -o file.o... (cached) yes
    checking whether the g++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
    checking dynamic linker characteristics... darwin15.0.0 dyld
    checking how to hardcode library paths into programs... immediate
    checking for ANSI C header files... (cached) yes
    checking fcntl.h usability... yes
    checking fcntl.h presence... yes
    checking for fcntl.h... yes
    checking for inttypes.h... (cached) yes
    checking limits.h usability... yes
    checking limits.h presence... yes
    checking for limits.h... yes
    checking for stdlib.h... (cached) yes
    checking for unistd.h... (cached) yes
    checking for working memcmp... yes
    checking for working strtod... yes
    checking for ftruncate... yes
    checking for memset... yes
    checking for mkdir... yes
    checking for strchr... yes
    checking for strerror... yes
    checking for strtol... yes
    checking google/protobuf/stubs/common.h usability... yes
    checking google/protobuf/stubs/common.h presence... no
    configure: WARNING: google/protobuf/stubs/common.h: accepted by the compiler, rejected by the preprocessor!
    configure: WARNING: google/protobuf/stubs/common.h: proceeding with the compiler's result
    checking for google/protobuf/stubs/common.h... yes
    checking that generated files are newer than configure... done
    configure: creating ./config.status
    config.status: creating Makefile
    config.status: creating src/compiler/Makefile
    config.status: creating config.h
    config.status: config.h is unchanged
    config.status: executing depfiles commands
    config.status: executing libtool commands
    + make clean
    Making clean in src/compiler
     rm -f protoc-gen-swift
    rm -rf .libs _libs
    rm -f *.o
    rm -f google/protobuf/*.o
    rm -f *.lo
    rm -rf .libs _libs
    rm -f *.lo
    + make -j8
    /Applications/Xcode.app/Contents/Developer/usr/bin/make  all-recursive
    Making all in src/compiler
    depbase=`echo main.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        g++ -DHAVE_CONFIG_H -I. -I../..     -I/usr/local/include -MT main.o -MD -MP -MF $depbase.Tpo -c -o main.o main.cc &&\
        mv -f $depbase.Tpo $depbase.Po
    depbase=`echo swift_enum_field.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        g++ -DHAVE_CONFIG_H -I. -I../..     -I/usr/local/include -MT swift_enum_field.o -MD -MP -MF $depbase.Tpo -c -o swift_enum_field.o swift_enum_field.cc &&\
        mv -f $depbase.Tpo $depbase.Po
    depbase=`echo swift_map_field.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        g++ -DHAVE_CONFIG_H -I. -I../..     -I/usr/local/include -MT swift_map_field.o -MD -MP -MF $depbase.Tpo -c -o swift_map_field.o swift_map_field.cc &&\
        mv -f $depbase.Tpo $depbase.Po
    depbase=`echo swift_file.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        g++ -DHAVE_CONFIG_H -I. -I../..     -I/usr/local/include -MT swift_file.o -MD -MP -MF $depbase.Tpo -c -o swift_file.o swift_file.cc &&\
        mv -f $depbase.Tpo $depbase.Po
    depbase=`echo swift_message_field.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        g++ -DHAVE_CONFIG_H -I. -I../..     -I/usr/local/include -MT swift_message_field.o -MD -MP -MF $depbase.Tpo -c -o swift_message_field.o swift_message_field.cc &&\
        mv -f $depbase.Tpo $depbase.Po
    depbase=`echo swift_oneof.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        g++ -DHAVE_CONFIG_H -I. -I../..     -I/usr/local/include -MT swift_oneof.o -MD -MP -MF $depbase.Tpo -c -o swift_oneof.o swift_oneof.cc &&\
        mv -f $depbase.Tpo $depbase.Po
    depbase=`echo swift_enum.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        g++ -DHAVE_CONFIG_H -I. -I../..     -I/usr/local/include -MT swift_enum.o -MD -MP -MF $depbase.Tpo -c -o swift_enum.o swift_enum.cc &&\
        mv -f $depbase.Tpo $depbase.Po
    depbase=`echo swift_generator.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        g++ -DHAVE_CONFIG_H -I. -I../..     -I/usr/local/include -MT swift_generator.o -MD -MP -MF $depbase.Tpo -c -o swift_generator.o swift_generator.cc &&\
        mv -f $depbase.Tpo $depbase.Po
    In file included from swift_generator.cc:22:
    ./google/protobuf/descriptor.pb.h:17:2: error: This file was generated by an older version of protoc which is
    #error This file was generated by an older version of protoc which is
     ^
    ./google/protobuf/descriptor.pb.h:18:2: error: incompatible with your Protocol Buffer headers.  Please
    #error incompatible with your Protocol Buffer headers.  Please
     ^
    ./google/protobuf/descriptor.pb.h:19:2: error: regenerate this file with a newer version of protoc.
    #error regenerate this file with a newer version of protoc.
     ^
    In file included from swift_file.cc:23:
    ./google/protobuf/descriptor.pb.h:17:2: error: This file was generated by an older version of protoc which is
    #error This file was generated by an older version of protoc which is
     ^
    ./google/protobuf/descriptor.pb.h:18:2: error: incompatible with your Protocol Buffer headers.  Please
    #error incompatible with your Protocol Buffer headers.  Please
     ^
    ./google/protobuf/descriptor.pb.h:19:2: error: regenerate this file with a newer version of protoc.
    #error regenerate this file with a newer version of protoc.
     ^
    In file included from swift_map_field.cc:25:
    In file included from /usr/local/include/google/protobuf/wire_format.h:44:
    ./google/protobuf/descriptor.pb.h:17:2: error: This file was generated by an older version of protoc which is
    #error This file was generated by an older version of protoc which is
     ^
    ./google/protobuf/descriptor.pb.h:18:2: error: incompatible with your Protocol Buffer headers.  Please
    #error incompatible with your Protocol Buffer headers.  Please
     ^
    ./google/protobuf/descriptor.pb.h:19:2: error: regenerate this file with a newer version of protoc.
    #error regenerate this file with a newer version of protoc.
     ^
    In file included from swift_oneof.cc:24:
    ./google/protobuf/descriptor.pb.h:17:2: error: This file was generated by an older version of protoc which is
    #error This file was generated by an older version of protoc which is
     ^
    ./google/protobuf/descriptor.pb.h:18:2: error: incompatible with your Protocol Buffer headers.  Please
    #error incompatible with your Protocol Buffer headers.  Please
     ^
    ./google/protobuf/descriptor.pb.h:19:2: error: regenerate this file with a newer version of protoc.
    #error regenerate this file with a newer version of protoc.
     ^
    In file included from swift_enum.cc:24:
    ./google/protobuf/descriptor.pb.h:17:2: error: This file was generated by an older version of protoc which is
    #error This file was generated by an older version of protoc which is
     ^
    ./google/protobuf/descriptor.pb.h:18:2: error: incompatible with your Protocol Buffer headers.  Please
    #error incompatible with your Protocol Buffer headers.  Please
     ^
    ./google/protobuf/descriptor.pb.h:19:2: error: regenerate this file with a newer version of protoc.
    #error regenerate this file with a newer version of protoc.
     ^
    In file included from swift_message_field.cc:24:
    In file included from /usr/local/include/google/protobuf/wire_format.h:44:
    ./google/protobuf/descriptor.pb.h:17:2: error: This file was generated by an older version of protoc which is
    #error This file was generated by an older version of protoc which is
     ^
    ./google/protobuf/descriptor.pb.h:18:2: error: incompatible with your Protocol Buffer headers.  Please
    #error incompatible with your Protocol Buffer headers.  Please
     ^
    ./google/protobuf/descriptor.pb.h:19:2: error: regenerate this file with a newer version of protoc.
    #error regenerate this file with a newer version of protoc.
     ^
    In file included from swift_enum_field.cc:25:
    In file included from /usr/local/include/google/protobuf/wire_format.h:44:
    ./google/protobuf/descriptor.pb.h:17:2: error: This file was generated by an older version of protoc which is
    #error This file was generated by an older version of protoc which is
     ^
    ./google/protobuf/descriptor.pb.h:18:2: error: incompatible with your Protocol Buffer headers.  Please
    #error incompatible with your Protocol Buffer headers.  Please
     ^
    ./google/protobuf/descriptor.pb.h:19:2: error: regenerate this file with a newer version of protoc.
    #error regenerate this file with a newer version of protoc.
     ^
    depbase=`echo swift_primitive_field.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
        g++ -DHAVE_CONFIG_H -I. -I../..     -I/usr/local/include -MT swift_primitive_field.o -MD -MP -MF $depbase.Tpo -c -o swift_primitive_field.o swift_primitive_field.cc &&\
        mv -f $depbase.Tpo $depbase.Po
    3 errors generated.
    make[2]: *** [swift_oneof.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    3 errors generated.
    make[2]: *** [swift_enum.o] Error 1
    3 errors generated.
    make[2]: *** [swift_generator.o] Error 1
    3 errors generated.
    3 errors generated.
    make[2]: *** [swift_enum_field.o] Error 1
    make[2]: *** [swift_message_field.o] Error 1
    3 errors generated.
    make[2]: *** [swift_map_field.o] Error 1
    In file included from swift_primitive_field.cc:25:
    In file included from /usr/local/include/google/protobuf/wire_format.h:44:
    ./google/protobuf/descriptor.pb.h:17:2: error: This file was generated by an older version of protoc which is
    #error This file was generated by an older version of protoc which is
     ^
    ./google/protobuf/descriptor.pb.h:18:2: error: incompatible with your Protocol Buffer headers.  Please
    #error incompatible with your Protocol Buffer headers.  Please
     ^
    ./google/protobuf/descriptor.pb.h:19:2: error: regenerate this file with a newer version of protoc.
    #error regenerate this file with a newer version of protoc.
     ^
    3 errors generated.
    make[2]: *** [swift_file.o] Error 1
    3 errors generated.
    make[2]: *** [swift_primitive_field.o] Error 1
    make[1]: *** [all-recursive] Error 1
    make: *** [all] Error 2
    
    opened by vyshane 8
  • InvalidProtocolBuffer

    InvalidProtocolBuffer


    Terminating app due to uncaught exception 'InvalidProtocolBuffer', reason: 'Invalid Tag: last tag 100' *** First throw call stack: ( 0 CoreFoundation 0x000000010452fc65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000103db0bb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010452f8a9 -[NSException raise] + 9 3 ProtocolBuffers 0x0000000102d55d1a TFC15ProtocolBuffers16CodedInputStream15checkLastTagWasfS0_FVSs5Int32T + 954

    4 ProtocolBuffers 0x0000000102d4dd39 TFC15ProtocolBuffers22AbstractMessageBuilder13mergeFromDatafDS0_FTCSo6NSData17extensionRegistryCS_17ExtensionRegistry_DS0 + 185

    I cannot find out witch parameter has error,how can i find out it?

    question unknown 
    opened by zhouzizi 8
  • Xcode12 build failure - Generic parameter 'Element' could not be inferred

    Xcode12 build failure - Generic parameter 'Element' could not be inferred

    I am facing the same issue in protobuf-swift while compiling in XCode 12.4 whereas it is working fine in 11.2 MACOS - 11.2.3 (Big Sur) XCode - 12.4 Swift Version - 4, 5 tried both

    Screenshot 2021-05-03 at 1 09 02 AM Screenshot 2021-05-03 at 1 19 45 AM
    opened by thatsmerahul1 2
  • Install failed

    Install failed

    I download version is 4.0.6 when I input '$ ./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ' or '$ ./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib64' checking build system type... x86_64-apple-darwin18.5.0 checking host system type... x86_64-apple-darwin18.5.0 checking target system type... x86_64-apple-darwin18.5.0 checking for a BSD-compatible install... /usr/local/bin/ginstall -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/local/bin/gmkdir -p checking for gawk... no checking for mawk... no checking for nawk... no checking for awk... awk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking whether make supports the include directive... yes (GNU style) checking dependency style of gcc... gcc3 checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking dependency style of g++... gcc3 checking C++ compiler flags...... use user-supplied: -I/usr/local/include checking how to print strings... printf checking for a sed that does not truncate output... /usr/bin/sed checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for fgrep... /usr/bin/grep -F checking for ld used by gcc... /Library/Developer/CommandLineTools/usr/bin/ld checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 196608 checking how to convert x86_64-apple-darwin18.5.0 file names to x86_64-apple-darwin18.5.0 format... func_convert_file_noop checking how to convert x86_64-apple-darwin18.5.0 file names to toolchain format... func_convert_file_noop checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for ar... ar checking for archiver @FILE support... no checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from gcc object... ok checking for sysroot... no checking for a working dd... /bin/dd checking how to truncate binary pipes... /bin/dd bs=4096 count=1 checking for mt... no checking if : is a manifest tool... no checking for dsymutil... dsymutil checking for nmedit... nmedit checking for lipo... lipo checking for otool... otool checking for otool64... no checking for -single_module linker flag... yes checking for -exported_symbols_list linker flag... yes checking for -force_load linker flag... yes checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... yes checking for gcc option to produce PIC... -fno-common -DPIC checking if gcc PIC flag -fno-common -DPIC works... yes checking if gcc static flag -static works... no checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes checking dynamic linker characteristics... darwin18.5.0 dyld checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking how to run the C++ preprocessor... g++ -E checking for ld used by g++... /Library/Developer/CommandLineTools/usr/bin/ld checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no checking whether the g++ linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes checking for g++ option to produce PIC... -fno-common -DPIC checking if g++ PIC flag -fno-common -DPIC works... yes checking if g++ static flag -static works... no checking if g++ supports -c -o file.o... yes checking if g++ supports -c -o file.o... (cached) yes checking whether the g++ linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes checking dynamic linker characteristics... darwin18.5.0 dyld checking how to hardcode library paths into programs... immediate checking for ANSI C header files... (cached) yes checking fcntl.h usability... yes checking fcntl.h presence... yes checking for fcntl.h... yes checking for inttypes.h... (cached) yes checking limits.h usability... yes checking limits.h presence... yes checking for limits.h... yes checking for stdlib.h... (cached) yes checking for unistd.h... (cached) yes checking for working memcmp... yes checking for working strtod... yes checking for ftruncate... yes checking for memset... yes checking for mkdir... yes checking for strchr... yes checking for strerror... yes checking for strtol... yes checking google/protobuf/stubs/common.h usability... no checking google/protobuf/stubs/common.h presence... yes configure: WARNING: google/protobuf/stubs/common.h: present but cannot be compiled configure: WARNING: google/protobuf/stubs/common.h: check for missing prerequisite headers? configure: WARNING: google/protobuf/stubs/common.h: see the Autoconf documentation configure: WARNING: google/protobuf/stubs/common.h: section "Present But Cannot Be Compiled" configure: WARNING: google/protobuf/stubs/common.h: proceeding with the compiler's result configure: WARNING: ## --------------------------------- ## configure: WARNING: ## Report this to alexeyxo.gmail.com ## configure: WARNING: ## --------------------------------- ## checking for google/protobuf/stubs/common.h... no configure: error: ERROR: protobuf headers are required.

    You must either install protobuf from google, or if you have it installed in a custom location you must add '-Iincludedir' to CXXFLAGS and '-Llibdir' to LDFLAGS.

    If you did not specify a prefix when installing protobuf, try './configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib -std=c++11' In some 64-bit environments, try LDFLAGS=-L/usr/local/lib64.

    What can I do next?

    opened by leonxjf 0
  • protocol buffer build.sh error and show “protobuf test program failed to link”

    protocol buffer build.sh error and show “protobuf test program failed to link”

    I am setting up protocal buffer in my mac(10.14.4) I step by step according to the readme When I input ./scripts/build.sh in the terminal and it tells me: ERROR: protobuf test program failed to link: perhaps you need to add -Llibdir to your LDFLAGS.

    what should I do? what is mean "add -Llibdir to your LDFLAGS" and how to fix it?

    opened by leonxjf 4
  • [Question] Use RawValue enum when formatting to JSON

    [Question] Use RawValue enum when formatting to JSON

    Description

    Version of protoc (protoc --version)

    libprotoc 3.6.1

    Version of ProtocolBuffers.framework

    Protobuf-swift version: 4.0

    Description

    Here is an enum in my proto file

    enum battery_status { STARTED = 0; STOPED = 1; ABSENT = 2; }

    To send it back in JSON, I use battery_status.encode()

    I get :

    ["status": "ABSENT"]

    Is there a way that the dictionary outputted uses raw value ?

    What I want is to get :

    ["status":2]

    Thanks

    opened by gregoireLem 0
  • Question : Codable

    Question : Codable

    Version of protoc (protoc --version)

    libprotoc 3.6.1

    Version of ProtocolBuffers.framework

    Protobuf-swift version: 4.0

    Description

    How can I make the objects conform to Codable ?

    Thanks for helping

    opened by gregoireLem 0
Releases(4.0.6)
Software Dummy Display Adapter for Apple Silicon Macs to Have Custom HiDPI Resolutions.

BetterDummy Dummy Display for Apple Silicon Macs to achieve custom resolutions. About M1 macs tend to have issues with custom resolutions. Notoriously

Istvan T. 8k Jan 9, 2023
DDC Library for Apple Silicon Macs

AppleSiliconDDC DDC Library for Apple Silicon Macs Usage Upcoming... For sample implementation take a look at the source code of MonitorControl (as Ar

Istvan T. 7 Oct 7, 2022
an Apple Watch® BINGO number generator app with histogram and history.

B4-BINGO-Number-Generator an Apple Watch® BINGO number generator app with histogram and history. This is a basic app using the Apple Watch which displ

Thomas Cavalli 1 Dec 7, 2021
Ecolande - Application realisé pendant l'Apple foundation Program.

Ecolande Application realisé pendant l'Apple foundation Program. Ecoland est l'application qui a été réalisé pendant l'Apple Foundation Program. Nous

Bilal Larose 1 Dec 31, 2021
Minecraft-silicon - Generate Apple Silicon-native versions of Minecraft

Minecraft Silicon A dead simple utility to generate Apple Silicon-native Minecra

Cole Feuer 4 Jun 21, 2022
A tool to convert Apple PencilKit data to Scribble Proto3.

ScribbleConverter Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation

Paul Han 1 Aug 1, 2022
A most fully customization calendar for Apple platforms 📅

KVKCalendar KVKCalendar is a most fully customization calendar. Library consists of five modules for displaying various types of calendar (day, week,

Kviatkovskii Sergei 353 Jan 5, 2023
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Apple 2k Dec 28, 2022
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Swift - ✏️Swift 공부 저장소✏️

Swift 스위프트의 기초 1. Swift의 기본 2. 변수와 상수 [3. 데이터 타입 기본] [4. 데이터 타입 고급] 5. 연산자 6. 흐름 제어 7. 함수 8. 옵셔널 객체지향 프로그래밍과 스위프트 9. 구조체와 클래스 10. 프로퍼티와 메서드 11. 인스턴스 생

Jiwon 0 Mar 9, 2022
Swift-ndi - Swift wrapper around NewTek's NDI SDK

swift-ndi Swift wrapper around NewTek's NDI SDK. Make sure you extracted latest

Alessio Nossa 12 Dec 29, 2022
__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

Tatsuya Hirose 86 Jun 29, 2022
SNTabBarDemo-Swift - Cool TabBar With Swift

SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu

iAnchor 3 Sep 29, 2022
Swift-when - Expression switch support in Swift

Swift When - supporting switch expressions in Swift! What is it? Basically, it a

Gordan Glavaš 7 Nov 24, 2022
Swift-compute-runtime - Swift runtime for Fastly Compute@Edge

swift-compute-runtime Swift runtime for Fastly Compute@Edge Getting Started Crea

Andrew Barba 57 Dec 24, 2022
Swift-HorizontalPickerView - Customizable horizontal picker view component written in Swift for UIKit/iOS

Horizontal Picker View Customizable horizontal picker view component written in

Afraz Siddiqui 8 Aug 1, 2022
swift-highlight a pure-Swift data structure library designed for server applications that need to store a lot of styled text

swift-highlight is a pure-Swift data structure library designed for server applications that need to store a lot of styled text. The Highlight module is memory-efficient and uses slab allocations and small-string optimizations to pack large amounts of styled text into a small amount of memory, while still supporting efficient traversal through the Sequence protocol.

kelvin 4 Aug 14, 2022