Skip to content

Commit

Permalink
Rename decodeBinary.
Browse files Browse the repository at this point in the history
Rename decodeBinary(from:count:extensions:) to
_mergeSerializedData(from:count:extensions:) since it merges into
the existing message and to tag it as an internal detail.
  • Loading branch information
thomasvl committed Feb 23, 2017
1 parent b4d5f25 commit c2120ff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Sources/SwiftProtobuf/BinaryDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ struct BinaryDecoder: Decoder {
if value == nil {
value = M()
}
try value!.decodeBinary(from: p, count: count, extensions: extensions)
try value!._mergeSerializedData(from: p, count: count, extensions: extensions)
consumed = true
}

Expand All @@ -829,7 +829,7 @@ struct BinaryDecoder: Decoder {
var count: Int = 0
let p = try getFieldBodyBytes(count: &count)
var newValue = M()
try newValue.decodeBinary(from: p, count: count, extensions: extensions)
try newValue._mergeSerializedData(from: p, count: count, extensions: extensions)
value.append(newValue)
consumed = true
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftProtobuf/BinaryTypeAdditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public extension Message {
mutating func merge(serializedData data: Data, extensions: ExtensionSet? = nil, partial: Bool = false) throws {
if !data.isEmpty {
try data.withUnsafeBytes { (pointer: UnsafePointer<UInt8>) in
try decodeBinary(from: pointer,
count: data.count,
extensions: extensions)
try _mergeSerializedData(from: pointer,
count: data.count,
extensions: extensions)
}
}
if !partial && !isInitialized {
Expand All @@ -103,7 +103,7 @@ public extension Message {

/// Proto2 messages preserve unknown fields
public extension Proto2Message {
public mutating func decodeBinary(from bytes: UnsafePointer<UInt8>, count: Int, extensions: ExtensionSet?) throws {
public mutating func _mergeSerializedData(from bytes: UnsafePointer<UInt8>, count: Int, extensions: ExtensionSet?) throws {
var decoder = BinaryDecoder(forReadingFrom: bytes, count: count, extensions: extensions)
try decodeMessage(decoder: &decoder)
guard decoder.complete else {
Expand All @@ -117,7 +117,7 @@ public extension Proto2Message {

// Proto3 messages ignore unknown fields
public extension Proto3Message {
public mutating func decodeBinary(from bytes: UnsafePointer<UInt8>, count: Int, extensions: ExtensionSet?) throws {
public mutating func _mergeSerializedData(from bytes: UnsafePointer<UInt8>, count: Int, extensions: ExtensionSet?) throws {
var decoder = BinaryDecoder(forReadingFrom: bytes, count: count, extensions: extensions)
try decodeMessage(decoder: &decoder)
guard decoder.complete else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftProtobuf/Google_Protobuf_Any.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public struct Google_Protobuf_Any: Message, Proto3Message, _MessageImplementatio
// Decode protobuf from the stored bytes
if protobuf.count > 0 {
try protobuf.withUnsafeBytes { (p: UnsafePointer<UInt8>) in
try target.decodeBinary(from: p, count: protobuf.count, extensions: nil)
try target._mergeSerializedData(from: p, count: protobuf.count, extensions: nil)
}
}
return
Expand Down
10 changes: 4 additions & 6 deletions Sources/SwiftProtobuf/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ public protocol Message: CustomDebugStringConvertible {
/// behaviors for specific encodings, but the general idea is quite simple.
func traverse<V: Visitor>(visitor: inout V) throws

//
// Protobuf Binary decoding
//
mutating func decodeBinary(from: UnsafePointer<UInt8>,
count: Int,
extensions: ExtensionSet?) throws
/// SwiftProtobuf Internal: Common support for decoding.
mutating func _mergeSerializedData(from: UnsafePointer<UInt8>,
count: Int,
extensions: ExtensionSet?) throws

//
// Protobuf Text decoding
Expand Down

0 comments on commit c2120ff

Please sign in to comment.