Skip to content

Commit

Permalink
Format options
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Khokhlov committed Jun 18, 2018
1 parent 3020ce1 commit 76b779a
Show file tree
Hide file tree
Showing 46 changed files with 1,631 additions and 1,145 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: objective-c
osx_image: xcode9
before_install:
- brew update
- brew install protobuf
# - brew uninstall xctool
# - brew install xctool --HEAD
Expand Down
2 changes: 1 addition & 1 deletion ProtocolBuffers-Swift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ProtocolBuffers-Swift"
s.version = "4.0.2"
s.version = "4.0.3"
s.summary = "Protocol Buffers for Swift"
s.homepage = "http://protobuf.io#swift"
s.license = "Apache 2.0"
Expand Down
14 changes: 7 additions & 7 deletions Source/AbstractMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public protocol ProtocolBuffersMessage:ProtocolBuffersMessageInit {
//JSON
func encode() throws -> Dictionary<String,Any>
static func decode(jsonMap:Dictionary<String,Any>) throws -> Self
func toJSON() throws -> Data
static func fromJSON(data:Data) throws -> Self
func toJSON(options: JSONSerialization.WritingOptions) throws -> Data
static func fromJSON(data:Data, options: JSONSerialization.ReadingOptions) throws -> Self

}

Expand All @@ -66,7 +66,7 @@ public protocol ProtocolBuffersMessageBuilder {
func mergeDelimitedFrom(inputStream:InputStream) throws -> Self?

static func decodeToBuilder(jsonMap:Dictionary<String,Any>) throws -> Self
static func fromJSONToBuilder(data:Data) throws -> Self
static func fromJSONToBuilder(data:Data, options: JSONSerialization.ReadingOptions) throws -> Self

}

Expand Down Expand Up @@ -141,12 +141,12 @@ open class AbstractProtocolBuffersMessage:Hashable, ProtocolBuffersMessage {
throw ProtocolBuffersError.obvious("JSON Encoding/Decoding available only in syntax=\"proto3\"")
}

