# Path: protobuf3/fields/base.py
# class BaseField(object):
#     DEFAULT_VALUE = None
#     WIRE_TYPE = -1
# 
#     def __init__(self, field_number=None, required=False, optional=False, repeated=False,
#                  default=None):
#         assert isinstance(field_number, int)
# 
#         self.__field_name = "undefined"
#         self.__field_number = field_number
#         self.__required = required
#         self.__optional = optional
#         self.__repeated = repeated
# 
#         if (default is not None) and (not self._validate(default)):
#             raise ValueError
#         self.__default = default
# 
#     @property
#     def field_name(self):
#         return self.__field_name
# 
#     @field_name.setter
#     def field_name(self, value):
#         self.__field_name = value
# 
#     @property
#     def field_number(self):
#         return self.__field_number
# 
#     @property
#     def required(self):
#         return self.__required
# 
#     @property
#     def optional(self):
#         return self.__optional
# 
#     @property
#     def repeated(self):
#         return self.__repeated
# 
#     @property
#     def default_value(self):
#         if self.__default:
#             return self.__default
#         return self.DEFAULT_VALUE
# 
#     def _convert_to_final_type(self, value):
#         return value
# 
#     def _convert_to_wire_type(self, value):
#         return value
# 
#     def _validate(self, value):
#         return True
# 
#     def __get__(self, instance, owner):
#         if self.__repeated:
#             return ListWrapper(instance, self)
#         else:
#             wire_values = instance._get_wire_values(self.__field_number)
# 
#             if not wire_values:
#                 final_value = self.default_value
#             else:
#                 final_value = self._convert_to_final_type(wire_values[0].value)
# 
#             if hasattr(final_value, '_set_parent'):
#                 final_value._set_parent((instance, self.__field_number, None))
# 
#             return final_value
# 
#     def __set__(self, instance, value):
#         if not self._validate(value):
#             raise ValueError
# 
#         instance._set_wire_values(self.__field_number, self.WIRE_TYPE,
#                                   self._convert_to_wire_type(value))
# 
#     def __delete__(self, instance):
#         instance._drop_wire_value(self.__field_number)
# 
#     def __repr__(self):
#         field_type = ''
#         if self.required:
#             field_type = 'required'
#         if self.optional:
#             field_type = 'optional'
#         if self.repeated:
#             field_type = 'repeated'
#         return '<{}(id={}, {})>'.format(self.__class__.__name__, self.field_number, field_type)


from collections import namedtuple
from protobuf3.fields.base import BaseField
from protobuf3.wire_types import *
        self.__read_offset += offset + 1

        return varint

    @staticmethod
    def _encode_varint(number):
        result = []

        while number:
            next_byte = number % 128
            number //= 128

            if number:
                next_byte |= 1 << 7
            result.append(next_byte)
        
        if len(result) == 0:
            result = [0]

        return bytes(result)

    def _decode_raw_message(self, data):
        def __read_n_bytes(n):
            result = bytes(data[self.__read_offset:self.__read_offset + n])
            self.__read_offset += n
            return result

        while self.__read_offset < len(data):
            field_signature = self._decode_field_signature(data)
            field_type, field_number, field_length = field_signature

# Path: protobuf3/fields/base.py
# class BaseField(object):
#     DEFAULT_VALUE = None
#     WIRE_TYPE = -1
# 
#     def __init__(self, field_number=None, required=False, optional=False, repeated=False,
#                  default=None):
#         assert isinstance(field_number, int)
# 
#         self.__field_name = "undefined"
#         self.__field_number = field_number
#         self.__required = required
#         self.__optional = optional
#         self.__repeated = repeated
# 
#         if (default is not None) and (not self._validate(default)):
#             raise ValueError
#         self.__default = default
# 
#     @property
#     def field_name(self):
#         return self.__field_name
# 
#     @field_name.setter
#     def field_name(self, value):
#         self.__field_name = value
# 
#     @property
#     def field_number(self):
#         return self.__field_number
# 
#     @property
#     def required(self):
#         return self.__required
# 
#     @property
#     def optional(self):
#         return self.__optional
# 
#     @property
#     def repeated(self):
#         return self.__repeated
# 
#     @property
#     def default_value(self):
#         if self.__default:
#             return self.__default
#         return self.DEFAULT_VALUE
# 
#     def _convert_to_final_type(self, value):
#         return value
# 
#     def _convert_to_wire_type(self, value):
#         return value
# 
#     def _validate(self, value):
#         return True
# 
#     def __get__(self, instance, owner):
#         if self.__repeated:
#             return ListWrapper(instance, self)
#         else:
#             wire_values = instance._get_wire_values(self.__field_number)
# 
#             if not wire_values:
#                 final_value = self.default_value
#             else:
#                 final_value = self._convert_to_final_type(wire_values[0].value)
# 
#             if hasattr(final_value, '_set_parent'):
#                 final_value._set_parent((instance, self.__field_number, None))
# 
#             return final_value
# 
#     def __set__(self, instance, value):
#         if not self._validate(value):
#             raise ValueError
# 
#         instance._set_wire_values(self.__field_number, self.WIRE_TYPE,
#                                   self._convert_to_wire_type(value))
# 
#     def __delete__(self, instance):
#         instance._drop_wire_value(self.__field_number)
# 
#     def __repr__(self):
#         field_type = ''
#         if self.required:
#             field_type = 'required'
#         if self.optional:
#             field_type = 'optional'
#         if self.repeated:
#             field_type = 'repeated'
#         return '<{}(id={}, {})>'.format(self.__class__.__name__, self.field_number, field_type)


# Path: protobuf3/message.py
from collections import namedtuple
from protobuf3.fields.base import BaseField
from protobuf3.wire_types import *

        self.__read_offset += offset + 1

        return varint

    @staticmethod
    def _encode_varint(number):
        result = []

        while number:
            next_byte = number % 128
            number //= 128

            if number:
                next_byte |= 1 << 7
            result.append(next_byte)
        
        if len(result) == 0:
            result = [0]

        return bytes(result)

    def _decode_raw_message(self, data):
        def __read_n_bytes(n):
            result = bytes(data[self.__read_offset:self.__read_offset + n])
            self.__read_offset += n
            return result

        while self.__read_offset < len(data):
            field_signature = self._decode_field_signature(data)
            field_type, field_number, field_length = field_signature

            field_object = self.__fields.get(field_number, BaseField(field_number))