Skip to content

feat/fix: support literal and single-quoted style for YAML::Binary emitting#1447

Merged
SGSSGene merged 3 commits into
jbeder:masterfrom
sxrzh:fix1287-styles
Jul 3, 2026
Merged

feat/fix: support literal and single-quoted style for YAML::Binary emitting#1447
SGSSGene merged 3 commits into
jbeder:masterfrom
sxrzh:fix1287-styles

Conversation

@sxrzh

@sxrzh sxrzh commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #1445 and a part of issue #1287.
Support literal and single-quoted style for YAML::Binary emitting. Attempts to support plain form may change the default behavior, so are not applied.
Related tests are added to EmitterTest.BinaryStyles in test/integration/emitter_test.cpp.

@sxrzh

sxrzh commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

I also implemented the line wrapping as mentioned in #1287, should I commit it here or open another PR?

@SGSSGene SGSSGene left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for this PR!

There are two concerns:

  1. The code that does the switching is hard to read and check for correctness. Some (non-trivial) comments could be helpful.
  2. Why does the indentation for pointing float type change?

Comment thread src/emitter.cpp
m_pState->CurIndent() + m_pState->GetIndent());
break;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you add some comment for this block, what actually is happening?
Why do you format create a format string for "a"?
And why is there a case for case StringFormat::Plain that is commented out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

About "a":
Just like Emitter::Write for const char*, we should use ComputeStringFormat to generate StringFormat. And I also thought it necessary to offer functions like WriteSingleQuotedBinary and WriteLiteralBinary in Utils and call them, rather than directly generating base64 and calling Utils functions for strings. However, ComputeStringFormat indeed requires a string, but the base64 string is not generated in Emitter::Write! If we encode twice, it may cost double the time with long binary.
In fact ComputeStringFormat returns the same value for any non-empty base64 string and a, so I just passed a for all non-empty Binary.
Maybe adding a ComputeBinaryFormat will look better?

About Plain
Previously, without any options, the strFormat remains Plain by default but emits double-quoted style for Binary. Some long-existing tests are also based on this. Changing the default behavior may also influence some downstream projects. So I left it unchanged (still double-quoted).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Best appreciation to you!

Comment on lines +1499 to +1500
"foo: .inf\n"
"bar: .inf");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you explain why the indentation of these change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This may be caused by clang-format. Previously this case used tab for indentation and the formatter changed it to spaces.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This may be caused by clang-format. Previously this case used tab for indentation and the formatter changed it to spaces.

Ah yes! than just leave the fix in. I just noticed other PRs have the same change.

@SGSSGene

SGSSGene commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

I also implemented the line wrapping as mentioned in #1287, should I commit it here or open another PR?

Hey, a second PR for #1287 would be appreciated.

@sxrzh

sxrzh commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Now it may look better.
I'll soon submit another PR after this one is merged.
:)

@SGSSGene

SGSSGene commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Now it may look better. I'll soon submit another PR after this one is merged. :)

This I find much easier to follow and read. Thank you!

@SGSSGene SGSSGene self-requested a review July 3, 2026 07:38
@SGSSGene SGSSGene merged commit ee52744 into jbeder:master Jul 3, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No way to emit YAML::Binary in literal, single-quoted or plain form.

2 participants