@@ -42,12 +42,9 @@ type OutputDataPtr[T any] interface {
4242// It always caches results, and optionally reuses previously cached results.
4343func Run [Output any , OutputPtr OutputDataPtr [Output ]](cfg * Config ) (OutputPtr , error ) {
4444 if cfg .CacheFile != "" {
45- data , err := os . ReadFile (cfg .CacheFile )
45+ out , err := osutil. ReadJSON [ OutputPtr ] (cfg .CacheFile )
4646 if err == nil {
47- out , err := unmarshal [Output , OutputPtr ](data )
48- if err == nil {
49- return out , nil
50- }
47+ return out , nil
5148 }
5249 }
5350
@@ -111,7 +108,7 @@ func runTool[Output any, OutputPtr OutputDataPtr[Output]](cfg *Config, dbFile, f
111108 }
112109 return nil , err
113110 }
114- out , err := unmarshal [ Output , OutputPtr ](data )
111+ out , err := osutil. ParseJSON [ OutputPtr ](data )
115112 if err != nil {
116113 return nil , err
117114 }
@@ -127,16 +124,6 @@ func runTool[Output any, OutputPtr OutputDataPtr[Output]](cfg *Config, dbFile, f
127124 return out , nil
128125}
129126
130- func unmarshal [Output any , OutputPtr OutputDataPtr [Output ]](data []byte ) (OutputPtr , error ) {
131- dec := json .NewDecoder (bytes .NewReader (data ))
132- dec .DisallowUnknownFields ()
133- out := OutputPtr (new (Output ))
134- if err := dec .Decode (out ); err != nil {
135- return nil , fmt .Errorf ("failed to unmarshal clang tool output: %w\n %s" , err , data )
136- }
137- return out , nil
138- }
139-
140127type compileCommand struct {
141128 Command string
142129 Directory string
0 commit comments