Skip to main content

GPack is struct analog!

Project description

An analogue of Struct for python!!

Installing:

pip install gpack

Example usage:

import gpack 
gpack.setup()
"1234".pack("bi",2)

GPack replaces the python compiler for improved and convenient operation.

b - Big-Endian

l - Little-Endian

i - Int

I - Signed Int

s - String

o - Bool

n - Bytes

> - Big-endian

< - Little-endian

More usage:

test_data = [123, -123, "aboba", b"aboba", 1234, True, False, 321]
import gpack
gpack.setup()
packed = test_data.pack("bilIsniooi", 1, 1, 5, 10, 5, 1, 1, 2)

unpacked = packed.unpack("bi lI s n i o o i", 1, 1, 5, 10, 5, 1, 1, 2)
print(unpacked)

[123, -123, 'aboba', b'aboba\x00\x00\x00\x00\x00', 1234, True, False, 321]

You can use the spaces for ease of use

Format Specifiers with sizes

Numbers after formats specify sizes in bytes:

# Pack string (5 bytes) + int (4 bytes) + bool (1 byte)
packed = ["hello", 123, True].pack("s i o", 5, 4, 1)

# Unpack with same sizes
unpacked = packed.unpack("s i o", 5, 4, 1)

Also you can use without setup:

import gpack
gpack.pack([123],'i',1)
gpack.unpack(b'}','i',1)

You can use size inside arg 1:

import gpack
gpack.setup()
[123].pack("1i") # Pack 123 with unsinged int and size 1
[123].pack("i",1) # Pack 123 with unsinged int and size 1

To use from libs remove "gpack.setup()"

In latest version:

Fixed some bugs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpack-0.2.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpack-0.2.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file gpack-0.2.2.tar.gz.

File metadata

  • Download URL: gpack-0.2.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for gpack-0.2.2.tar.gz
Algorithm Hash digest
SHA256 f85f8de8bf5dee4ca04c6ad931e512848d0aa7c5709d835c5fb0e29bce4abd45
MD5 eb0e27e10b7df3aa61844396d4e23500
BLAKE2b-256 224c46977eb157b6ec2d21fa95221b869b5d153f0ced030d1fadae94d803ac55

See more details on using hashes here.

File details

Details for the file gpack-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: gpack-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for gpack-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 89b29a90fb8e56220046a586e07cc04d47e86128d4dcfd4a45a60a84d7dc0181
MD5 f208beb238467ac8f906cf52b6eed6f5
BLAKE2b-256 c90f693c1b4eda23ba69579b6f8ac503acbe8f11adf40b7a61b20893a3e4b81c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page