From: storm@cua.dk (Kim F. Storm)
Cc: emacs-devel@gnu.org
Subject: Re: struct.el -- a package to encode/decode binary data
Date: 19 Mar 2002 15:34:25 +0100 [thread overview]
Message-ID: <5xadt4d3ta.fsf@kfs2.cua.dk> (raw)
In-Reply-To: <Pine.SUN.3.91.1020319133840.17982G-100000@is>
Eli Zaretskii <eliz@is.elta.co.il> writes:
> [I think we should conduct this discussion on emacs-devel: it might be
> useful for others.]
I've CC:ed the list.
>
> On 19 Mar 2002, Kim F. Storm wrote:
>
> > I used string-make-unibyte because I was having a great many
> > difficulties with "struct-pack" generating what seems to be a bogus
> > string, i.e. if I used `length' on the result, it didn't even have the
> > expected length. So it didn't DTRT for me in this case.
>
> You would have to show fragments of Lisp for me to see what could be the
> problem.
>
> > I did manage to control that via the current buffer's coding system,
> > but that seemed to make pretty random results, depending on what
> > buffer I happened to eval the function in (e.g. my source buffer
> > vs. *scratch* vs. a process buffer).
>
> This seems to indicate that you forced Emacs to convert from unibyte to
> multibyte and back. When you do that, it uses the current defaults to
> guess what you mean as TRT. That's why I said we shouldn't stress this
> ad-hoc'ery too much--it's too fragile.
The problem probably was that I took some binary data from one buffer,
put it into a (multibyte) string, and then tried to unpack that string
in another buffer. It didn't work - probably because those buffers
had different coding systems.
Since I really wanted this to work on binary, byte-oriented data,
I thought unibyte would be the correct mantra for me to use (and
it does work for this purpose).
>
> > So I probably just have to warn users that this package will only work
> > on binary data if the current buffer's coding system is raw-text-unix.
>
> I don't understand this--when you read binary data, what other decoding
> can you possibly use in the buffer into which the data is read?
True. It just puzzles me why I always seem to run into problems when
emacs DTRT with this coding stuff. It *was* easier in the old days,
and my mind probably just can't cope with this "new" coding stuff :-)
> Why
> should users bother about what kind of buffer are you using behind the
> scenes to convert binary garbage into human-readable description? What
> am I missing?
In this scope, the `users' I was talking about are really `programmers'.
So `real users' definitely shouldn't bother -- and they will probably be
unaware of the existence of the struct.el package too.
>
> > To me it would make sense to have a coding system named `binary' which
> > would work across all platforms.
>
> `binary' _does_ work this way. My problem was not with the coding system
> you used, it was with the fact that you used unibyte strings. That's a
> different issue.
>
> > Besides setting the buffer's coding system, is there some other way to
> > ensure that I'll always *use* a coding system which ensures that
> > `(substring ... 4 5)' really does only take one *byte* from the
> > string?
>
> `substring' is a string operation. Your data is not text, so you
> should avoid string operations, I think. Again, it's hard to give
> specific advice without a specific example. In general, functions like
> char-after are much better.
My code is typically used in a network process filter, and in that
scope, the received (binary) data is delivered in a string, so yes, my
data isn't text, but it stored in a string...
In any case, I'll follow your advice and rely on using the proper
coding systems for the buffers and processes involved (and keep my
fingers crossed :-).
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/emacs-devel
next parent reply other threads:[~2002-03-19 14:34 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.SUN.3.91.1020319133840.17982G-100000@is>
2002-03-19 14:34 ` Kim F. Storm [this message]
2002-03-19 21:27 ` struct.el -- a package to encode/decode binary data Thien-Thi Nguyen
2002-03-21 9:04 ` Richard Stallman
2002-03-21 11:15 ` Eli Zaretskii
2002-03-21 13:31 ` Kim F. Storm
2002-03-21 14:56 ` Eli Zaretskii
2002-03-21 15:36 ` Kim F. Storm
2002-03-21 16:58 ` Stefan Monnier
2002-03-21 19:45 ` Eli Zaretskii
2002-03-22 1:05 ` Stefan Monnier
2002-03-22 11:04 ` Eli Zaretskii
2002-03-22 0:37 ` Miles Bader
2002-03-23 2:35 ` Richard Stallman
2002-03-21 16:53 ` Stefan Monnier
2002-03-23 2:36 ` Richard Stallman
2002-03-22 1:30 Kenichi Handa
-- strict thread matches above, loose matches on Subject: below --
2002-03-22 1:25 Kenichi Handa
2002-03-22 1:27 ` Stefan Monnier
2002-03-18 23:12 Kim F. Storm
2002-03-19 0:25 ` Miles Bader
2002-03-19 7:02 ` Eli Zaretskii
2002-03-19 12:34 ` Stefan Monnier
2002-03-19 14:38 ` Eli Zaretskii
2002-03-19 14:33 ` Luke Gorrie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5xadt4d3ta.fsf@kfs2.cua.dk \
--to=storm@cua.dk \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).