Protocol buffers are supported in Charles
Original address:
Original author:
Published: 19 September 2020 -3 minutes to read
I use Charles almost exclusively for all my network debugging needs. From debugging unreleased apis to testing slow Internet throttling scenarios, it has been my web genie, my brother as I sniff out network calls made by repackaged mobile apps. It has proven itself to be a reliable tool that has stood the test of time until I came across Google’s protocol buffer.
I was greeted with this disgusting view. As a developer, I understand all the benefits of protobuf being a binary protocol, but this is one of the biggest downsides. It can’t be read by humans, making it one of the most difficult protocols to use when debugging things.
Thankfully, Charles has built-in Support for Protobuf, which can help us solve this problem and end up with a readable output that can be understood by mere mortals. This article describes how to set up Charles to understand Protobuf responses.
Prepare the potions
Protobuf descriptor
Descriptors essentially contain the same information as in.proto files, and their types make this information accessible in other tools and programmable languages.
Let’s work with a simple Protobuf file
syntax = "proto3";
option java_package = "com.example.protobuf";
message Response {
int32 id = 1;
string label = 2;
}
Copy the code
My chosen working language is Java and Gradle build system. To generate this combined descriptor file, the following changes must be made to the build.gradle file. You can find documentation for other languages here.
protobuf {
...
generateProtoTasks {
all().each { task ->
...
task.generateDescriptorSet = true
task.descriptorSetOptions.path = ...
task.descriptorSetOptions.includeSourceInfo = true
task.descriptorSetOptions.includeImports = true}}}Copy the code
- GenerateDescriptorSet Generates a descriptor set file. The default file name is descriptor_set.desc.
- Generated descriptorSetOptions. Path specified descriptor file paths. The default value is generatedFilesBaseDir/generatedFilesBaseDir/generatedFilesBaseDir/sourceSet.
- DescriptorSetOptions. IncludeSourceInfo descriptor set will contain the line number information and comments.
- DescriptorSetOptions. IncludeImports descriptor set will contain all the escape of the import, so is sufficient.
Now run
./gradlew clean build
Copy the code
If you use the default value is running, you should be in generatedFilesBaseDir/generatedFilesBaseDir/generatedFilesBaseDir/sourceSet folder has a descriptor_set desc file.
Give Charles a Protobuf Booster.
- Under Charles’ View menu, select Viewer Mapping.
- Enable Viewer Mappings and add a new mapping and select the response type as protocol Buffer.
- Click Open Descriptor Registry to add the generated descriptor file
- Select the appropriate message type from the message type drop – down menu.
Experience the magic
Look! Our response information now shows the mapping of all keys to their respective values. Our response message now shows the mapping of all the keys to their respective values.
This is just one of the ways Charles and Protobuf use it. Read all the possibilities in detail here.
Translation via www.DeepL.com/Translator (free version)