• Interpret bytes as packed binary data


    7.1. struct — Interpret bytes as packed binary data — Python 3.6.5 documentation https://docs.python.org/3/library/struct.html

    ource code: Lib/struct.py


    This module performs conversions between Python values and C structs represented as Python bytes objects. This can be used in handling binary data stored in files or from network connections, among other sources. It uses Format Strings as compact descriptions of the layout of the C structs and the intended conversion to/from Python values.

    Note

     

    By default, the result of packing a given C struct includes pad bytes in order to maintain proper alignment for the C types involved; similarly, alignment is taken into account when unpacking. This behavior is chosen so that the bytes of a packed struct correspond exactly to the layout in memory of the corresponding C struct. To handle platform-independent data formats or omit implicit pad bytes, use standard size and alignment instead of nativesize and alignment: see Byte Order, Size, and Alignment for details.

    Several struct functions (and methods of Struct) take a buffer argument. This refers to objects that implement theBuffer Protocol and provide either a readable or read-writable buffer. The most common types used for that purpose are bytes and bytearray, but many other types that can be viewed as an array of bytes implement the buffer protocol, so that they can be read/filled without additional copying from a bytes object.

  • 相关阅读:
    Nuget:aliyun-openapi-sdk
    iptables简述
    openOffice安装
    bash:command not found
    linux nc命令
    linux命令帮助
    linux用户管理
    LDAP 后缀操作
    LDAP缓存命令
    LDAP索引及缓存优化
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9146096.html
Copyright © 2020-2023  润新知