I upgraded ksv to get support for opaque types and with it came a changed interaction with ksc, the new ksc-json-output is used now. This leads to compile time errors in ksv for me, because your generated JSON doesn't seem to handle paths and their different representation in Java under different OS correctly.
C:/[...]/visualizer_main.rb:68:in block (2 levels) in compile_formats': undefined method []' for nil:NilClass (NoMethodError)
from C:/Program Files (x86)/kaitai_struct/visualizer/lib/kaitai/struct/visualizer/visualizer_main.rb:64:in each' from C:/Program Files (x86)/kaitai_struct/visualizer/lib/kaitai/struct/visualizer/visualizer_main.rb:64:in each_with_index'
from C:/Program Files (x86)/kaitai_struct/visualizer/lib/kaitai/struct/visualizer/visualizer_main.rb:64:in `block in compile_formats'
fns.each_with_index { |fn, idx|
puts "... processing #{fn} #{idx}"
log_fn = log[fn]
if log_fn['errors']
{"record\fmt_clt_recs.ksy": {"firstSpecName": "fmt_clt_recs","output": {"ruby": {"fmt_clt_recs": {"topLevelName": "FmtCltRecs","files": [{"fileName": "fmt_clt_recs.rb"}]},"fmt_oms_rec": {"topLevelName": "FmtOmsRec","files": [{"fileName": "fmt_oms_rec.rb"}]}}}},"record\fmt_oms_rec.ksy": {"firstSpecName": "fmt_oms_rec","output": {"ruby": {"fmt_oms_rec": {"topLevelName": "FmtOmsRec","files": [{"fileName": "fmt_oms_rec.rb"}]}}}}}
There are two problems here:
- / to \
I use a command line similar to the following in Eclipse to start ksv:
[...]ksv "${workspace_loc}/[...]/data.bin" "record/fmt_clt_recs.ksy" "record/fmt_oms_rec.ksy"
With the current ksc this leads to \ instead of / in the generated JSON object, because Java internally uses a platform dependent path separator most of the times. The problem is that ksv sees / itself and can't find its own paths in the JSON anymore. I used / in favour of \ simply because I had trouble using \ in the past and / seems to be more common in Ruby, this would work on non-Windows etc.
- Improper escaping of \
\ needs to be escaped in JSON, that's why changing / to \ in my invocation above doesn't fix the problem: JSON contains \f in the end instead of \\f which is what Ruby internally would have as the String key.
In my opinion, the best thing to do is simply to not generate \ in JSON at all, so that only one normalized path separator is used across platforms and languages:
// FIXME: do proper string handling
def stringToJson(str: String): String =
"\"%s\"".format(str.replaceAll("\\\\", "/"))
This is somewhat hacky as well of course, but fixes the escape problem and makes interacting with ksv easier.
I upgraded
ksvto get support for opaque types and with it came a changed interaction withksc, the newksc-json-outputis used now. This leads to compile time errors inksvfor me, because your generated JSON doesn't seem to handle paths and their different representation in Java under different OS correctly.{"record\fmt_clt_recs.ksy": {"firstSpecName": "fmt_clt_recs","output": {"ruby": {"fmt_clt_recs": {"topLevelName": "FmtCltRecs","files": [{"fileName": "fmt_clt_recs.rb"}]},"fmt_oms_rec": {"topLevelName": "FmtOmsRec","files": [{"fileName": "fmt_oms_rec.rb"}]}}}},"record\fmt_oms_rec.ksy": {"firstSpecName": "fmt_oms_rec","output": {"ruby": {"fmt_oms_rec": {"topLevelName": "FmtOmsRec","files": [{"fileName": "fmt_oms_rec.rb"}]}}}}}There are two problems here:
I use a command line similar to the following in Eclipse to start
ksv:With the current
kscthis leads to\instead of/in the generated JSON object, because Java internally uses a platform dependent path separator most of the times. The problem is thatksvsees/itself and can't find its own paths in the JSON anymore. I used/in favour of\simply because I had trouble using\in the past and/seems to be more common in Ruby, this would work on non-Windows etc.\needs to be escaped in JSON, that's why changing/to\in my invocation above doesn't fix the problem: JSON contains\fin the end instead of\\fwhich is what Ruby internally would have as the String key.In my opinion, the best thing to do is simply to not generate
\in JSON at all, so that only one normalized path separator is used across platforms and languages:This is somewhat hacky as well of course, but fixes the escape problem and makes interacting with
ksveasier.