java.util.Date serialization on RPC...

44 views
Skip to first unread message

Hilario Perez Corona

unread,
Aug 10, 2011, 3:33:36 AM8/10/11
to google-we...@googlegroups.com
Hi,

I'm working on a Go implementation of GWT-RPC... It's in a very early stage, but it's working fine for most objects...

One object that i don't know how to convert is the java.util.Date class.

It sends something like this: TGyZwy5

And i don't have a clue of how to convert it to milliseconds, nanoseconds, or anything that it used to be before serialization.

Any help would be very appreciated.

Thanx.

Hilario Perez Corona

unread,
Aug 11, 2011, 3:29:12 AM8/11/11
to google-we...@googlegroups.com
Ok, i've resolved the mistery... And if anyone is wondering, here's how it works.

The date is a simple Long value containing the milliseconds.

It is encoded in something that looks like base64, but using this characters:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$_

Where:

A = 0
B = 1
_ = 63
BA = 64
P__________ = -1
P_________$ = -2

So, my code to convert it back to a long ended up like this:

const gwtLongChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$_"

func ToLong(v string) (int64, os.Error) {
var t int64 = 0
for i := 0; i < len(v); i++ {
c := v[i:i+1]
idx := strings.Index(gwtLongChars, c)
if idx < 0 {
return 0, os.NewError(fmt.Sprintf("Not long GWT, found: %s", c))
}
t = t * 64 + int64(idx)
}
return t, nil
}

Hope it's helpful for someone else.

Thanks.
Reply all
Reply to author
Forward
0 new messages