Skip to main content

A decoder for Google Maps protobuf format

Project description

deproto

A Python package for decoding and manipulating Google Maps protobuf format strings. This library allows you to decode, modify, and re-encode protobuf strings commonly found in Google Maps URLs and data structures.

Installation

Install using pip:

pip install deproto

Quick Start

from deproto import Protobuf

# Example protobuf string from Google Maps
pb_string = '!3m1!1e3!4m12!3m11!1s0x4795cd1c65280cb9:0xad3b34d7340adc02!5m3!1s2024-12-21!4m1!1i2!8m2!3d49.167174!4d7.22149!9m1!1b1'

# Create decoder instance
decoder = Protobuf(pb_string)

# Decode the string into a tree structure
cluster = decoder.decode()

# Print the tree structure
decoder.print_tree()

# Make changes to values
cluster[0][0].change('2024-12-21')

# Encode back to protobuf format
encoded = decoder.encode()

Features

  • Decode Google Maps protobuf strings into a tree structure
  • Modify the decoded structure
  • Encode the structure back to protobuf format
  • Print tree visualization of the structure
  • Support for various data types (int, float, string, etc.)

Tree Structure Visualization

The print_tree() method provides a clear visualization of the protobuf structure:

1m3
├── 3m1
│   └── 1e3
├── 4m12
│   └── 3m11
│       ├── 1s0x4795cd1c65280cb9:0xad3b34d7340adc02
│       ├── 5m3
│       │   └── 1s2024-12-21
│       └── ...

Supported Data Types

  • Bytes (B)
  • Boolean (b)
  • Double (d)
  • Enum (e)
  • Float (f)
  • Fixed32 (x)
  • Fixed64 (y)
  • Int32/64 (i)
  • SFixed32 (g)
  • SFixed64 (h)
  • SInt32 (n)
  • SInt64 (o)
  • String (s)
  • UInt32 (u)
  • UInt64 (v)
  • Base64String (z)

Tree Manipulation

# Access nodes using index
node = cluster[0][1]

# Change values
node.change("new_value")

# Delete nodes
cluster[1][0].delete(5)

# Insert nodes
from deproto import Node
from deproto.data_types import IntType
cluster.insert(4, Node(4, '42', IntType()))

State Management

# Reset to original state
decoder.reset()

Advanced Usage

Working with Clusters

Clusters are collections of nodes that can be manipulated as a group:

from deproto import Cluster, Node
from deproto.data_types import StringType

# Create a new cluster
cluster = Cluster(1, 2)

# Add nodes
cluster.append(Node(1, "value1", StringType()))
cluster.append(Node(3, "value2", StringType()))

# Insert at specific position
cluster.insert(2, Node(2, "inserted", StringType()))

Custom Data Type Handling

The package includes a DataTypeFactory for handling various protobuf data types:

from deproto.data_types import DataTypeFactory

# Get type handler
string_type = DataTypeFactory.get_type('s')  # StringType
int_type = DataTypeFactory.get_type('i')     # IntType

# Auto-detect type
value_type = DataTypeFactory.get_type_by_value("some string")  # Returns StringType

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Ijaz Ur Rahim (ijazurrahim.com | @MrDebugger)

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

deproto-0.1.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

deproto-0.1.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file deproto-0.1.1.tar.gz.

File metadata

  • Download URL: deproto-0.1.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for deproto-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f874d4edf4aa2080493a9eef1c7eb020a8dea65fde82949d4d048d344820e062
MD5 06027015ddb1e5a02db82c91ff18b119
BLAKE2b-256 e11c1c6f94597b710989c7a46910ac0d0ad3724446fefaa0df93b7596a432f34

See more details on using hashes here.

File details

Details for the file deproto-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: deproto-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for deproto-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 725471cc07efa767ba68ad3240a283b6fc98090b5f3cb5f001d37791cd6c9723
MD5 966c019fa0cc2dba47a9e350533980f0
BLAKE2b-256 935e824f7ed18619a96792a7776d9669c3b2f345a1fa475a3cca1c4a93d16ea8

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