Re: Read/write integers?
David King <[email protected]>
| Newsgroups | gmane.mail.spam.crm114 |
|---|---|
| Message-ID | <[email protected]> |
> Say, what are you looking for, really? Functionality-wise? Because I
> don;t think you want this because you just love the way numbers look.
> ;-)
I have a bunch of database entries that I'm trying to classify. I have
a few hundred or thousand every minute or so, so I don't like the
rather expensive idea of spawning a new process for each entry, which
means that I need a wire-protocol between me and crm114 to delimit
beginning- and end-of-message.
At the moment, I've limited each entry to one line of text, delimited
by newlines ("window <bychunk> /\n/ /\n/"). That makes it relatively
easy to communicate with crm114 just by "print line into pipe, read
line". (And it works very well!) However, given the line-length limit
imposed by crm114 (on my 32-bit machine, crm114 will crash if I feed
it lines longer than 4k, and on my 64-bit machine, it crashes on lines
longer than 1k; probably libreadline or somesuch's fault), that means
that for longer entries, I can only classify based on the first ~1k of
the message, which isn't ideal, and keeps me from adding some of the
more interesting tokens from our database, as they could be quite long.
I'm trying to communicate with crm114 via Erlang, which has two easy
in-built ways to communicate with external programs via pipes. One
line-based, which is what I'm using, and one using length-encoded
"packets" (the {packet,4} option to erlang:open_port/2). It prints the
length of the message, then the message, then reads four bytes for the
length of the incoming message, and reads that many bytes. Insta-wire-
protocol.
Since it's not possible for crm114 to parse or generate the length-
header (although it looks like the rest of the bits are there, like
reading N bytes, and finding the length of a message), my options are
to either just continue to use the one-line messages, or to actually
write up a wire-protocol. I was just hoping to get one for free :)
> [1] interesting little challenge before I leave. :-) I'm fed up
> debugging my Javascript stuff now anyway...
Let me know. I'd use it :) If one could pull the ordinal value of a
character, it would be easy to multiply to combine several and get a
representation of the integer value (taking endianness into account as
appropriate)
It also seems like something pretty easy to add to crm114, but
probably not one that would see much wide use, and is therefore
probably not worth it.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone