Determine the encoding of an object.

@param rtype The redis type string.
@param value The value of the object.
@param conf Reference to the configuration.
769053
function encoding(rtype, value, conf) {
  var enc;

  //console.dir('rtype: ' + rtype);
  //console.dir(value);

  switch(rtype) {
    case RTYPE.STRING:
      enc = ENCODING.RAW;
      // integer encoding
      if(typeof value === 'number'
        && parseInt(value) === value
        || (typeof value === 'string'
          && /^-?\d+$/.test(value))
        || (value instanceof Buffer) && isIntegerBuffer(value)) {
        enc = ENCODING.INT;
      }
      break;
    case RTYPE.LIST:
      // no ziplist support yet
      enc = ENCODING.LINKEDLIST;
      break;
    case RTYPE.SET:
      // no intset support yet
      enc = ENCODING.HASHTABLE;
      break;
    case RTYPE.HASH:
      // no zipmap support yet
      enc = ENCODING.HASHTABLE;
      break;
    case RTYPE.ZSET:
      // no ziplist support yet
      enc = ENCODING.SKIPLIST;
      break;
  }

  return enc;
}
1103707
def _utf8(value):
    
    if isinstance(value, _UTF8_TYPES):
        return value
    if not isinstance(value, unicode_type):
        raise TypeError(
            "Expected bytes, unicode, or None; got %r" % type(value)
        )
    return value.encode("utf-8")
302767
public static Object converValue(String type, String value){
		if(type.equals("java.lang.String")){
			return value;
		} else if(type.equals("int") || type.equals("java.lang.Integer")){
			return (int)Integer.parseInt(value);
		} else if(type.equals("boolean") || type.equals("java.lang.Boolean")){
			return (boolean)Boolean.parseBoolean(value);
		} else if(type.equals("float") || type.equals("java.lang.Double")){
			return (float)Float.parseFloat(value);
		} else if(type.equals("double") || type.equals("java.lang.Double")){
			return (double)Double.parseDouble(value);
		} else if(type.equals("short") || type.equals("java.lang.Short")){
			return (short)Short.parseShort(value);
		} else if(type.equals("char") || type.equals("java.lang.Character")){
			if(value.length()>0){
				return value.charAt(0);
			}else{
				return null;
			}
		} else if(type.equals("long") || type.equals("java.lang.Long")){
			return (long)Long.parseLong(value);
		} else if(type.equals("byte") || type.equals("java.lang.Byte")){
			return (byte)Byte.parseByte(value);
		} else if (type.equals("java.util.Date")){
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			if (value.contains("/")){
				String items[] = value.split("/");
				dateFormat = new SimpleDateFormat(items[0]);
				value = items[1];
			}
			try {
				return dateFormat.parseObject(value);
			} catch (ParseException e) {
				logger.error(String.format("Parse Date Exception: exception=%s", e.getMessage()));
				return null;
			}
		} else if (type.equals("java.math.BigDecimal")){
			return new BigDecimal(value);
		} else if (type.equals("java.math.BigInteger")){
			return new BigInteger(value);
		} else{
			return null;
		}
	}
1293262
private Class<?> serializerToClass(String value) {
    try {
      return Thread.currentThread().getContextClassLoader().loadClass(value);
    } catch (ClassNotFoundException e) {
      throw new ConfigurationException("unknown serializable type: " + value);
    }
  }
949796
def utf8(value):
    
    if isinstance(value, _UTF8_TYPES):
        return value
    if not isinstance(value, unicode_type):
        raise TypeError(
            "Expected bytes, unicode, or None; got %r" % type(value)
        )
    return value.encode("utf-8")
135033
function dtype( value ) {
	var type,
		dt;
	if ( value === null ) {
		return 'null';
	}
	// Check for base types:
	type = typeof value;
	switch ( type ) {
		case 'undefined':
		case 'boolean':
		case 'number':
		case 'string':
		case 'function':
		case 'symbol':
			return type;
	}
	// Resort to slower look-up:
	type = typeName( value );

	// Is value a known array type?
	dt = getType( type );
	if ( dt ) {
		return dt;
	}
	// Is value a buffer object?
	if ( type === 'Buffer' || type === 'ArrayBuffer' ) {
		return 'binary';
	}
	// Assume the value is a generic object (Object|Class instance) which could contain any or multiple data types...
	return 'generic';
}
531180
protected Object cast(Object value) {
        switch (type) {
            case STRING :
               return valueFactories.getStringFactory().create(value);
            case LONG :
                return valueFactories.getLongFactory().create(value);
            case NAME :
                return valueFactories.getNameFactory().create(value);
            case PATH :
                return valueFactories.getPathFactory().create(value);
            case DATE :
                return valueFactories.getDateFactory().create(value);
            case BOOLEAN :
                return valueFactories.getBooleanFactory().create(value);
            case URI :
                return valueFactories.getUriFactory().create(value);
            case REFERENCE :
                return valueFactories.getReferenceFactory().create(value);
            case SIMPLEREFERENCE :
                return valueFactories.getSimpleReferenceFactory().create(value);
            case WEAKREFERENCE :
                return valueFactories.getWeakReferenceFactory().create(value);
            default :
                return value;
        }
    }
1337507
def value(self, value, encoding="utf-8"):
        
        from abilian.services.repository import session_repository as repository

        repository.set(self, self.uuid, value)
        self.meta["md5"] = str(hashlib.md5(self.value).hexdigest())

        if hasattr(value, "filename"):
            filename = value.filename
            if isinstance(filename, bytes):
                filename = filename.decode("utf-8")
            self.meta["filename"] = filename

        if hasattr(value, "content_type"):
            self.meta["mimetype"] = value.content_type
