Created
August 20, 2012 23:54
-
-
Save dylanvee/3409403 to your computer and use it in GitHub Desktop.
db/ndb protocol buffer serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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