Skip to content

Commit

Permalink
Simplify proto value decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Hagen committed Jul 9, 2022
1 parent ed98585 commit fadbaa7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ class ProtoDecodingNode: AbstractDecodingNode, Decoder {

let storage: Storage

private let isAtTopLevel: Bool

init(data: Data, top: Bool = false, path: [CodingKey], info: UserInfo) {
init(data: Data, path: [CodingKey], info: UserInfo) {
self.storage = .data(data)
self.isAtTopLevel = top
super.init(path: path, info: info)
}

init(decoder: DataDecoder, isNil: Bool = false, path: [CodingKey], info: UserInfo) {
init(decoder: DataDecoder, path: [CodingKey], info: UserInfo) {
self.storage = .decoder(decoder)
self.isAtTopLevel = false
super.init(path: path, info: info)
}

Expand All @@ -30,7 +26,6 @@ class ProtoDecodingNode: AbstractDecodingNode, Decoder {
func singleValueContainer() throws -> SingleValueDecodingContainer {
return ProtoValueDecoder(
data: storage.useAsDecoder(),
top: isAtTopLevel,
path: codingPath,
info: userInfo)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ final class ProtoValueDecoder: AbstractDecodingNode, SingleValueDecodingContaine

let data: DataDecoder

private let isAtTopLevel: Bool

init(data: DataDecoder, top: Bool = false, path: [CodingKey], info: UserInfo) {
init(data: DataDecoder, path: [CodingKey], info: UserInfo) {
self.data = data
self.isAtTopLevel = top
super.init(path: path, info: info)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/BinaryCodable/ProtobufDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class ProtobufDecoder {
- Throws: Errors of type `BinaryDecodingError` or `ProtobufDecodingError`
*/
public func decode<T>(_ type: T.Type = T.self, from data: Data) throws -> T where T: Decodable {
let root = ProtoDecodingNode(data: data, top: true, path: [], info: userInfo)
let root = ProtoDecodingNode(data: data, path: [], info: userInfo)
return try type.init(from: root)
}

Expand Down

0 comments on commit fadbaa7

Please sign in to comment.