# Path: groundstation/objects/base_object_pb2.py
# class BaseObject(_message.Message):
#   __metaclass__ = _reflection.GeneratedProtocolMessageType
#   DESCRIPTOR = _BASEOBJECT
# 
#   # @@protoc_insertion_point(class_scope:BaseObject)
# 
# ROOT = 1
# 
# UPDATE = 2
# 
# UNSET = 0
# 
# Path: groundstation/objects/root_object.py
# class RootObject(base_object.BaseObject):
#     data_members = ["id", "channel", "protocol"]
# 
#     def __init__(self, id, channel, protocol):
#         self.id = id
#         self.channel = channel
#         self.protocol = protocol
#         self._sha1 = None
# 
#     @staticmethod
#     def from_object(obj):
#         """Convert an object straight from Git into a RootObject"""
#         protobuf = root_object_pb2.RootObject()
#         protobuf.ParseFromString(obj)
#         return RootObject(protobuf.id, protobuf.channel, protobuf.protocol)
# 
#     def as_object(self):
#         """Convert a RootObject into data suitable to write into the database
#         as a Git object"""
#         protobuf = root_object_pb2.RootObject()
#         for member in self.data_members:
#             setattr(protobuf, member, getattr(self, member))
#         return protobuf.SerializeToString()
# 
#     def as_json(self):
#         return {
#                 "id": self.id,
#                 "channel": self.channel,
#                 "protocol": self.protocol
#                 }
# 
# Path: groundstation/objects/update_object.py
# class UpdateObject(base_object.BaseObject):
#     data_members = ["parents", "data"]
# 
#     def __init__(self, parents, data):
#         self.parents = parents
#         self.data = data
#         self._sha1 = None
# 
#     @staticmethod
#     def from_object(obj):
#         """Convert an object straight from Git into a RootObject"""
#         protobuf = update_object_pb2.UpdateObject()
#         protobuf.ParseFromString(obj)
#         return UpdateObject(protobuf.parents, protobuf.data)
# 
#     def as_object(self):
#         """Convert a RootObject into data suitable to write into the database
#         as a Git object"""
#         protobuf = update_object_pb2.UpdateObject()
#         protobuf.parents.extend(self.parents)
#         protobuf.data = self.data
#         return protobuf.SerializeToString()


from groundstation.objects.base_object_pb2 import BaseObject, \
    ROOT as TYPE_ROOT, \
    UPDATE as TYPE_UPDATE, \
    UNSET as TYPE_UNSET
from groundstation.objects.root_object import RootObject
from groundstation.objects.update_object import UpdateObject


def type_of(protobuf):
    base = BaseObject()
    base.ParseFromString(protobuf)
    return base.type


def hydrate_object(protobuf):
    # Test if it's strongly typed first
    _type = type_of(protobuf)
    if _type == TYPE_ROOT:
        return RootObject.from_object(protobuf)
    elif _type == TYPE_UPDATE:
        return UpdateObject.from_object(protobuf)
    elif _type == TYPE_UNSET:
        # Use existing heuristic

# Path: groundstation/objects/base_object_pb2.py
# class BaseObject(_message.Message):
#   __metaclass__ = _reflection.GeneratedProtocolMessageType
#   DESCRIPTOR = _BASEOBJECT
# 
#   # @@protoc_insertion_point(class_scope:BaseObject)
# 
# ROOT = 1
# 
# UPDATE = 2
# 
# UNSET = 0
# 
# Path: groundstation/objects/root_object.py
# class RootObject(base_object.BaseObject):
#     data_members = ["id", "channel", "protocol"]
# 
#     def __init__(self, id, channel, protocol):
#         self.id = id
#         self.channel = channel
#         self.protocol = protocol
#         self._sha1 = None
# 
#     @staticmethod
#     def from_object(obj):
#         """Convert an object straight from Git into a RootObject"""
#         protobuf = root_object_pb2.RootObject()
#         protobuf.ParseFromString(obj)
#         return RootObject(protobuf.id, protobuf.channel, protobuf.protocol)
# 
#     def as_object(self):
#         """Convert a RootObject into data suitable to write into the database
#         as a Git object"""
#         protobuf = root_object_pb2.RootObject()
#         for member in self.data_members:
#             setattr(protobuf, member, getattr(self, member))
#         return protobuf.SerializeToString()
# 
#     def as_json(self):
#         return {
#                 "id": self.id,
#                 "channel": self.channel,
#                 "protocol": self.protocol
#                 }
# 
# Path: groundstation/objects/update_object.py
# class UpdateObject(base_object.BaseObject):
#     data_members = ["parents", "data"]
# 
#     def __init__(self, parents, data):
#         self.parents = parents
#         self.data = data
#         self._sha1 = None
# 
#     @staticmethod
#     def from_object(obj):
#         """Convert an object straight from Git into a RootObject"""
#         protobuf = update_object_pb2.UpdateObject()
#         protobuf.ParseFromString(obj)
#         return UpdateObject(protobuf.parents, protobuf.data)
# 
#     def as_object(self):
#         """Convert a RootObject into data suitable to write into the database
#         as a Git object"""
#         protobuf = update_object_pb2.UpdateObject()
#         protobuf.parents.extend(self.parents)
#         protobuf.data = self.data
#         return protobuf.SerializeToString()


# Path: groundstation/objects/object_factory.py
from groundstation.objects.base_object_pb2 import BaseObject, \
    ROOT as TYPE_ROOT, \
    UPDATE as TYPE_UPDATE, \
    UNSET as TYPE_UNSET
from groundstation.objects.root_object import RootObject
from groundstation.objects.update_object import UpdateObject



def type_of(protobuf):
    base = BaseObject()
    base.ParseFromString(protobuf)
    return base.type


def hydrate_object(protobuf):
    # Test if it's strongly typed first
    _type = type_of(protobuf)
    if _type == TYPE_ROOT:
        return RootObject.from_object(protobuf)
    elif _type == TYPE_UPDATE:
        return UpdateObject.from_object(protobuf)
    elif _type == TYPE_UNSET:
        # Use existing heuristic

        obj = RootObject.from_object(protobuf)