Repository navigation
Decode Pkl Bytes into interface values - #277
Merged
Merged
Conversation
Decoding a Bytes value into `any` (for example a property typed `Any`, or an element of a Dynamic or Listing<Any>) failed with "encountered unknown object code: 0x0f", because decodePklObject only handled Bytes when the target was a []byte. Decode it to []byte, the same Go type used for typed Bytes properties.
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.
Decoding a Pkl
Bytesvalue into an interface fails:decodeSlicehandlescodeByteswhen the target is[]byte, butdecodePklObject(used foranytargets) has no case for it. So aBytesvalue fails to decode wherever the Go type isany. That includes a property typedAny, elements of aListing<Any>, the members of aDynamic, andEvaluateExpressionintovar out any.To reproduce with real Pkl output, decode the committed
test_fixtures/msgpack/collections.pkl.msgpack(res14: Bytes = Bytes(1, 2, 3, 4, 255)) intoanywith no registered schema:This change decodes it to
[]byte, the same type used for typedBytesproperties.Testing: added a
TestDecoder_Decodecase ("should successfully decode interface with Pkl Bytes"). It fails onmainand passes with the fix.go vet ./pkl/is clean. Ingo test ./pkl/, the only failures are the tests that run thepklCLI, which I don't have installed locally, and the same tests fail onmain.Note: when the decoded value is
any, aBytesused as aSetelement orMapkey still can't be decoded, because[]byteis not a valid Go map key. With this change that case panics inreflect.SetMapIndexinstead of returning the error above. This is the same as what already happens onmainforSet { List() }intoany, so I left it out of scope.