Myprotosql
A set of mysql stored functions/procedures to read protobuf binary data
Getting started (with *.proto files)
See decode using .proto files for an example.
-
Download and install protoc
-
Install myprotosql (requires python):
pip install myprotosql
-
Run protoc with the myprotosql plugin (your
*.protofiles located in./proto, output in./build):protoc --proto_path=proto --myprotosql_out=build ./proto/*
-
Run the generated
install_myproto.sqlandmyproto_descriptors.sqlscripts in MySQL
If you used this proto file, you can now decode your first protobuf messageselect myproto_decode_to_textformat( 0x1a03089601, 'foo.bar.ParentMessage', myproto_descriptors());
Getting started (without *.proto files)
This is similar to protoc --decode_raw. See decode raw for an example.
-
Install myprotosql (requires python):
pip install myprotosql
-
Generate the install script
myprotosql-install-script > install_myproto.sql
-
Run the generated
install_myproto.sqlscript in MySQL
Decode your first protobuf message:select myproto_decode_to_textformat(0x1a03089601, null, null);
Alternative
Instead of using pip and python to install myprotosql, you can also just download the install_myproto.sql from the github repository and run that in MySQL.
Decoding
Running install_myproto.sql installs two functions that can be used to decode protobuf binary messages:
- myproto_decode_to_textformat(binary_message, message_type, type_descriptors)
- myproto_decode_to_jsonformat(binary_message, message_type, type_descriptors)
Decode raw
Decoding without the *.proto files
Textformat
decode_raw the 0x1a03089601 binary data to textformat:
select myproto_decode_to_textformat(0x1a03089601, null, null);
Returns:
3: {
1: 150
}
JSON
select myproto_decode_to_jsonformat(0x1a03089601, null, null);
Returns:
{"3": {"1": 150}}
Decode using .proto files
Let's say we have a .proto file like this:
package foo.bar;
message SubMessage {
optional int32 a = 1;
}
message ParentMessage {
optional SubMessage c = 3;
}
Check out Getting started (with *.proto files) to compile these *.proto files in something MySQL can understand.
Textformat
For example to decode the 0x1a03089601 binary data to textformat:
select myproto_decode_to_textformat(0x1a03089601, 'foo.bar.ParentMessage', myproto_descriptors());
Returns:
c: {
a: 150
}
JSON
select myproto_decode_to_jsonformat(0x1a03089601, 'foo.bar.ParentMessage', myproto_descriptors());
Returns:
{"c": {"a": 150}}
Troubleshooting
on Windows if you used Virtualenv
you need to specify the full path to the myprotosql plugin, like this:
protoc.exe --proto_path=proto --myprotosql_out=build --plugin=protoc-gen-myprotosql=.\venv\Scripts\protoc-gen-myprotosql.exe .\proto\*
This assumed your proto files are located in .\proto and your virtual env path is .\venv. In general the command is of the form:
protoc --proto_path=<the-path-to-your-proto-files> --myprotosql_out=<the-output-path> --plugin=protoc-gen-myprotosql=<the-path-to-the-myprotosql-plugin> <the-path-to-your-proto-files>\*
Limitations of decode_raw
Decode raw has limitations because protobuf binary data does not contain all info to properly decode the data.
- output will not contain field names, only field numbers
- packed repeated scalar values will be decoded as one binary string
- numbers will be decoded as unsigned integers
If you need proper decoding, then read on and learn how to use information in your *.proto files
Uninstalling
-
Generate the uninstall script
myprotosql-uninstall-script > uninstall_myproto.sql
-
Run the generated
uninstall_myproto.sqlscript in MySQL
Alternative
Download the uninstall_myproto.sql from the github repository and run that in MySQL.
Todo
- todos in code
Metadata
Release files for myprotosql 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| myprotosql-0.0.8.tar.gz | 39.0 kB | Without provenance | Details for myprotosql-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| myprotosql-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for myprotosql-0.0.8-py3-none-any.whl |
Total release size: 69.4 kB
Release files / myprotosql-0.0.8.tar.gz
| Download URL | myprotosql-0.0.8.tar.gz |
|---|---|
| Size | 39.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c27375572335eb0a0202c9fbcdacee386f156a794402ff6859370412763c36c
|
|
BLAKE2b-256 checksum How to use checksums |
8eec045cb186fbb1775beb0fbadfdb7f5c4e21d66e585c836c107210e3942c28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / myprotosql-0.0.8-py3-none-any.whl
| Download URL | myprotosql-0.0.8-py3-none-any.whl |
|---|---|
| Size | 30.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
685e35972b9f377a191e67b69ba8fbe39e24f9b3f3980c5a2f46d61c10461405
|
|
BLAKE2b-256 checksum How to use checksums |
e9e090af2fbc00ac13eb889df1c1c77dcf123c8db5fd128130e25493ca5c2f2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Security for myprotosql 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.