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

Interface design of simple unified access to json, xml, yaml, ini, etc. #259

Merged
merged 12 commits into from
Dec 11, 2023

Conversation

lihuiba
Copy link
Collaborator

@lihuiba lihuiba commented Nov 17, 2023

with examples and tests to show the usage

Copy link
Collaborator

@Coldwings Coldwings left a comment

Choose a reason for hiding this comment

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

LGTM

@lihuiba lihuiba marked this pull request as ready for review December 4, 2023 13:03
common/stream.h Outdated
};

// read until EOF
ReadAll readall(size_t min_buf = 1024, size_t max_buf = 1024 * 1024 * 1024);
Copy link
Contributor

Choose a reason for hiding this comment

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

is the param 'min_buf' necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

in case that you want it start from, say, 1MB, to avoid some unnecessary realloc()

class RootNode;
struct NodeWrapper;

// the interface for internal implementations
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can it be concealed for internal use and not disclosed externally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No,because it's also the binary interface.

NodeWrapper get(size_t i) const {
IF_RET({_node->get(i)});
}
NodeWrapper get(str key) const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the result if the get operation fails?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

an NodeWrapper with nullptr pointer to node implementation

Copy link
Collaborator

Choose a reason for hiding this comment

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

This requires a clear explanation and instructions for use.

// even if they are equivalent in binary form.
Node* parse(char* text, size_t size, int flags);

inline Node* parse(IStream::ReadAll&& buf, int flags) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't the Node meant for internal use? How come it's being used by users here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

parse(...)->wrap()

// 3. returning a pointer (of Node) is more efficient than an object (of Document),
//    even if they are equivalent in binary form.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For users, it's a direct use after parsing, and calling wrap is a burden.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not a big problem

Copy link
Collaborator

Choose a reason for hiding this comment

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

It a problem. The returned NodeImpl* is not the type used by the user and users must first determine if the returned NodeImpl* is nullptr before calling wrap. it's best not to expose these to users.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

else return {};

// the interface for users
struct NodeWrapper {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For user use, it's better to be named as "Node". The original "Node" can be renamed to NodeBase or something else, and not be exposed externally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

@lihuiba lihuiba merged commit 194839d into alibaba:main Dec 11, 2023
7 checks passed
@lihuiba lihuiba deleted the SimpleDOM branch January 3, 2024 04:20
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.

4 participants