如何在.Java文件中解码协议缓冲区字符串

时间:2015-09-01 16:49:52

标签: java string protocol-buffers decode

我四处寻找名字叫这个,但我找不到任何.... 它是在朋友发送给我的.java文件中(他以为我会直接解码它),不知道我也是这个菜鸟.... 这是我想要在不编译Java文件的情况下解码的字符串数据。

String[] descriptorData = {
  "\n0com/google/javascript/jscomp/function_" +
  "info.proto\022\006jscomp\"\277\002\n\026FunctionInformati" +
  "onMap\0223\n\005entry\030\001 \003(\n2$.jscomp.FunctionIn" +
  "formationMap.Entry\0225\n\006module\030e \003(\n2%.jsc" +
  "omp.FunctionInformationMap.Module\032\207\001\n\005En" +
  "try\022\n\n\002id\030\002 \002(\005\022\023\n\013source_name\030\003 \002(\t\022\023\n\013" +
  "line_number\030\004 \002(\005\022\023\n\013module_name\030\005 \002(\t\022\014" +
  "\n\004size\030\006 \002(\005\022\014\n\004name\030\007 \002(\t\022\027\n\017compiled_s" +
  "ource\030\010 \002(\t\032/\n\006Module\022\014\n\004name\030f \002(\t\022\027\n\017c" +
  "ompiled_source\030g \002(\tB \n\034com.google.javas","cript.jscompP\001"

2 个答案:

答案 0 :(得分:0)

What you see there is if I'm not mistaken a piece of auto generated code that describes

message FunctionInformationMap {
  repeated group Entry = 1 {
    required int32 id = 2;
    required string source_name = 3;
    required int32 line_number = 4;
    required string module_name = 5;
    required int32 size = 6;
    required string name = 7;
    required string compiled_source = 8;
  }
}

It's here https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/function_info.proto

and the generated code here can be found for example here

https://code.google.com/p/closure-compiler/source/browse/gen/com/google/javascript/jscomp/FunctionInfo.java?name=v20140407

Ps: I just googled "com/google/javascript/jscomp/function_info.proto" but you can actually reverse the process. Hints here for example https://www.sysdream.com/reverse-engineering-protobuf-apps

答案 1 :(得分:0)

我只是通过使用System.Out.PrintIn将字符串数据打印到TXT文件来解决这个问题......

那是...... 感谢...