Exemplo n.º 1
0
 def _ParseTypeDesc(type_desc, names):
     type_schema = schema.SchemaFromJSONData(type_desc, names=names)
     if type_schema.type not in VALID_TYPE_SCHEMA_TYPES:
         raise ProtocolParseException(
             'Invalid type %r in protocol %r: '
             'protocols can only declare types %s.' %
             (type_schema, avro_name, ','.join(VALID_TYPE_SCHEMA_TYPES)))
     return type_schema
Exemplo n.º 2
0
    def _ParseResponseFromJSONDesc(response_desc, names):
        """Parses the response descriptor of a protocol message.

    Args:
      response_desc: Descriptor of the message response.
          This is an arbitrary Avro schema descriptor.
    Returns:
      The parsed response schema.
    """
        return schema.SchemaFromJSONData(response_desc, names=names)
Exemplo n.º 3
0
    def _ParseErrorsFromJSONDesc(errors_desc, names):
        """Parses the errors descriptor of a protocol message.

    Args:
      errors_desc: Descriptor of the errors thrown by the protocol message.
          This is a list of error types understood as an implicit union.
          Each error type is an arbitrary Avro schema.
      names: Tracker for named Avro schemas.
    Returns:
      The parsed ErrorUnionSchema.
    """
        error_union_desc = {
            'type': schema.ERROR_UNION,
            'declared_errors': errors_desc,
        }
        return schema.SchemaFromJSONData(error_union_desc, names=names)
Exemplo n.º 4
0
            def register_message(self,
                                 obj: dict,
                                 type_identifier: int = None) -> int:
                """
                :param obj: A message object to register.

                :param type_identifier: An optional message type identifier to
                  use for the object. If not specified then a number will be
                  automatically assigned.
                """
                if isinstance(obj, dict):
                    avro_schema = schema.SchemaFromJSONData(
                        obj, schema.Names())
                else:
                    avro_schema = obj

                if type_identifier is None:
                    self._id += 1
                    type_identifier = self._id

                self.id2schema[type_identifier] = avro_schema
                return type_identifier