-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialization #255
Open
GreyCat
wants to merge
105
commits into
master
Choose a base branch
from
serialization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Serialization #255
Changes from 97 commits
Commits
Show all changes
105 commits
Select commit
Hold shift + click to select a range
de0938e
Added --read-write switch
GreyCat d24a36d
JavaMain: ensure that exceptions are really thrown, even on compile s…
GreyCat 0b757b9
Started PoC seq writer support in JavaCompiler
GreyCat 93b37a1
JavaCompiler: very basic bytes writing support
GreyCat 75ec0c2
Allow simple serialization of FixedBytesType
GreyCat eed5d07
Translators: added strToBytes, implemented in Java translator
GreyCat 5cf4edd
Added _i iteration number identifier
GreyCat 4a3535f
JavaTranslator: added translation of `_i`
GreyCat 568964d
ClassTypeProvider: use constants + added ITERATOR_I handling
GreyCat 9e7bffa
Writing: added string handling, some repeat-expr handling, BytesEos h…
GreyCat 8fd1002
Serialization: basic support for user types and BytesLimitType
GreyCat 0d73de2
Merge branch 'master' into serialization
GreyCat ea06fec
Serialization: implemented unprocess and slightly better user type wr…
GreyCat 9c1793e
AllocateIOLocalVar: Added allocation of fixed and growing IOs
GreyCat 9f0e331
Serialization: implemented fixed-size preallocated IO buffers
GreyCat 969401c
JavaCompiler: generate new Readable/Writable interface implements
GreyCat 885469f
Serialization: more intricate process-on-top-of-user-type support
GreyCat 0f3a2aa
JavaCompiler: implemented writing of repeat-eos
GreyCat e4a56f1
Serialization: implemented switch types support, reworked JavaCompile…
GreyCat 44185e1
Added basic _check implementation, added checks for a proper number o…
GreyCat 769dabc
Added String#to_b(encoding) and ByteArray#size methods + JavaTranslat…
GreyCat 040b689
Added limited byte / string sizing checks
GreyCat 28e8d06
Translators: added BytesType#first and #last, implemented for Java
GreyCat 1b66897
GenericChecks: implemented tons of checks for BytesLimitType - bounda…
GreyCat 7d2295f
Merge branch 'master' into serialization
GreyCat dd0880e
Merge branch 'master' into serialization
GreyCat d73ec6b
JavaCompiler: only use ReadOnly when _read is public, i.e. when debug…
GreyCat 2081fb2
Merge branch 'master' into serialization
GreyCat 7dee284
Merge branch 'master' into serialization
GreyCat 75729f7
WIP
generalmimon 6e6bdda
Merge branch 'master' into serialization
generalmimon 9eb2ab5
Merge pull request #177 from generalmimon/serialization
GreyCat 2e2e985
Stop generating empty constructor when autoRead
generalmimon e46cc95
Use common loop for all repetitions
generalmimon 9d8f2d3
Merge pull request #182 from generalmimon/serialization-common-loop
GreyCat e4ad9aa
Revert "Stop generating empty constructor when autoRead"
generalmimon d8adcc5
Disable autoRead automatically in readWrite mode
generalmimon cfba0cc
Merge pull request #180 from generalmimon/serialization-autoread-empt…
GreyCat d26e37b
Extract changes from https://github.com/kaitai-io/kaitai_struct_compi…
generalmimon ead02a4
Merge tag '0.10' into serialization
generalmimon 5c70d8f
Fix build errors after upgrading to the 0.10 codebase
generalmimon 0867d51
Remove `FixedBytesType` as intended in the 0.9 `valid` design
generalmimon 939cf98
Refactor EveryWriteIsExpression to use Ast.expr.InternalName
generalmimon 83b1fa7
Delete unused attrFixedContentsParse (_io.ensure_fixed_contents())
generalmimon caea2b7
Fix writing of a field with `terminator` + `consume: false`
generalmimon c1d391a
Fix broken consistency check for repeated byte arrays
generalmimon 43d044a
Java: fix bytesSubscript to give unsigned byte values (finally!)
generalmimon 8404319
Drop `expr` argument of condIfFooter method
generalmimon 2acf924
Java: include term if `include: true` && `terminator` == `pad-right`
generalmimon 73b0347
Fix & add missing `terminator`/`pad-right` consistency checks
generalmimon d721d08
Reuse the byte array write method for strings
generalmimon 50d6556
Add repeat-until last element check
generalmimon 72ca925
Refactor access to the last array item in attrAssertUntilCond
generalmimon 426a38d
Merge pull request #183 from generalmimon/serialization-repeat-until-…
generalmimon def6650
Extend repeat-until consistency check to all elements
generalmimon 306bfb2
Add consistency check for *non-empty* `repeat: until` array
generalmimon 849fc1c
Fix "Object cannot be converted to byte[]" errors in type switches
generalmimon 74d553c
Fix locale-sensitive String#toUpperCase call in writeHeader
generalmimon 604359d
Java: finally solve boxed numeric type casting issues consistently
generalmimon f8bb577
Add _invalidate*() for value and set*() for parse instances
generalmimon 16374cc
Add _write*() and _check*() for parse instances
generalmimon 070391c
Set write flags of parse instances at the beginning of `_write`
generalmimon 9897818
_write(): use special loops for each repetition type again
generalmimon 69e4a12
Java: make {_read,_write}{BE,LE}() `private` even if autoRead is off
generalmimon 2710191
Fix instance write flags (previous attempt led to infinite recursion)
generalmimon 7dce0c3
Rename _write{,LE,BE}() methods to _write_Seq{,LE,BE}()
generalmimon 826b242
Rename {writeExprAsExpr=>itemExpr}(), move to EveryReadIsExpression
generalmimon ca012b6
Add _fetchInstances() method to recursively fetch parse instances
generalmimon 3b08efe
Write substreams to parent only after all fields have been written
generalmimon 544cad0
Add set{Inst}_ToWrite() setter to select what instances to write
generalmimon 11da92f
Add support for writing substreams with `process` and/or `terminator`
generalmimon 175c278
Fix handling `size-eos: true` with `terminator`/`pad-right`
generalmimon b5c2e92
Java: call writeBitsInt{Be,Le}(), disable calls to alignToByte()
generalmimon bda1842
Move consistency checks from _check() to _write() if needed
generalmimon a5dd1f9
Add a _write() check on EOF after a `size-eos: true` field
generalmimon ecb5757
Add a _write() check on EOF states of `repeat: eos`
generalmimon 37f432b
Generate byte array checks for substreams in _write()
generalmimon 4fdf21d
Add write support for `eos-error: false`
generalmimon a8e4c03
Convert Identifier to id in ConsistencyError using `humanReadable`
generalmimon 08ac809
Remove unused `isRaw` parameter in `itemExpr` method
generalmimon cf26f3e
Generate checks for SwitchType as well
generalmimon 37da6dd
Add checks for user `params`, set `io`/`io[]` params in _write()
generalmimon 2accf38
Add checks for `_root` and `_parent` built-in parameters
generalmimon 5afa962
Add `valid` checks as in _read() to _check()/_write()
generalmimon 793f58b
Add necessary fixes after testing on https://github.com/kaitai-io/kai…
generalmimon 533aaa8
Going forward, starting 0.11-SNAPSHOT
GreyCat 52812f9
Fix superfluous footer in Lua, Perl, PHP, Python and Ruby
generalmimon 203613b
Delete unused method attrWriteStreamToStream
generalmimon d1f16dd
Port serialization support to Python
generalmimon d986731
Fix Python 2 compatibility when creating a fixed stream
generalmimon fca43d9
Python: disable calls to alignToByte()
generalmimon e776c98
Python: use `self` as default `_root` only in top-level types
generalmimon 00c831f
Add "implies --no-auto-read" to --read-write CLI option description
generalmimon f1dc857
Add "Java and Python only" to --read-write CLI option description
generalmimon 952c89c
Merge branch 'master' into serialization
generalmimon 9142a1b
Improve setting `zeroCopySubstream` to false in `readWrite` mode
generalmimon 2eca3de
Bring back init of instance flags in non-`readWrite` mode (C++, C#)
generalmimon a477800
PythonCompiler: fix "{alignToByte => align_to_byte}()" in comment
generalmimon 8b258e2
Remove alignToByte() insertion logic when writing
generalmimon cb0c1eb
Endianness.fromString(): revert incorrect `case {None => _}` change
generalmimon 0179199
Stop using `_io` when throwing validation errors from _check()
generalmimon 31f1359
Merge branch 'master' into serialization
generalmimon 7d830fa
Fix Java 7 compat: add `final` in allocateIOFixed()
generalmimon dea74e1
Merge branch 'master' into serialization
generalmimon 4066d1e
Merge branch 'master' into serialization
generalmimon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to avoid using
var
and imperative.foldLeft
seems to do the trick here, cleanly conveying the semantics and allowing e.g. advanced parallelization of such loops:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, one of the major changes in Java and Python runtime libraries related to serialization was that all
alignToByte
insertion logic is handled in the runtime libraries themselves and thealignToByte()
call generation is disabled in the compiler for both Java and Python:kaitai_struct_compiler/shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala
Lines 497 to 500 in 2eca3de
kaitai_struct_compiler/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala
Lines 486 to 489 in 2eca3de
(and now I see a small mistake in the comment in
PythonCompiler
- technically it should be "the compiler does not need to outputalignToByte()align_to_byte()
" per Python naming)So I guess the piece of code you're reviewing can be simplified to just
lang.attrWrite(attr, attr.id, defEndian)
.