Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96921
| References | <CAPTjJmpuYp5uEDnRJqC9qKj-YkNRx1jW48WsRyRn+U0rzGiTYw@mail.gmail.com> <20150921062713.GA77399@cskk.homeip.net> |
|---|---|
| Date | 2015-09-21 17:57 +1000 |
| Subject | Re: Lightwight socket IO wrapper |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.23.1442822248.28679.python-list@python.org> (permalink) |
On Mon, Sep 21, 2015 at 4:27 PM, Cameron Simpson <cs@zip.com.au> wrote: > I don't like embedding arbitrary size limits in protocols or data formats if > I can easily avoid it. So (for my home grown binary protocols) I encode > unsigned integers as big endian octets with the top bit meaning "another > octet follows" and the bottom 7 bits going to the value. So my packets look > like: > > encoded(length)data > > For sizes below 128, one byte of length. For sizes 128-16383, two bytes. And > so on. Compact yet unbounded. Ah, the MIDI Variable-Length Integer. Decent. It's generally a lot faster to do a read(2) than a loop with any number of read(1), and you get some kind of bound on your allocations. Whether that's important to you or not is another question, but certainly your chosen encoding is a good way of allowing arbitrary integer values. ChrisA
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Lightwight socket IO wrapper Chris Angelico <rosuav@gmail.com> - 2015-09-21 17:57 +1000
Re: Lightwight socket IO wrapper Marko Rauhamaa <marko@pacujo.net> - 2015-09-21 10:59 +0300
Re: Lightwight socket IO wrapper Chris Angelico <rosuav@gmail.com> - 2015-09-21 18:07 +1000
Re: Lightwight socket IO wrapper Marko Rauhamaa <marko@pacujo.net> - 2015-09-21 11:38 +0300
Re: Lightwight socket IO wrapper Chris Angelico <rosuav@gmail.com> - 2015-09-21 18:45 +1000
Re: Lightwight socket IO wrapper Marko Rauhamaa <marko@pacujo.net> - 2015-09-21 11:48 +0300
Re: Lightwight socket IO wrapper Marko Rauhamaa <marko@pacujo.net> - 2015-09-21 11:49 +0300
Re: Lightwight socket IO wrapper Chris Angelico <rosuav@gmail.com> - 2015-09-21 18:50 +1000
Re: Lightwight socket IO wrapper Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-09-22 07:59 +0000
csiph-web