Support schema-on-read for PrimitiveWeaver.intWeaver#106
Merged
Conversation
Co-authored-by: xerial <57538+xerial@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Support schema-on-read for PrimitiveWeaver.intWeaver
Support schema-on-read for PrimitiveWeaver.intWeaver
May 30, 2025
xerial
reviewed
May 30, 2025
| case ValueType.NIL => | ||
| try | ||
| u.unpackNil | ||
| context.setInt(0) |
Contributor
Author
There was a problem hiding this comment.
Updated to use context.setNull instead of context.setInt(0) for NIL values. This is more semantically correct as NIL represents absence of value rather than explicit zero. The functional behavior remains the same (NIL → 0) since null.asInstanceOf[Int] returns 0 in Scala. (578b981)
xerial
reviewed
May 30, 2025
| case e: Exception => | ||
| context.setError(e) | ||
| case other => | ||
| context.setError(new IllegalArgumentException(s"Cannot convert ${other} to Int")) |
Member
There was a problem hiding this comment.
For unknown valuse, we also need to call skipValue of the unpacker to proceed the cursor
Contributor
Author
There was a problem hiding this comment.
Added u.skipValue call before setting error for unknown value types to properly advance the unpacker cursor. (eeea193)
…xerial Co-authored-by: xerial <57538+xerial@users.noreply.github.com>
…acker cursor Co-authored-by: xerial <57538+xerial@users.noreply.github.com>
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.
This PR implements schema-on-read capability for
PrimitiveWeaver.intWeaver, enabling flexible type conversions from various MessagePack types to Int, similar to airframe-codec functionality.Changes
Enhanced
intWeaver.unpackmethod to support:Before:
After:
Testing
Added comprehensive test suite (
PrimitiveWeaverTest) with 9 test cases covering:All existing tests continue to pass, ensuring backward compatibility.
Impact
Fixes #105.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.