File tree 1 file changed +16
-3
lines changed
1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ public protocol ScaleEncoder {
18
18
@discardableResult
19
19
func encode( _ value: ScaleEncodable ) throws -> ScaleEncoder
20
20
func write( _ data: Data )
21
+
22
+ // Make a copy of encoder preserving `path`.
23
+ // If full = True data will be copied too
24
+ func fork( full: Bool ) -> ScaleEncoder
21
25
}
22
26
23
27
internal class SEncoder : ScaleEncoder {
@@ -28,9 +32,13 @@ internal class SEncoder: ScaleEncoder {
28
32
return context. currentPath
29
33
}
30
34
31
- init ( ) {
32
- output = Data ( )
33
- context = SContext ( )
35
+ convenience init ( ) {
36
+ self . init ( output: Data ( ) , context: SContext ( ) )
37
+ }
38
+
39
+ init ( output: Data , context: SContext ) {
40
+ self . output = output
41
+ self . context = context
34
42
}
35
43
36
44
@discardableResult
@@ -44,4 +52,9 @@ internal class SEncoder: ScaleEncoder {
44
52
func write( _ data: Data ) {
45
53
output. append ( data)
46
54
}
55
+
56
+ func fork( full: Bool ) -> ScaleEncoder {
57
+ let out = full ? Data ( output) : Data ( )
58
+ return SEncoder ( output: out, context: SContext ( Array ( context. currentPath) ) )
59
+ }
47
60
}
You can’t perform that action at this time.
0 commit comments