-
-
Notifications
You must be signed in to change notification settings - Fork 244
Support get/is_registered methods for serde #1122
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
base: master
Are you sure you want to change the base?
Conversation
|
||
// IsIDRegistered returns true if the given schema ID is registered and has | ||
// a decode function available. | ||
func (s *Serde) IsIDRegistered(id int) bool { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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.