Make encode_kv_length bigendian-safe

Change-Id: I7ebc0d6263597b82859419ee573812113b524aad
Reviewed-on: http://review.couchbase.org/30408
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>