Skip to content

Instantly share code, notes, and snippets.

@dylanvee
Created August 20, 2012 23:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanvee/3409403 to your computer and use it in GitHub Desktop.
Save dylanvee/3409403 to your computer and use it in GitHub Desktop.
db/ndb protocol buffer serialization
from google.appengine.ext import db, ndb
from google.appengine.datastore import entity_pb
def db_entity_to_protobuf(e):
return db.model_to_protobuf(e).Encode()
def protobuf_to_db_entity(pb):
# precondition: model class must be imported
return db.model_from_protobuf(entity_pb.EntityProto(pb))
def ndb_entity_to_protobuf(e):
return ndb.ModelAdapter().entity_to_pb(e).Encode()
def protobuf_to_ndb_entity(pb):
# precondition: model class must be imported
return ndb.ModelAdapter().pb_to_entity(entity_pb.EntityProto(pb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment