google_maps_pb_decoder 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 57a9c45d0e263a4a8ad65497f9114e55aec4ed55af4b5512de9d88ff62500eee
4
+ data.tar.gz: 945082f965dc3a43c277f82e62e882ad371885067ff8410ddfd3c790d38e841c
5
+ SHA512:
6
+ metadata.gz: 0c647c50912cc5417841ffe678705d66b4cc29a60d2566aac4b16e5e5d6efabf788f56bc203a64f337ffa0865131af048bf61672200f8935e9ef99f9cde1bb20
7
+ data.tar.gz: 10722c263d09cc431b3b8198dddeac6b4ce57b1f78be543248df4bd9986a6177211f136b7554d1ed2a15e31e018d301fbd1f7c4e7bc6aa2b2b1c06475a1050be
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/google_maps_pb_decoder'
4
+
5
+ if (pb_encoded_string = ARGV[-1])
6
+ begin
7
+ output = GoogleMapsPbDecoder.decode(pb_encoded_string)
8
+ puts output.inspect
9
+ rescue => e
10
+ STDERR.puts "Error: #{e.message}"
11
+ exit 1
12
+ end
13
+ else
14
+ puts "google_maps_pb_decoder #{GoogleMapsPbDecoder::VERSION}"
15
+ puts "Usage: google_maps_pb_decoder <pb_encoded_string>"
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GoogleMapsPbDecoder
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "google_maps_pb_decoder/version"
4
+
5
+ module GoogleMapsPbDecoder
6
+ # Original script: https://gist.github.com/jeteon/e71fa21c1feb48fe4b5eeec045229a0c
7
+ def self.decode(str)
8
+ parts = str.split('!').select { |s| s.size > 0 }
9
+ root = [] # Root elemet
10
+ curr = root # Current array element being appended to
11
+ m_stack = [root] # Stack of "m" elements
12
+ m_count = [parts.size] # Number of elements to put under each level
13
+
14
+ parts.each do |e|
15
+ match = e.match(/\d+([a-z])(.*)/)
16
+ if !match || match.size != 3
17
+ raise ArgumentError, "The argument is not a valid protobuf-encoded string"
18
+ end
19
+
20
+ kind = match[1]
21
+ value = match[2]
22
+
23
+ # Decrement all the m_counts
24
+ (0...m_count.size).each do |i|
25
+ m_count[i] -= 1
26
+ end
27
+
28
+ if kind == 'm'
29
+ new_arr = []
30
+ m_count << value.to_i
31
+ curr << new_arr
32
+ m_stack << new_arr
33
+ curr = new_arr
34
+ else
35
+ if kind == 'b' # Assuming these are boolean
36
+ curr << (value == '1')
37
+ elsif kind == 'd' || kind == 'f' # Float or double
38
+ curr << value.to_f
39
+ elsif kind == 'i' || kind == 'u' || kind == 'e' # Integer, unsigned or enum as int
40
+ curr << value.to_i
41
+ else # Store anything else as a string
42
+ curr << value
43
+ end
44
+ end
45
+
46
+ # Pop off all the arrays that have their values already
47
+ while m_count[m_count.size - 1] == 0
48
+ m_stack.pop
49
+ m_count.pop
50
+ curr = m_stack[m_stack.size - 1]
51
+ end
52
+ end
53
+
54
+ root
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_maps_pb_decoder
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yicheng Zhou
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem decodes the protobuf parameters used in Google Maps into readable
14
+ JSON for easy inspection and debugging.
15
+ email:
16
+ - zyc9012@gmail.com
17
+ executables:
18
+ - google_maps_pb_decoder
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - exe/google_maps_pb_decoder
23
+ - lib/google_maps_pb_decoder.rb
24
+ - lib/google_maps_pb_decoder/version.rb
25
+ homepage: https://github.com/serpapi/google-maps-pb-decoder
26
+ licenses:
27
+ - MIT
28
+ metadata:
29
+ homepage_uri: https://github.com/serpapi/google-maps-pb-decoder
30
+ source_code_uri: https://github.com/serpapi/google-maps-pb-decoder
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '1.9'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.0.3.1
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Google Maps pb (protobuf) parameter decoder.
50
+ test_files: []