示例#1
0
/*
This method takes in an operand value and context and returns a value.
If the type of operand is missing then return it. Call MarshalJSON
to get the bytes, and then use Go's encoding/base64 package to
encode the bytes to string. Create a newValue using the string and
return it.
*/
func (this *Base64) Apply(context Context, operand value.Value) (value.Value, error) {
	if operand.Type() == value.MISSING {
		return operand, nil
	}

	bytes, _ := operand.MarshalJSON() // Ignore errors from BINARY values
	str := base64.StdEncoding.EncodeToString(bytes)
	return value.NewValue(str), nil
}
示例#2
0
func (this *cacheType) GetPrepared(value value.Value) (*Prepared, error) {
	json_bytes, err := value.MarshalJSON()
	if err != nil {
		return nil, err
	}
	key := makeKey(json_bytes)
	this.RLock()
	prepared := this.prepareds[key]
	this.RUnlock()
	return prepared, nil
}
示例#3
0
/*
This method returns a number value that represents the length of the bytes slice
returned by the MarshalJSON method cast to a float64 value.
*/
func (this *EncodedSize) Apply(context Context, arg value.Value) (value.Value, error) {
	bytes, _ := arg.MarshalJSON()
	return value.NewValue(float64(len(bytes))), nil
}
示例#4
0
/*
This method returns a Json encoded string by sing the MarshalJSON
method. The return bytes value is cast to a string and returned.
*/
func (this *EncodeJSON) Apply(context Context, arg value.Value) (value.Value, error) {
	bytes, _ := arg.MarshalJSON()
	return value.NewValue(string(bytes)), nil
}