Skip to content

Commit

Permalink
Tighten up attribute group encoding from #193 (#195)
Browse files Browse the repository at this point in the history
* Remove PrintStyle DynamicNodeEncoding conformance

* Tidy encoding of attribute groups
  • Loading branch information
jsbean authored Oct 29, 2019
1 parent e5e7e8c commit a02940e
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 25 deletions.
3 changes: 1 addition & 2 deletions Sources/MusicXML/Complex Types/AccordionRegistration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ extension AccordionRegistration: Codable {
self.middle = try container.decodeIfPresent(AccordionMiddle.self, forKey: .middle)
}
public func encode(to encoder: Encoder) throws {
var singleValueContainer = encoder.singleValueContainer()
try singleValueContainer.encode(printStyleAlign)
try printStyleAlign.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if high { try container.encode(Empty(), forKey: .high) }
if low { try container.encode(Empty(), forKey: .low) }
Expand Down
3 changes: 1 addition & 2 deletions Sources/MusicXML/Complex Types/Harmonic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ extension Harmonic: Codable {
}

public func encode(to encoder: Encoder) throws {
var singleValueContainer = encoder.singleValueContainer()
try singleValueContainer.encode(printStyle)
try printStyle.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
if let baseSoundingTouchingPitch = self.baseSoundingTouchingPitch {
switch baseSoundingTouchingPitch {
Expand Down
3 changes: 1 addition & 2 deletions Sources/MusicXML/Complex Types/LyricFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ extension LyricFont: Codable {
self.name = try container.decodeIfPresent(String.self, forKey: .name)
}
public func encode(to encoder: Encoder) throws {
var singleValueContainer = encoder.singleValueContainer()
try singleValueContainer.encode(font)
try font.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(number, forKey: .number)
try container.encodeIfPresent(name, forKey: .name)
Expand Down
8 changes: 0 additions & 8 deletions Sources/MusicXML/Complex Types/PrintStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,3 @@ extension PrintStyle: Codable {
try container.encodeIfPresent(color, forKey: .color)
}
}

import XMLCoder

extension PrintStyle: DynamicNodeEncoding {
public static func nodeEncoding(for key: CodingKey) -> XMLEncoder.NodeEncoding {
return .attribute
}
}
3 changes: 1 addition & 2 deletions Sources/MusicXML/Complex Types/Technical.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extension Technical: Codable {
values = try container.decode([Technique].self)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(values)
try values.encode(to: encoder)
}
}
3 changes: 1 addition & 2 deletions Sources/MusicXML/Simple Types/AccordionMiddle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public struct AccordionMiddle {
extension AccordionMiddle: Equatable {}
extension AccordionMiddle: Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(value)
try value.encode(to: encoder)
}

public init(from decoder: Decoder) throws {
Expand Down
3 changes: 1 addition & 2 deletions Sources/MusicXML/Simple Types/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ extension Color: Codable {
self = color
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(String(hexValue, radix: 16, uppercase: true))
try String(hexValue, radix: 16, uppercase: true).encode(to: encoder)
}
}

Expand Down
5 changes: 2 additions & 3 deletions Sources/MusicXML/Simple Types/FontSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ extension FontSize: Codable {
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case let .css(size):
try container.encode(size)
try size.encode(to: encoder)
case let .numeric(size):
try container.encode(size)
try size.encode(to: encoder)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/MusicXML/Simple Types/Tenths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ extension Tenths: Hashable { }

extension Tenths: Codable {
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(value)
try value.encode(to: encoder)
}

public init(from decoder: Decoder) throws {
Expand Down

0 comments on commit a02940e

Please sign in to comment.