Skip to content

Commit

Permalink
Skip encoding any optionals. Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaRU committed Jan 29, 2024
1 parent 6229168 commit cf9bc40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
25 changes: 18 additions & 7 deletions Sources/CDRCodable/Encoder/KeyedEncodingContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,24 @@ extension _CDREncoder.KeyedContainer: KeyedEncodingContainerProtocol {
self.dataStore.data.append(pointer.baseAddress!.assumingMemoryBound(to: UInt8.self), count: count * size)
}

func encodeNil(forKey key: Key) throws {
}
// Ignoring optionals as having no analog in the CDR protocol
func encodeNil(forKey key: Key) throws {}
func encodeIfPresent(_ value: Bool?, forKey key: Key) throws {}
func encodeIfPresent(_ value: String?, forKey key: Key) throws {}
func encodeIfPresent(_ value: Double?, forKey key: Key) throws {}
func encodeIfPresent(_ value: Float?, forKey key: Key) throws {}
func encodeIfPresent(_ value: Int?, forKey key: Key) throws {}
func encodeIfPresent(_ value: Int8?, forKey key: Key) throws {}
func encodeIfPresent(_ value: Int16?, forKey key: Key) throws {}
func encodeIfPresent(_ value: Int32?, forKey key: Key) throws {}
func encodeIfPresent(_ value: Int64?, forKey key: Key) throws {}
func encodeIfPresent(_ value: UInt?, forKey key: Key) throws {}
func encodeIfPresent(_ value: UInt8?, forKey key: Key) throws {}
func encodeIfPresent(_ value: UInt16?, forKey key: Key) throws {}
func encodeIfPresent(_ value: UInt32?, forKey key: Key) throws {}
func encodeIfPresent(_ value: UInt64?, forKey key: Key) throws {}
func encodeIfPresent<T>(_ value: T?, forKey key: Key) throws where T : Encodable {}


func encode(_ value: Bool, forKey key: Key) throws {
switch value {
Expand Down Expand Up @@ -84,11 +100,6 @@ extension _CDREncoder.KeyedContainer: KeyedEncodingContainerProtocol {
}
}

private func nestedSingleValueContainer(forKey key: Key) -> SingleValueEncodingContainer {
let container = _CDREncoder.SingleValueContainer(dataStore: self.dataStore, codingPath: self.nestedCodingPath(forKey: key), userInfo: self.userInfo)
return container
}

func nestedUnkeyedContainer(forKey key: Key) -> UnkeyedEncodingContainer {
let container = _CDREncoder.UnkeyedContainer(dataStore: self.dataStore, codingPath: self.nestedCodingPath(forKey: key), userInfo: self.userInfo)
return container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ extension _CDREncoder {
}

extension _CDREncoder.SingleValueContainer: SingleValueEncodingContainer {
func encodeNil() throws {
}
func encodeNil() throws {}

func encode(_ value: Bool) throws {
switch value {
Expand Down
7 changes: 1 addition & 6 deletions Sources/CDRCodable/Encoder/UnkeyedEncodingContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ extension _CDREncoder {
}

extension _CDREncoder.UnkeyedContainer: UnkeyedEncodingContainer {
func encodeNil() throws {
}
func encodeNil() throws {}

func encode<T>(_ value: T) throws where T : Encodable {
defer { count += 1 }
let encoder = _CDREncoder(data: self.dataStore)
try value.encode(to: encoder)
}

private func nestedSingleValueContainer() -> SingleValueEncodingContainer {
fatalError("Unimplemented")
}

func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey> where NestedKey : CodingKey {
fatalError("Unimplemented")
}
Expand Down

0 comments on commit cf9bc40

Please sign in to comment.