Skip to content
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

parser pull: Add support for reusing parser #220

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

DmitryPogrebnoy
Copy link
Contributor

@DmitryPogrebnoy DmitryPogrebnoy commented Oct 30, 2024

GitHub: Fix GH-214

This is for parsing XML documents stream. We can use one parser to parse multiple XML documents with this feature.

@kou
Copy link
Member

kou commented Nov 6, 2024

@naitoh Do you want to review this?

@kou kou changed the title #214 Introduce reset option to PullParser parser pull: Add support for reusing parser Nov 6, 2024
@naitoh
Copy link
Contributor

naitoh commented Nov 6, 2024

Do you want to review this?

Looks good to me.

"<message>Third valid and complete message</message>"
]

reader, writer = IO.pipe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use IO.pipe do |reader, writer| ... instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

messages = []
while parser.has_next?
start_event = parser.pull
if start_event.start_element? and start_event[0] == 'message'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need start_element? check?

Can we simplify this like the following?

_message_start = parser.pull
message_text = parser.pull
messages << message_text[0]
_message_end = parser.pull
parser.reset

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we don't need these checks in tests because we know our test example. Fixed.

@DmitryPogrebnoy DmitryPogrebnoy requested a review from kou November 7, 2024 19:14
@kou kou merged commit 20562ec into ruby:master Nov 8, 2024
61 checks passed
@kou
Copy link
Member

kou commented Nov 8, 2024

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Can't use PullParser to parse several valid messages in a row
3 participants