-
Notifications
You must be signed in to change notification settings - Fork 173
Protobuf URL
Marin edited this page Mar 17, 2017
·
1 revision
Google Maps web clients and APIs use a specific way to encode Protobuf messages into URLs. It is composed of a text sequence of the following elements:
- Delimiter: “!” for private API, “&” for public API
- Field number: base 10 integer
- Field type: single character, see table below
- Value: see table below
Type | Representation | Notes | |
---|---|---|---|
d | double | Base 10 decimal | |
f | float | ||
i | int32 | Base 10 integer | |
j | int64 | ||
u | uint32 | ||
v | uint64 | ||
x | fixed32 | ||
y | fixed64 | ||
g | sfixed32 | ||
h | sfixed64 | ||
n | sint32 | ||
o | sint64 | ||
e | enum | ||
b | bool | ||
m | message | Value is the number of subsequent “!”-separated blocks contained in the message. | |
s | string | Plain string | “*” and “!” encoded as “*2A” and “*21”. |
z | Base64 string | Base64url, no padding. | |
B | bytes |
Server (decoding) implementation notes:
- Payload is converted on the fly to wire format, as such type character does not matter much, as long as wire type and representation matches.
- As such, embedded messages can be encoded in raw form using z and B types.
Client (encoding) implementation notes:
- A C++ implementation is compiled into Google Earth's desktop and Android clients. The class is named “JsProtoUrlSerializer”.
This will return wire format representation for the “5” embedded message.
$ curl -s 'https://kh.google.com/rt/earth/ViewportMetadata?pb=!1u0!5m2!9998sabcd!12y1' | tail -c+12 | protoc --decode_raw
This will enumerate existing types and their minimal outputs.
$ for i in {A..Z} {a..z}; do x=`curl -s 'https://kh.google.com/rt/earth/ViewportMetadata?pb=!1u0!5m1!4'$i'0' | tail -c+12 | hexdump -ve '1/1 "%.2x "'`; [[ -z $x ]] || echo $i $x; done
See here for generic type information: