Message flags - #275
Conversation
Added message flags to indicate a couple of states and have room for future ones. Since NatsMsg is a struct we must keep its size in check. Flags added as a byte allows us to define upto seven flags only adding one byte to the struct size.
|
I'm not sure that Flags is the right construct - it seems like this would mainly be used for identifying the The original suggestion was to use something like the StatusCodes class If we are trying to expose the defacto-standard "Code" header as a Status Code it should probably look something like this: Then we can get rid of all the booleans like: And if someone wants to check the status they can do: Or if they want to come up with their own message status codes, they could easily make thier own Status Codes constants and compare against those. |
That's fine but 503 might not always mean no-responders, it must have a more generic meaning I would've thought, no? hence the additional check for payload in below Go code? That's the reason I treated no-responders as a special case. In a lot of cases we have to check the status message as well as the code, in general.
I accepted that to not complicate the PR. Payload needs to be checked as well: We still need a way to identify an empty payload since using |
|
True, wherever we throw for No Responders we'd need the status code check + a message size check. Was that the main point of the flags - we have no way of telling if it was an empty message post-de-serialization? |
pretty much, I can't think of another way of flagging (no pun intended) the fact payload is empty. I didn't want to use a bool and waste space, then IsNoRespondersError flag was just an easy addition to that. |
|
My main hesitation is that we are copying a state of a condition that could be checked pre-de-serialziation and creating a struct field that persists post-de-serialization. It shouldn't be hard for the user to check to see if it is an empty message - they know what serializer they are using - most of the time they are probably just checking Should we instead be settings something like Likewise, for sentinel message checking, should we set something like And we could leave these fields out of the user-facing NatsMsg and handle before de-serailzation? |
problem is with some value types default doesn't mean empty payload e.g. number types. Also in generic methods like
This is a good idea but unfortunately because of channels we can only throw exceptions by ending the subscription. I think that would make subscriptions less flexible.
I think empty-payload is warranted because that information is effectively lost after serialization. I know checking for no-responders to me is not just another error and we should be pragmatic about it. But I get the argument against it. If you feel strongly about it maybe We could move that to an extension method? |
|
On the concept of throwing, I don't really feel that the 503 - No Responders (and similar errors) should throw unless the user specifically wants to. HttpResponseMessage (from HttpClient) in .NET for example doesn't throw on non-200 statuses, but in case the user want's to see if the call is a valid result, it has a |
|
Alternate approach in #277 |
I still think |
I agree that the library needs to know when a message payload is empty. But if all of those checks are performed pre-de-serialization, the library will never need to have that indicator on |
|
Closing in favor of #277 and not to stretch already too big |
Added message flags to indicate a couple of states and have room for future ones. Since NatsMsg is a struct we must keep its size in check. Flags added as a byte allows us to define upto seven flags only adding one byte to the struct size.