Serialize a val schema to teleport.
173077
def from_val(val_schema):
    """"""
    definition = getattr(val_schema, "definition", val_schema) if isinstance(
        val_schema, BaseSchema) else val_schema
    if isinstance(definition, dict):
        return _dict_to_teleport(definition)

    if isinstance(definition, list):
        # teleport only supports a single type by default
        if len(definition) == 1:
            return {"Array": from_val(definition[0])}

    if definition in VAL_PRIMITIVES:
        return VAL_PRIMITIVES[definition]

    raise SerializationError(
        "Serializing %r not (yet) supported." % definition)
292961
private Object composeColumnValue(CqlMetadata cqlMetadata, byte[] thriftColumnValue, byte[] thriftColumnName) {
        Map<ByteBuffer, String> schemaTypes = cqlMetadata.getValue_types();
        AbstractType<?> type = null;
        try {
            type = TypeParser.parse(schemaTypes.get(ByteBuffer.wrap(thriftColumnName)));
        } catch (SyntaxException | ConfigurationException ex) {
            log.error(ex.getMessage());
            throw new KunderaException("Error while deserializing column value " + ex);
        }
        if (type.isCollection()) {
            return ((CollectionSerializer) type.getSerializer())
                .deserializeForNativeProtocol(ByteBuffer.wrap(thriftColumnValue), ProtocolVersion.V2);
        }
        return type.compose(ByteBuffer.wrap(thriftColumnValue));
    }
1231061
def to_simple(self, request, data, many=False, **kwargs):
        """"""
        schema = self.get_schema(request, **kwargs)
        return schema.dump(data, many=many).data if schema else data
774819
def SerializeFaultDetail(self, val, info):
      
      self._SerializeDataObject(val, info, ' xsi:typ="{1}"'.format(val._wsdlName), self.defaultNS)
550027
function serialize (value, columnDefinitions) {

    var serializedValue = {};

    try {
        Validate.notNull(columnDefinitions, 'columnDefinitions');
        Validate.isObject(columnDefinitions);
        
        Validate.notNull(value);
        Validate.isObject(value);

        for (var property in value) {

            var columnType = storeHelper.getColumnType(columnDefinitions, property);
            // Skip properties that don't match any column in the table 
            if (!_.isNull(columnType)) {
                serializedValue[property] = serializeMember(value[property], columnType);
            }
        }
        
    } catch (error) {
        throw new verror.VError(error, 'Failed to serialize value ' + JSON.stringify(value) + '. Column definitions: ' + JSON.stringify(columnDefinitions));
    }

    return serializedValue;
}
1374097
def Serialize(self, val, info):
      
      self._Serialize(val, info, self.defaultNS)
1307071
def serialize(buff)
      serialized_data = ''
      @data.each_pair do |key, value|
        data_str = key + '=' + value
        serialized_data = serialized_data + [data_str.length, data_str].pack('Va*')
      end
      total_byte = serialized_data.length
      return buff.write([total_byte, serialized_data].pack('Va*'))
    end
797755
function serialize(value, callback) {
    var valueType = '';
    if (value) {
        valueType = toString$1.call(value);
    }

    // Cannot use `value instanceof ArrayBuffer` or such here, as these
    // checks fail when running the tests using casper.js...
    //
    // TODO: See why those tests fail and use a better solution.
    if (value && (valueType === '[object ArrayBuffer]' || value.buffer && toString$1.call(value.buffer) === '[object ArrayBuffer]')) {
        // Convert binary arrays to a string and prefix the string with
        // a special marker.
        var buffer;
        var marker = SERIALIZED_MARKER;

        if (value instanceof ArrayBuffer) {
            buffer = value;
            marker += TYPE_ARRAYBUFFER;
        } else {
            buffer = value.buffer;

            if (valueType === '[object Int8Array]') {
                marker += TYPE_INT8ARRAY;
            } else if (valueType === '[object Uint8Array]') {
                marker += TYPE_UINT8ARRAY;
            } else if (valueType === '[object Uint8ClampedArray]') {
                marker += TYPE_UINT8CLAMPEDARRAY;
            } else if (valueType === '[object Int16Array]') {
                marker += TYPE_INT16ARRAY;
            } else if (valueType === '[object Uint16Array]') {
                marker += TYPE_UINT16ARRAY;
            } else if (valueType === '[object Int32Array]') {
                marker += TYPE_INT32ARRAY;
            } else if (valueType === '[object Uint32Array]') {
                marker += TYPE_UINT32ARRAY;
            } else if (valueType === '[object Float32Array]') {
                marker += TYPE_FLOAT32ARRAY;
            } else if (valueType === '[object Float64Array]') {
                marker += TYPE_FLOAT64ARRAY;
            } else {
                callback(new Error('Failed to get type for BinaryArray'));
            }
        }

        callback(marker + bufferToString(buffer));
    } else if (valueType === '[object Blob]') {
        // Conver the blob to a binaryArray and then to a string.
        var fileReader = new FileReader();

        fileReader.onload = function () {
            // Backwards-compatible prefix for the blob type.
            var str = BLOB_TYPE_PREFIX + value.type + '~' + bufferToString(this.result);

            callback(SERIALIZED_MARKER + TYPE_BLOB + str);
        };

        fileReader.readAsArrayBuffer(value);
    } else {
        try {
            callback(JSON.stringify(value));
        } catch (e) {
            console.error("Couldn't convert value into a JSON string: ", value);

            callback(null, e);
        }
    }
}
951099
function serialize(input) {
    const value = JSON.stringify(input);
    return value === undefined
        ? reject(new Error(`Unsupported type ${type(input)}`))
        : resolve(value);
}
684555
def raw_value(self) -> RawValue:
        """"""
        if isinstance(self.value, ObjectValue):
            return {m: self._member(m).raw_value() for m in self.value}
        if isinstance(self.value, ArrayValue):
            return [en.raw_value() for en in self]
        return self.schema_node.type.to_raw(self.value)
837822
def dumps(self, value):
    ''''''
    for serializer in self:
      value = serializer.dumps(value)
    return value
132483
def dump(self, obj, **kwargs):
        """"""
        self.obj = obj
        return super(JSONSchema, self).dump(obj, **kwargs)
1073825
def _translate_composite(teleport_value):
    """"""
    for key in ("Array", "Map", "Struct"):
        value = teleport_value.get(key)
        if value is None:
            continue
        return COMPOSITES[key](value)

    raise DeserializationError(
        "Could not interpret %r as a teleport schema." % teleport_value)
276512
def _translate(teleport_value):
    """"""
    if isinstance(teleport_value, dict):
        return _translate_composite(teleport_value)

    if teleport_value in PRIMITIVES:
        return PRIMITIVES[teleport_value]

    raise DeserializationError(
        "Could not interpret %r as a teleport schema." % teleport_value)
1040819
def _dict_to_teleport(dict_value):
    """"""
    if len(dict_value) == 1:
        for key, value in dict_value.items():
            if key is str:
                return {"Map": from_val(value)}

    optional = {}
    required = {}
    for key, value in dict_value.items():
        if isinstance(key, Optional):
            optional[key.value] = from_val(value)
        else:
            required[key] = from_val(value)

    return {"Struct": {
        "required": required,
        "optional": optional}}
21570
def serialize(self, value, primitive=False):
        """"""
        return [self.field.serialize(v, primitive=primitive) for v in value]
630845
def _to_string(val):
    """"""
    if isinstance(val, binary_type):
        return val.decode('utf-8')
    assert isinstance(val, text_type)
    return val