kaitai_struct icon indicating copy to clipboard operation
kaitai_struct copied to clipboard

GO: Serialization

Open yywing opened this issue 1 year ago • 3 comments

Following up #27 #1060

documented in https://doc.kaitai.io/serialization.html

branches:

  • https://github.com/kaitai-io/kaitai_struct_go_runtime/pull/28
  • https://github.com/kaitai-io/kaitai_struct_compiler/pull/261
    • base on https://github.com/kaitai-io/kaitai_struct_compiler/tree/serialization
  • https://github.com/kaitai-io/kaitai_struct_tests/pull/101
    • base on https://github.com/kaitai-io/kaitai_struct_tests/tree/serialization

yywing avatar Nov 22 '23 08:11 yywing

kaitai_struct_go_runtime:

  • [x] add more function for compiler, make go translator like other language.
    • [x] if case
    • [x] err resolve
  • [x] add function to support writer

kaitai_struct_compiler:

  • [x] rewrite go translator supoprt writer

yywing avatar Nov 22 '23 08:11 yywing

the changes we do:

  • kaitai_struct_go_runtime
  1. delete original reader and writer, and combined them into a new struct -> stream (like python and java's runtime)
  2. for go, add a new rws(read, write, seek) buffer struct
  3. for terminated string and bytes, add a new struct to describe them(util.go)
  • kaitai_stricuct_compiler
  1. splite common reader and common write into go reader and go writer (also works well for any other language)
  2. rewrite go translator to support writer
  3. complete functions in go compiler
  4. some type conversions are fixed(support go's interface{})
  5. clean up unuseful code generate

now we can use the compiler to generate go files which support serialize and unserialize

mashiro01 avatar Dec 25 '23 09:12 mashiro01

for terminated string and bytes, add a new struct to describe them

This change is used to calc length when write. We add this.SizeOf() to calc length of struct.

yywing avatar Dec 26 '23 08:12 yywing