Skip to content

Commit

Permalink
Refacoring: remove unnecessary code.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaRU committed Jan 30, 2024
1 parent cf9bc40 commit bcfdcde
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 58 deletions.
32 changes: 0 additions & 32 deletions Sources/CDRCodable/Box.swift

This file was deleted.

8 changes: 1 addition & 7 deletions Sources/CDRCodable/Decoder/CDRDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ final public class CDRDecoder {
let decoder = _CDRDecoder(data: _CDRDecoder.DataBlock(data: data))
decoder.userInfo = self.userInfo

switch type {
case is Data.Type:
let box = try Box<Data>(from: decoder)
return box.value as! T
default:
return try T(from: decoder)
}
return try T(from: decoder)
}
}

Expand Down
8 changes: 2 additions & 6 deletions Sources/CDRCodable/Decoder/SingleValueDecodingContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ extension _CDRDecoder.SingleValueContainer: SingleValueDecodingContainer {
return t
}

func decode(_ type: Data.Type) throws -> Data {
let length = Int(try read(UInt32.self))
return try read(length)
}

func decode<T>(_ type: T.Type) throws -> T where T : Decodable {
switch type {
case is Data.Type:
return try decode(Data.self) as! T
let length = Int(try read(UInt32.self))
return try read(length) as! T
default:
let decoder = _CDRDecoder(data: self.data)
let value = try T(from: decoder)
Expand Down
9 changes: 2 additions & 7 deletions Sources/CDRCodable/Encoder/CDREncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@ final public class CDREncoder {
var encoder: _CDREncoder? = _CDREncoder(data: dataBlock)
encoder!.userInfo = self.userInfo

switch value {
case let data as Data:
try Box<Data>(data).encode(to: encoder!)
default:
try value.encode(to: encoder!)
}

try value.encode(to: encoder!)

encoder = nil // call deinit and finalize dataBlock changes.
// Final data aligment
let aligment = dataBlock.data.count % 4
Expand Down
8 changes: 2 additions & 6 deletions Sources/CDRCodable/Encoder/SingleValueEncodingContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@ extension _CDREncoder.SingleValueContainer: SingleValueEncodingContainer {
dataStore.write(value: value)
}

func encode(_ value: Data) throws {
try write(count: value.count)
dataStore.write(data: value)
}

func encode<T>(_ value: T) throws where T : Encodable {
switch value {
case let data as Data:
try self.encode(data)
try write(count: data.count)
dataStore.write(data: data)
default:
let encoder = _CDREncoder(data: self.dataStore)
try value.encode(to: encoder)
Expand Down

0 comments on commit bcfdcde

Please sign in to comment.