MikO MikO - 1 year ago 66
JSON Question

getting a timestamp out of a gwt-rpc string

i have a response from a server, which looks like:


my reseach led me to the assumption that this is a GWT-RPC response. the question is now, how i can unserialize this strings
which used to be timestamps?

Answer Source

This is how Google Web Toolkit encodes longs in RPC. Also timestamps are encoded in this format.

The encoding is pretty simple: Instead of the alphabet 0123456789 (as used for decimals, base 10) the alphabet here is ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$ and the base is 64.

Here is a python snippet to decode a number encoded like this:

def from_gwt_long(inp):
    base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$"
    return sum(base.index(inp[p]) * (len(base) ** (len(inp) - p - 1)) for p in range(len(inp)))

You can also put the alphabet given above into this base converter: http://elenzil.com/esoterica/baseConversion.html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download