+
Skip to content

Conversation

siller174
Copy link

@siller174 siller174 commented Oct 10, 2025

Dear maintainer.

As a Developer, I want to check if the schema is present or not. I added methods to do it.

I will be happy to hear your feedback and fix comments if you have any.


// IsIDRegistered returns true if the given schema ID is registered and has
// a decode function available.
func (s *Serde) IsIDRegistered(id int) bool {
Copy link
Owner

Choose a reason for hiding this comment

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

What's the need for this, when you have ForEncoding and ForDecoding below?

Copy link
Author

Choose a reason for hiding this comment

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

I want to check if we support schema or not before decoding, and if we do not support it, implement logic to get a new schema or something

Copy link
Owner

Choose a reason for hiding this comment

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

Given that, are the getters needed?

func (s *Serde) IsIDRegisteredForEncoding(id int) bool {
ids := s.loadIDs()
t := ids[id]
return t.exists
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't check if encode or appendEncode are non-nil?

// IsTypeRegistered returns true if the given type is registered and has
// an encode function available.
func (s *Serde) IsTypeRegistered(v any) bool {
t, ok := s.loadTypes()[reflect.TypeOf(v)]
Copy link
Owner

Choose a reason for hiding this comment

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

Since types are only used for encoding, is there any reason not to move this to checking just IsIDRegisteredForEncoding?

return ok && (t.encode != nil || t.appendEncode != nil)
}

// GetRegisteredIDs returns a slice of all registered schema IDs (for encoding).
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this specific to just encoding? Naming is inconsistent with the other getter.

return result
}

// GetRegisteredTypes returns a slice of all registered types.
Copy link
Owner

Choose a reason for hiding this comment

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

What's the need for this? This seems like some internal niche guts

Copy link
Author

Choose a reason for hiding this comment

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

Mainly, I need only IsIDRegistered and GetRegisteredIDs; this I implemented additionally

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.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载