I'm parsing a stream of delimited strings. The protocol specifies that the first string is an integer value indicating the type of the message, followed by some arbitrary number of delimited strings (determined by the message type.)
A message might be defined as:
Code: Select all
MESSAGE_TYPE: 1 (LOCATION-OVERVIEW)
string: name
integer: location-id
double: resource-rating
Code: Select all
1@Haymarket@[email protected]@1@Joliet@[email protected]@...
In a nutshell, instead of having code that does something like:
Code: Select all
(let ((token (parse-next-token my-stream))
(setf (slot-value obj 'resource-rating) (read-from-string token))))
Code: Select all
(let ((token (parse-next-token my-stream))
(setf (slot-value obj 'resource-rating) token))
Any pointers here are appreciated.
**Edit**
As a follow-up, I realize I can use (read-from-string) to get automatic conversion for many cases, but there is some strange behavior in the system that requires special handling. For instance, some messages have boolean fields where NULL=false and *anything*=true, while other messages have boolean fields where 0=false and *anything-else*=true, while yet others have 1=true, and *anything-else*=false.

Yes, bask in the horribleness, but that's what I'm stuck with.