[issue27446] struct: allow per-item byte order

2017-03-25 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I concur with the other reviewers.  Am going to mark this as closed.

If the need arises, just make multiple struct unpacks.

--
nosy: +rhettinger
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27446] struct: allow per-item byte order

2017-03-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I concur with Martin.

--
nosy: +mark.dickinson, meador.inge, serhiy.storchaka
resolution:  -> rejected

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27446] struct: allow per-item byte order

2017-03-25 Thread Martin Panter

Martin Panter added the comment:

This seems too obscure to be worth supporting in the built-in library IMO. The 
use case loses one line of code but gains a more complicated structure format 
string.

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27446] struct: allow per-item byte order

2016-07-03 Thread Zack Weinberg

New submission from Zack Weinberg:

Occasionally one encounters binary formats which do not stick to one byte order 
throughout.  For example, I have a C program that reads and writes  arrays of 
this struct:

```
struct conn_data
{
  uint32_t ipv4_addr; /* read - network byte order - target IPv4 address */
  uint16_t tcp_port;  /* read - network byte order - target TCP port */
  uint16_t errnm; /* write - native byte order - errno code */
  uint64_t elapsed;   /* write - native byte order - elapsed time in ns */
};
```

On little-endian systems, the first and second fields of this struct will be in 
the opposite byte order from the third and fourth.

If the struct module allowed specification of byte order on a per-item basis, 
it would make working with structures of this type simpler.  Hypothetical 
notation:

```
addr, port, errnm, elapsed = struct.unpack("=4s!H=H=Q")
addr = socket.inet_ntoa(addr)
```

instead of what one must do now,

```
addr, port, errnm, elapsed = struct.unpack("=4sHHQ")
addr = socket.inet_ntoa(addr)
port = socket.ntohs(port)
```

To avoid ambiguities and confusion, I would suggest that, if more than one item 
has its own byte-order specifier, _all_ items must have byte-order specifiers 
(with the possible exception of the 1-byte item types?), and that this is not 
allowed in an '@'-mode format.

--
components: Library (Lib)
messages: 269770
nosy: zwol
priority: normal
severity: normal
status: open
title: struct: allow per-item byte order
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com