A decorator that apply marshalling to the return values of your methods.

        :param schema: The schema class to be used to serialize the values.
        :param envelope: The key used to envelope the data.
        :return: A function.
178211
def marshal_with(self, schema, envelope=None):
        

        # schema is pre instantiated to avoid instantiate it
        # on every request
        schema_is_class = isclass(schema)
        schema_cache = schema() if schema_is_class else schema

        def decorator(func):
            @functools.wraps(func)
            def wrapper(*args, **kwargs):
                data = func(*args, **kwargs)
                if isinstance(data, self.__app.response_class):
                    return data

                schema_instance = schema_cache

                # if there is the parameter 'fields' in the url
                # we cannot use the cached schema instance
                # in this case we have to instantiate the schema
                # on every request.
                if schema_is_class:
                    only = get_fields_from_request(schema=schema)
                    if only:
                        schema_instance = schema(only=only)

                return marshal(data, schema_instance, envelope)
            return wrapper
        return decorator
1368010
public static <T> byte[] toByteArray(T message, Schema<T> schema, LinkedBuffer buffer)
    {
        if (buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");

        final XmlXOutput output = new XmlXOutput(buffer, schema);

        final String name = schema.messageName();
        try
        {
            // header and start root element
            output.tail = output.sink.writeByte(XmlXOutput.END_TAG, output,
                    output.sink.writeStrAscii(name, output,
                            output.sink.writeByte(XmlXOutput.START_TAG, output,
                                    output.sink.writeByteArray(HEADER, output, output.tail))));

            schema.writeTo(output, message);

            // end root element
            output.tail = output.sink.writeByte(XmlXOutput.END_TAG, output,
                    output.sink.writeStrAscii(name, output,
                            output.sink.writeByteArray(XmlXOutput.START_SLASH_TAG, output, output.tail)));
        }
        catch (IOException e)
        {
            throw new RuntimeException("Serializing to a byte array threw an IOException " +
                    "(should never happen).", e);
        }

        return output.toByteArray();
    }
1277227
def parse(schema):
    
    if not isinstance(schema, basestring):
        # assume it is file-like
        schema = schema.read()

    message = re.compile(r'^\(([^,]+),\s*(\d+)\):\s*$')
    field = re.compile(r'^-\s*([^:]+):\s+(.+?)\s*$')

    registry = MessageRegistry({})
    messages = registry.messages
    curr = None
    names = None
    for lineno, line in enumerate(schema.split('\n')):
        line = line.strip()
        if '#' in line:
            line = line[:line.index('#')]
        if line == '':
            continue

        f = field.match(line)
        if f:
            if curr is None:
                raise ParseError(
                    'field definition outside of message at line %d' % lineno)
            name = f.group(1)
            type = f.group(2)
            if name not in names:
                f = Field(curr, name, type)
                curr.fields.append(f)
                names.add(name)
                continue
            else:
                raise ParseError(
                    'duplicate field name "%s" at line %d' % (name, lineno))

        m = message.match(line)
        if m:
            # new message definition
            name, vers = m.group(1), int(m.group(2))
            if (name, vers) in messages:
                raise ParseError('Duplicate message (%s, %d)' % (name, vers))
            curr = messages[(name, vers)] = Message(registry, name, vers, [])
            names = set()
            continue

    for message in registry.messages.values():
        message.fields = tuple(message.fields)

    return registry
322923
def _normalize(schema, allow_none=True):
    
    if allow_none and schema is None:
        return schema
    if isinstance(schema, CommonSchema):
        return schema
    if isinstance(schema, StreamSchema):
        return schema

    if isinstance(schema, basestring):
        return StreamSchema(schema)

    py_types = {
        _spl_object: CommonSchema.Python,
        _spl_str: CommonSchema.String,
        json: CommonSchema.Json,
        }

    if schema in py_types:
        return py_types[schema]

    # With Python 3 allow a named tuple with type hints
    # to be used as a schema definition
    if sys.version_info.major == 3:
        import typing
        if isinstance(schema, type) and  issubclass(schema, tuple):
            if hasattr(schema, '_fields') and hasattr(schema, '_field_types'):
                return _from_named_tuple(schema)

    raise ValueError("Unknown stream schema type:" + str(schema))
991997
function SchemaMoment(key, options) {
		SchemaType.call(this, key, options);

		this.get(function(val, self){
			if(!val){
				return val;
			} else {
				return new Moment(val);
			}
		});
	}
573532
def get(self, schema, query=None, **kwargs):
        
        ret = self._get_query(self._get, schema, query, **kwargs)
        if not ret: ret = []
        return ret
959800
def _read_method(schema):
    
    def func(
        self,
        filename,
        seq_label='sequence',
        alphabet=None,
        combine_on='uid',
        use_uids=True,
        **kwargs):
        # Use generic write class to write data.
        df0 = self._data
        df1 = _read(
            filename=filename,
            schema=schema,
            seq_label=seq_label,
            alphabet=alphabet,
            use_uids=use_uids,
            **kwargs
        )
        return df0.phylo.combine(df1, on=combine_on)

    # Update docs
    func.__doc__ = _read_doc_template(schema)
    return func
390774
def model_factory(schema, resolver=None, base_class=model.Model, name=None):
    
    schema = copy.deepcopy(schema)
    resolver = resolver

    class Model(base_class):
        def __init__(self, *args, **kwargs):
            self.__dict__['schema'] = schema
            self.__dict__['resolver'] = resolver
            base_class.__init__(self, *args, **kwargs)

    if resolver is not None:
        Model.resolver = resolver

    if name is not None:
        Model.__name__ = name
    elif 'name' in schema:
        Model.__name__ = str(schema['name'])
    return Model
706516
def pack(mtype, request, rid=None):
    ''''''
    envelope = wire.Envelope() 
    if rid is not None:
        envelope.id = rid
    envelope.type = mtype
    envelope.message = request.SerializeToString()
    data = envelope.SerializeToString()
    data = encoder._VarintBytes(len(data)) + data
    return data
765240
def schema(cls):
        """"""
        root = '/'.join([API_ROOT, 'schemas', cls.__name__])
        schema = cls.GET(root)
        return schema
948576
def resolve_schema_instance(schema):
    
    if isinstance(schema, type) and issubclass(schema, marshmallow.Schema):
        return schema()
    if isinstance(schema, marshmallow.Schema):
        return schema
    try:
        return marshmallow.class_registry.get_class(schema)()
    except marshmallow.exceptions.RegistryError:
        raise ValueError(
            "{!r} is not a marshmallow.Schema subclass or instance and has not"
            " been registered in the Marshmallow class registry.".format(schema)
        )
832644
function wrap(field, type, packet, encoding) {
    return {
      type: type,
      length: field.columnLength,
      db: field.schema,
      table: field.table,
      name: field.name,
      string: function() {
        return packet.readLengthCodedString(encoding);
      },
      buffer: function() {
        return packet.readLengthCodedBuffer();
      },
      geometry: function() {
        return packet.parseGeometryValue();
      }
    };
  }
1156876
public MsgpackOutput use(MsgpackGenerator generator, Schema<?> schema)
    {
        this.schema = schema;
        this.generator = generator;
        return this;
    }
1092183
public static <T> byte[] toByteArray(T message, Schema<T> schema)
    {
        return toByteArray(message, schema, DEFAULT_OUTPUT_FACTORY);
    }
785750
def _read_function(schema):
    
    def func(
        filename,
        seq_label='sequence',
        alphabet=None,
        use_uids=True,
        **kwargs):
        # Use generic write class to write data.
        return _read(
            filename=filename,
            schema=schema,
            seq_label=seq_label,
            alphabet=alphabet,
            use_uids=use_uids,
            **kwargs
        )
    # Update docs
    func.__doc__ = _read_doc_template(schema)
    return func
498074
def request(schema):
    
    def wrapper(func):
        setattr(func, REQUEST, schema)
        return func
    return wrapper
262874
def encode(self, envelope, session, **kwargs):
		
		return WMessengerTextEnvelope(str(WHex(envelope.message())), meta=envelope)