open func toJSON() throws -> Data {
let json = try JSONSerialization.data(withJSONObject: encode())
open func toJSON(options: JSONSerialization.WritingOptions = []) throws -> Data {
let json = try JSONSerialization.data(withJSONObject: encode(), options:options)
return json
}

open class func fromJSON(data:Data) throws -> Self {
open class func fromJSON(data:Data, options: JSONSerialization.ReadingOptions) throws -> Self {
throw ProtocolBuffersError.obvious("JSON Encoding/Decoding available only in syntax=\"proto3\"")
}

Expand Down Expand Up @@ -238,7 +238,7 @@ open class AbstractProtocolBuffersMessageBuilder:ProtocolBuffersMessageBuilder {
throw ProtocolBuffersError.obvious("JSON Encoding/Decoding available only in syntax=\"proto3\"")
}

open class func fromJSONToBuilder(data: Data) throws -> Self {
open class func fromJSONToBuilder(data: Data, options: JSONSerialization.ReadingOptions = []) throws -> Self {
throw ProtocolBuffersError.obvious("JSON Encoding/Decoding available only in syntax=\"proto3\"")
}

Expand Down
8 changes: 4 additions & 4 deletions Source/Google.Protobuf.Any.proto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public extension Google.Protobuf {
override class public func decode(jsonMap:Dictionary<String,Any>) throws -> Google.Protobuf.`Any` {
return try Google.Protobuf.`Any`.Builder.decodeToBuilder(jsonMap:jsonMap).build()
}
override class public func fromJSON(data:Data) throws -> Google.Protobuf.`Any` {
return try Google.Protobuf.`Any`.Builder.fromJSONToBuilder(data:data).build()
override class public func fromJSON(data:Data, options: JSONSerialization.ReadingOptions = []) throws -> Google.Protobuf.`Any` {
return try Google.Protobuf.`Any`.Builder.fromJSONToBuilder(data:data, options:options).build()
}
override public func getDescription(indent:String) throws -> String {
var output = ""
Expand Down Expand Up @@ -343,8 +343,8 @@ public extension Google.Protobuf {
}
return resultDecodedBuilder
}
override class public func fromJSONToBuilder(data:Data) throws -> Google.Protobuf.`Any`.Builder {
let jsonData = try JSONSerialization.jsonObject(with:data)
override class public func fromJSONToBuilder(data:Data, options: JSONSerialization.ReadingOptions = []) throws -> Google.Protobuf.`Any`.Builder {
let jsonData = try JSONSerialization.jsonObject(with:data, options: options)
guard let jsDataCast = jsonData as? Dictionary<String,Any> else {
throw ProtocolBuffersError.invalidProtocolBuffer("Invalid JSON data")
}
Expand Down
16 changes: 8 additions & 8 deletions Source/Google.Protobuf.Api.proto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ public extension Google.Protobuf {
override class public func decode(jsonMap:Dictionary<String,Any>) throws -> Google.Protobuf.Api {
return try Google.Protobuf.Api.Builder.decodeToBuilder(jsonMap:jsonMap).build()
}
override class public func fromJSON(data:Data) throws -> Google.Protobuf.Api {
return try Google.Protobuf.Api.Builder.fromJSONToBuilder(data:data).build()
override class public func fromJSON(data:Data, options: JSONSerialization.ReadingOptions = []) throws -> Google.Protobuf.Api {
return try Google.Protobuf.Api.Builder.fromJSONToBuilder(data:data, options:options).build()
}
override public func getDescription(indent:String) throws -> String {
var output = ""
Expand Down Expand Up @@ -541,8 +541,8 @@ public extension Google.Protobuf {
}
return resultDecodedBuilder
}
override class public func fromJSONToBuilder(data:Data) throws -> Google.Protobuf.Api.Builder {
let jsonData = try JSONSerialization.jsonObject(with:data)
override class public func fromJSONToBuilder(data:Data, options: JSONSerialization.ReadingOptions = []) throws -> Google.Protobuf.Api.Builder {
let jsonData = try JSONSerialization.jsonObject(with:data, options: options)
guard let jsDataCast = jsonData as? Dictionary<String,Any> else {
throw ProtocolBuffersError.invalidProtocolBuffer("Invalid JSON data")
}
Expand Down Expand Up @@ -696,8 +696,8 @@ public extension Google.Protobuf {
override class public func decode(jsonMap:Dictionary<String,Any>) throws -> Google.Protobuf.Method {
return try Google.Protobuf.Method.Builder.decodeToBuilder(jsonMap:jsonMap).build()
}
override class public func fromJSON(data:Data) throws -> Google.Protobuf.Method {
return try Google.Protobuf.Method.Builder.fromJSONToBuilder(data:data).build()
override class public func fromJSON(data:Data, options: JSONSerialization.ReadingOptions = []) throws -> Google.Protobuf.Method {
return try Google.Protobuf.Method.Builder.fromJSONToBuilder(data:data, options:options).build()
}
override public func getDescription(indent:String) throws -> String {
var output = ""
Expand Down Expand Up @@ -1038,8 +1038,8 @@ public extension Google.Protobuf {
}
return resultDecodedBuilder
}
override class public func fromJSONToBuilder(data:Data) throws -> Google.Protobuf.Method.Builder {
let jsonData = try JSONSerialization.jsonObject(with:data)
override class public func fromJSONToBuilder(data:Data, options: JSONSerialization.ReadingOptions = []) throws -> Google.Protobuf.Method.Builder {
let jsonData = try JSONSerialization.jsonObject(with:data, options: options)
guard let jsDataCast = jsonData as? Dictionary<String,Any> else {
throw ProtocolBuffersError.invalidProtocolBuffer("Invalid JSON data")
}
Expand Down
Loading

0 comments on commit 76b779a

Please sign in to comment.