Add TypeScript, Python, and PHP code generators#1094
Open
pcriadoperez wants to merge 13 commits intoaeron-io:masterfrom
Open
Add TypeScript, Python, and PHP code generators#1094pcriadoperez wants to merge 13 commits intoaeron-io:masterfrom
pcriadoperez wants to merge 13 commits intoaeron-io:masterfrom
Conversation
| final String compositeName, | ||
| final List<Token> tokens) | ||
| { | ||
| final String byteOrder = ir.byteOrder() == ByteOrder.LITTLE_ENDIAN ? "<" : ">"; |
Check notice
Code scanning / CodeQL
Unread local variable Note
| final List<Token> groups, | ||
| final List<Token> varData) | ||
| { | ||
| final String byteOrder = ir.byteOrder() == ByteOrder.LITTLE_ENDIAN ? "<" : ">"; |
Check notice
Code scanning / CodeQL
Unread local variable Note
…N_FIELD The composite decoder used Generators.forEachField() which only matches Signal.BEGIN_FIELD tokens, but composite type inner tokens use Signal.ENCODING. This produced empty interfaces and wrong ENCODED_LENGTH (e.g., MessageHeader had ENCODED_LENGTH=2 instead of 8), causing all subsequent field reads to be offset by 6 bytes. Rewrite generateCompositeDecoder() to iterate tokens checking for Signal.ENCODING, matching the pattern already used by the Python and PHP generators. Pass encodedLength as a parameter from the composite token. Regenerated all TypeScript output from the Binance schema.
Three fixes to the TypeScript code generator:
1. Nested groups and vardata inside groups were silently dropped.
generateGroupInterfaces() and generateGroupDecoderMethods() only used
Generators.forEachField() which skips BEGIN_GROUP and BEGIN_VAR_DATA
tokens. Rewrote both to use collectFields/collectGroups/collectVarData
on the group body with recursive handling of nested groups, matching
the pattern used by the Go generator.
2. Var data length type was hardcoded as uint32. Replaced shared helper
methods (decodeVarData, decodeVarStringUtf8, decodeVarStringAscii)
with inline decode that reads the actual length type from schema
tokens via Generators.findFirst("length", ...).
3. Message interface character encoding detection used the BEGIN_VAR_DATA
token which doesn't carry characterEncoding. Changed to use
Generators.findFirst("varData", ...) to read from the inner composite
token, fixing type mismatches (e.g. ErrorResponse.msg was Uint8Array,
now correctly string).
…coding into add-languages
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds SBE code generators for three new target languages: TypeScript, Python, and PHP.
Each generator follows the same architecture as the existing generators (Java, C++, Rust, etc.) and plugs into the standard SBE tool pipeline via
TargetCodeGeneratorLoader.What's included
structmodule for binary serialization, with type hints. Supports a keyword append token (-Dsbe.keyword.append.token=_) for schemas containing Python reserved words.pack()/unpack()for binary serialization, with union types and typed properties.TargetCodeGeneratorLoaderto registerPYTHON,PHP, andTYPESCRIPTtargets.Generator files
Each language follows the same structure under
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/{language}/:{Language}Generator.java— main code generation logic{Language}OutputManager.java— file output management{Language}Util.java— language-specific utilities (type mapping, keyword handling, etc.)How to test
1. Build the SBE tool
2. Generate codecs from a schema
3. Run the included test scripts
These scripts encode and decode a simple Order message and verify round-trip correctness.
4. Test with the existing SBE test schemas
You can also generate code against the test schemas bundled in the repo to verify more complex scenarios (groups, vardata, composites, enums):
5. Verify existing tests still pass
./gradlew test