Implement validation functions #4

Open
opened 2016-01-05 11:48:49 -06:00 by jpetso · 0 comments
jpetso commented 2016-01-05 11:48:49 -06:00 (Migrated from github.com)

Sometimes I'm not interested in actually decoding a base-N string into its binary form, I just want to know whether it's valid and then keep it as encoded string.

I was thinking that the current API makes this possible with an empty Result type that makes put() a no-op, one would merely watch for a parse_error being thrown. This could be wrapped in an API like this:

bool <codec>::valid(const T& encoded);
bool <codec>::valid(const [char|uint8_t]* encoded, size_t encoded_size);

It would also be nice if this method didn't throw internally, because that will hit gdb/lldb when listening for arbitrary throws. Given that, the decode() functions should probably expose more overloads that take a std::error_code and set that to an error, instead of throwing. This would also make it possible to use cppcodec entirely without RTTI internals.

Sometimes I'm not interested in actually decoding a base-N string into its binary form, I just want to know whether it's valid and then keep it as encoded string. I was thinking that the current API makes this possible with an empty `Result` type that makes `put()` a no-op, one would merely watch for a `parse_error` being thrown. This could be wrapped in an API like this: ``` bool <codec>::valid(const T& encoded); bool <codec>::valid(const [char|uint8_t]* encoded, size_t encoded_size); ``` It would also be nice if this method didn't throw internally, because that will hit gdb/lldb when listening for arbitrary throws. Given that, the `decode()` functions should probably expose more overloads that take a `std::error_code` and set that to an error, instead of throwing. This would also make it possible to use cppcodec entirely [without RTTI internals](https://monoinfinito.wordpress.com/2013/07/25/c-exceptions-under-the-hood-appendix-iii-rtti-and-exceptions-orthogonality/).
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-tplgy/cppcodec#4
No description provided.