Repository navigation
Support every Skir serialization format - #2
Merged
Merged
Conversation
Add ReadableJson::encode() and ReadableJson::toJson(), matching the upstream skir-client toJson(value, "readable") and toJsonCode(value, "readable") output, including two-space indentation and JavaScript number formatting. DenseJson::decode() and DenseJson::fromJson() now accept both flavors and follow upstream fromJson coercion: unknown enum variants and names decode to UNKNOWN, constant/wrapper shape changes are tolerated, null structs decode to defaults, and invalid strings, bytes and int64 values are rejected. Dense encoding now wraps int32 values, clamps int64, hash64 and timestamp values and writes JSON the way JSON.stringify does. Type traversal is shared by an internal JsonCodec. Expected values in the tests were generated with the upstream skir-client package.
Add BinaryFormat::encode() and BinaryFormat::decode(), byte-for-byte compatible with the upstream skir-client toBytes() and fromBytes(), including the "skir" header, the variable-length number wires, the UTF-16 based string length prefix sizing, struct slot trimming and skipping of unrecognized struct slots and enum payloads. Expected bytes in the tests were generated with the upstream skir-client package.
Encoding cast them with (string), turning arrays into a PHP warning instead of a SkirRuntimeException.
This was referenced Nov 9, 2026
Merged
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.
Skir declares three serialization formats: dense JSON, readable JSON and binary. The runtime only had dense JSON. This PR adds the other two, byte-for-byte compatible with the upstream TypeScript runtime (
skir-client@1.0.22). Test vectors were generated by running upstream, not written by hand.New API
ReadableJson::encode()/ReadableJson::toJson(): readable JSON, formatted like upstream (2-space indent, unescaped unicode, JS number formatting).BinaryFormat::encode()/BinaryFormat::decode(): the binary format, including theskirheader.DenseJson::decode()/fromJson()now accept either JSON flavor, like upstreamfromJson.Behaviour now matching upstream (from a code review against the TS runtime)
UNKNOWNinstead of throwing, so adding a variant on the server no longer breaks PHP clients.nulldecodes to the default struct. Objects decode by field name.intwhen they fit and to a digit string otherwise; garbage is rejected. int32 wraps and 64-bit values clamp like upstream on encode.Known gaps vs upstream (PHP constraints)
json_decodecan't tell{"0":…}from a list.Type::structdoesn't keep declaration order.Shared logic lives in
src/Internal(@internal).Breaking (0.2.0): decoding is more permissive (enum evolution) and more strict (types).
Pairs with php-skir/server#2 and php-skir/client#2.