namedstruct


Namenamedstruct JSON
Version 1.2.3 PyPI version JSON
download
home_pagehttps://github.com/barry-scott/namedstruct
Summarynamedstruct encapsulates struct.unpack() with results accessed by name
upload_time2020-04-20 10:25:02
maintainer
docs_urlNone
authorBarry Scott
requires_python
licenseApache 2.0
keywords development
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Module namedstruct
------------------

namedstruct encapsulates struct.unpack() and struct.pack() with results accessed by name.

Classes
-------

  class namedstruct.namedstruct

    __init__( description, struct_definition )

        The *description* is used to title a dump of unpacked data.

        *struct_definition* is a single string that defines the type and name of each field
        as a space seperated list.
        Each field's type and name are seperated by a ":". If the name is left blank that
        field cannot be accessed by name, useful
        for padding fields. If a field's type has a repeat count the value returned with
        be a tuple of all the fields parts.

    len()

        Returns the size of the struct.

    unpack( bytes )

        Unpack the *bytes* into a namestruct.namestructresults object used to access the decoded fields.

    packer( from_unpacked=None )

        Return a namedstructpacker object that can be used to pack the fields into a buffer.
        The optional from_unpacked will initialise the fields from a previously unpacked
        buffer.

  class namedstruct.namedstructresults

    .*name*

       Returns the value of the field called name.

    dump( writer )

       Using the writer function to output a formatted dump of the whole struct.

  class namedstruct.namedstructpacker

    .*name* = value

        Assign a value to the named field

    init_from( from_unpacked )

        Assign each field from a previous unpacked buffer's namedstructresults.

    pack()

        Pack the fields and return the bytes buffer.

Example
-------

::

  import namedstruct

  # Windows EXE files start with a DOS header
  struct_windows_exe_header = namedstruct.namedstruct( 'DOS header', '<'
    '2s:dos_magic '
    'h:lastsize '
    'h:nblocks '
    'h:nreloc '
    'h:hdrsize '
    'h:minalloc '
    'h:maxalloc '
    'H:ss '
    'H:sp '
    'h:checksum '
    'H:ip '
    'H:cs '
    'h:relocpos '
    'h:noverlay '
    '4H:reserved1 '
    'h:oem_id '
    'h:oem_info '
    '10H:reserved2 '
    'L:pe_offset'
    )

  dos_image = open( 'c:\\windows\\system32\\cmd.exe', 'rb' ).read()
  header = struct_windows_exe_header.unpack( dos_image[0:len(struct_windows_exe_header)] )

  if debug:
    header.dump( print )

  print( 'dos_magic %r' % (header.dos_magic,) )
  print( 'PE header offer: 0x%8.8x' % (header.pe_offset,) )




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/barry-scott/namedstruct",
    "name": "namedstruct",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "development",
    "author": "Barry Scott",
    "author_email": "barry@barrys-emacs.org",
    "download_url": "https://files.pythonhosted.org/packages/b6/46/adde3edd7992f1726704d19824725359185538ddef256c1be059b6e163d0/namedstruct-1.2.3.tar.gz",
    "platform": "",
    "description": "Module namedstruct\n------------------\n\nnamedstruct encapsulates struct.unpack() and struct.pack() with results accessed by name.\n\nClasses\n-------\n\n  class namedstruct.namedstruct\n\n    __init__( description, struct_definition )\n\n        The *description* is used to title a dump of unpacked data.\n\n        *struct_definition* is a single string that defines the type and name of each field\n        as a space seperated list.\n        Each field's type and name are seperated by a \":\". If the name is left blank that\n        field cannot be accessed by name, useful\n        for padding fields. If a field's type has a repeat count the value returned with\n        be a tuple of all the fields parts.\n\n    len()\n\n        Returns the size of the struct.\n\n    unpack( bytes )\n\n        Unpack the *bytes* into a namestruct.namestructresults object used to access the decoded fields.\n\n    packer( from_unpacked=None )\n\n        Return a namedstructpacker object that can be used to pack the fields into a buffer.\n        The optional from_unpacked will initialise the fields from a previously unpacked\n        buffer.\n\n  class namedstruct.namedstructresults\n\n    .*name*\n\n       Returns the value of the field called name.\n\n    dump( writer )\n\n       Using the writer function to output a formatted dump of the whole struct.\n\n  class namedstruct.namedstructpacker\n\n    .*name* = value\n\n        Assign a value to the named field\n\n    init_from( from_unpacked )\n\n        Assign each field from a previous unpacked buffer's namedstructresults.\n\n    pack()\n\n        Pack the fields and return the bytes buffer.\n\nExample\n-------\n\n::\n\n  import namedstruct\n\n  # Windows EXE files start with a DOS header\n  struct_windows_exe_header = namedstruct.namedstruct( 'DOS header', '<'\n    '2s:dos_magic '\n    'h:lastsize '\n    'h:nblocks '\n    'h:nreloc '\n    'h:hdrsize '\n    'h:minalloc '\n    'h:maxalloc '\n    'H:ss '\n    'H:sp '\n    'h:checksum '\n    'H:ip '\n    'H:cs '\n    'h:relocpos '\n    'h:noverlay '\n    '4H:reserved1 '\n    'h:oem_id '\n    'h:oem_info '\n    '10H:reserved2 '\n    'L:pe_offset'\n    )\n\n  dos_image = open( 'c:\\\\windows\\\\system32\\\\cmd.exe', 'rb' ).read()\n  header = struct_windows_exe_header.unpack( dos_image[0:len(struct_windows_exe_header)] )\n\n  if debug:\n    header.dump( print )\n\n  print( 'dos_magic %r' % (header.dos_magic,) )\n  print( 'PE header offer: 0x%8.8x' % (header.pe_offset,) )\n\n\n\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "namedstruct encapsulates struct.unpack() with results accessed by name",
    "version": "1.2.3",
    "split_keywords": [
        "development"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "60baad8f9781b68b80303d501ab66b2d",
                "sha256": "a0b89de3b1d5631758dbb7e11976ddbb83f5fe3e9e7562b2214e4fe357c14a15"
            },
            "downloads": -1,
            "filename": "namedstruct-1.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "60baad8f9781b68b80303d501ab66b2d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8401,
            "upload_time": "2020-04-20T10:25:00",
            "upload_time_iso_8601": "2020-04-20T10:25:00.858020Z",
            "url": "https://files.pythonhosted.org/packages/18/9e/fcedff38fd21fce022c88d7a2d6270f7f566755e1455de3de9d6072e3a57/namedstruct-1.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "114637771c6d054e8868e7d61c40d934",
                "sha256": "f466378bea6f185e52c38054b91e585bfab7b0f619f8021de97788891e547ad1"
            },
            "downloads": -1,
            "filename": "namedstruct-1.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "114637771c6d054e8868e7d61c40d934",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8872,
            "upload_time": "2020-04-20T10:25:02",
            "upload_time_iso_8601": "2020-04-20T10:25:02.319167Z",
            "url": "https://files.pythonhosted.org/packages/b6/46/adde3edd7992f1726704d19824725359185538ddef256c1be059b6e163d0/namedstruct-1.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-04-20 10:25:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "barry-scott",
    "github_project": "namedstruct",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "namedstruct"
}
        
Elapsed time: 0.02739s