1237160
public static void writeNativeValue(Type type, BlockBuilder blockBuilder, Object value)
    {
        if (value == null) {
            blockBuilder.appendNull();
        }
        else if (type.getJavaType() == boolean.class) {
            type.writeBoolean(blockBuilder, (Boolean) value);
        }
        else if (type.getJavaType() == double.class) {
            type.writeDouble(blockBuilder, ((Number) value).doubleValue());
        }
        else if (type.getJavaType() == long.class) {
            type.writeLong(blockBuilder, ((Number) value).longValue());
        }
        else if (type.getJavaType() == Slice.class) {
            Slice slice;
            if (value instanceof byte[]) {
                slice = Slices.wrappedBuffer((byte[]) value);
            }
            else if (value instanceof String) {
                slice = Slices.utf8Slice((String) value);
            }
            else {
                slice = (Slice) value;
            }
            type.writeSlice(blockBuilder, slice, 0, slice.length());
        }
464993
public void writeUTF8Const(String value)
    throws IOException
  {
    ConstantPool pool =  _javaClass.getConstantPool();
    Utf8Constant entry = pool.getUTF8(value);

    if (entry != null)
      writeShort(entry.getIndex());
    else
      throw new NullPointerException(L.l("utf8 constant {0} does not exist", value));
  }
1069832
private String getDataType(final Value value) {
        if (value instanceof BigDecimalValue) {
            return DataType.TYPE_NUMERIC_BIGDECIMAL;
        } else if (value instanceof BigIntegerValue) {
            return DataType.TYPE_NUMERIC_BIGINTEGER;
        } else if (value instanceof BooleanValue) {
            return DataType.TYPE_BOOLEAN;
        } else if (value instanceof ByteValue) {
            return DataType.TYPE_NUMERIC_BYTE;
        } else if (value instanceof DateValue) {
            return DataType.TYPE_DATE;
        } else if (value instanceof DoubleValue) {
            return DataType.TYPE_NUMERIC_DOUBLE;
        } else if (value instanceof FloatValue) {
            return DataType.TYPE_NUMERIC_FLOAT;
        } else if (value instanceof IntegerValue) {
            return DataType.TYPE_NUMERIC_INTEGER;
        } else if (value instanceof LongValue) {
            return DataType.TYPE_NUMERIC_LONG;
        } else if (value instanceof ShortValue) {
            return DataType.TYPE_NUMERIC_SHORT;
        } else if (value instanceof EnumValue) {
            return DataType.TYPE_COMPARABLE;
        }

        return DataType.TYPE_STRING;
    }
1162460
public void encodeSelf(ObjectOutput buf) throws IOException {
    buf.writeByte((byte) type);
    switch (type) {
    case STRING:
      buf.writeUTF((String) value);
      return;
    case LONG:
      buf.writeLong(((Long) value).longValue()); // was NumericValue
      return;
    case DOUBLE:
      buf.writeDouble(((Double) value).doubleValue()); // was NumericValue
      return;
    case INT:
      buf.writeInt(((Integer) value).intValue()); // was NumericValue
      return;
    case FLOAT:
      buf.writeFloat(((Float) value).floatValue()); // was NumericValue
      return;
    case BOOLEAN:
      buf.writeBoolean(((Boolean) value).booleanValue()); // was BooleanValue
      return;
    case OBJECT:
      buf.writeObject(value);
    default:
      throw new IllegalStateException();
    }
  }
1327504
public static void writeRawVarint64(OutputStream os, long value) throws IOException {
        while (true) {
            if ((value & ~0x7FL) == 0) {
                os.write((int) value);
                return;
            } else {
                os.write(((int) value & 0x7F) | 0x80);
                value >>>= 7;
            }
        }
    }
1311993
public static void writeString(String value, ByteBuffer buf) {
        if (value == null) {
            buf.putInt(VoltType.NULL_STRING_LENGTH);
            return;
        }

        byte[] strbytes = value.getBytes(Constants.UTF8ENCODING);
        int len = strbytes.length;

        buf.putInt(len);
        buf.put(strbytes);
    }
260309
def pyrdf2(value, class_type=None, datatype=None, lang=None, **kwargs):
    
    try:

        if isinstance(value, dict):
            # test to see if the type is a literal, a literal will have a another
            # dictionary key call datatype. Feed the datatype to the lookup to
            # return the value else convert it to a XsdString
            if value.get('type') == "literal":
                if not value.get("datatype"):
                    return XsdString(value['value'])
                else:
                    try:
                        if value.get("lang"):
                            # The lang keyword only applies to XsdString types
                            return DT_LOOKUP[value['datatype']](value['value'],
                                    lang=value.get("lang"))
                        else:
                            return DT_LOOKUP[value['datatype']](value['value'])
                    except:
                        rtn_val = BaseRdfDataType(value['value'])
                        rtn_val.datatype = Uri(value['datatype'])
                        return rtn_val
            else:
                return DT_LOOKUP[value['type']](value['value'])
        elif isinstance(value, BaseRdfDataType):
            return value
        else:
            return DT_LOOKUP[type(value)](value)
    except:
        pdb.set_trace()
        pass
998476
def validate_rtype(self, value):
        

        if not value or value != self.rtype:
            msg = self.messages['rtype'].format(self.rtype, value)
            raise ValidationError(msg)
        return value
1095843
static String encodeRaw(TypeMirror type) {
    StringBuilder sb = new StringBuilder();
    return type.accept(RAW_ENCODING_TYPE_VISITOR, sb).toString();
  }