Esempio n. 1
0
func makeVectorEntry(index int, args interface{}) (*scanVectorEntry, errors.Error) {
	data, is_map := args.(map[string]interface{})
	if !is_map {
		return nil, errors.NewServiceErrorTypeMismatch(SCAN_VECTOR, "array or map of { number, string }")
	}
	seqno, has_seqno := data["seqno"]
	if !has_seqno {
		return nil, errors.NewServiceErrorTypeMismatch(SCAN_VECTOR, "array or map of { number, string }")
	}
	seqno_val, is_number := seqno.(float64)
	if !is_number {
		return nil, errors.NewServiceErrorTypeMismatch(SCAN_VECTOR, "array or map of { number, string }")
	}
	uuid, has_uuid := data["uuid"]
	if !has_uuid {
		return nil, errors.NewServiceErrorTypeMismatch(SCAN_VECTOR, "array or map of { number, string }")
	}
	uuid_val, uuid_ok := uuid.(string)
	if !uuid_ok {
		return nil, errors.NewServiceErrorTypeMismatch(SCAN_VECTOR, "array or map of { number, string }")
	}
	return &scanVectorEntry{
		pos:  uint32(index),
		val:  uint64(seqno_val),
		uuid: uuid_val,
	}, nil
}
Esempio n. 2
0
func (this *jsonArgs) getScanVector() (timestamp.Vector, errors.Error) {
	var type_ok bool

	scan_vector_data_field, in_request := this.args[SCAN_VECTOR]
	if !in_request {
		return nil, nil
	}
	full_vector_data, type_ok := scan_vector_data_field.([]interface{})
	if type_ok {
		if len(full_vector_data) != SCAN_VECTOR_SIZE {
			return nil, errors.NewServiceErrorTypeMismatch(SCAN_VECTOR,
				fmt.Sprintf("array of %d entries", SCAN_VECTOR_SIZE))
		}
		entries := make([]timestamp.Entry, len(full_vector_data))
		for index, arg := range full_vector_data {
			nextEntry, err := makeVectorEntry(index, arg)
			if err != nil {
				return nil, err
			}
			entries[index] = nextEntry
		}
	}
	sparse_vector_data, type_ok := scan_vector_data_field.(map[string]interface{})
	if !type_ok {
		return nil, errors.NewServiceErrorTypeMismatch(SCAN_VECTOR, "array or map of { number, string }")
	}
	entries := make([]timestamp.Entry, len(sparse_vector_data))
	i := 0
	for key, arg := range sparse_vector_data {
		index, e := strconv.Atoi(key)
		if e != nil {
			return nil, errors.NewServiceErrorBadValue(e, SCAN_VECTOR)
		}
		nextEntry, err := makeVectorEntry(index, arg)
		if err != nil {
			return nil, err
		}
		entries[i] = nextEntry
		i = i + 1
	}
	return &scanVectorEntries{
		entries: entries,
	}, nil
}
Esempio n. 3
0
// helper function to get a string type argument
func (this *jsonArgs) getString(f string, dflt string) (string, errors.Error) {
	value_field, in_request := this.args[f]
	if !in_request {
		return dflt, nil
	}

	value, type_ok := value_field.(string)
	if !type_ok {
		return value, errors.NewServiceErrorTypeMismatch(f, "string")
	}
	return value, nil
}
Esempio n. 4
0
func (this *jsonArgs) getTristate(f string) (value.Tristate, errors.Error) {
	value_tristate := value.NONE
	value_field, in_request := this.args[f]
	if !in_request {
		return value_tristate, nil
	}

	b, type_ok := value_field.(bool)
	if !type_ok {
		return value_tristate, errors.NewServiceErrorTypeMismatch(f, "boolean")
	}

	value_tristate = value.ToTristate(b)
	return value_tristate, nil
}
Esempio n. 5
0
func (this *jsonArgs) getCredentials() ([]map[string]string, errors.Error) {
	var creds_data []map[string]string

	creds_field, in_request := this.args[CREDS]
	if !in_request {
		return creds_data, nil
	}

	creds_data, type_ok := creds_field.([]map[string]string)
	if !type_ok {
		return creds_data, errors.NewServiceErrorTypeMismatch(CREDS, "array of { user, pass }")
	}

	return creds_data, nil
}
Esempio n. 6
0
// makeFullVector is used when the request includes all entries
func makeFullVector(args []*restArg) (*scanVectorEntries, errors.Error) {
	if len(args) != SCAN_VECTOR_SIZE {
		return nil, errors.NewServiceErrorTypeMismatch(SCAN_VECTOR,
			fmt.Sprintf("array of %d entries", SCAN_VECTOR_SIZE))
	}
	entries := make([]timestamp.Entry, len(args))
	for i, arg := range args {
		entries[i] = &scanVectorEntry{
			pos:  uint32(i),
			val:  arg.Seqno,
			uuid: arg.Uuid,
		}
	}
	return &scanVectorEntries{
		entries: entries,
	}, nil
}
Esempio n. 7
0
func (this *jsonArgs) getPositionalArgs() (value.Values, errors.Error) {
	var positionalArgs value.Values

	args_field, in_request := this.args[ARGS]
	if !in_request {
		return positionalArgs, nil
	}

	args, type_ok := args_field.([]interface{})
	if !type_ok {
		return positionalArgs, errors.NewServiceErrorTypeMismatch(ARGS, "array")
	}

	positionalArgs = make([]value.Value, len(args))
	// Put each element of args into positionalArgs
	for i, arg := range args {
		positionalArgs[i] = value.NewValue(arg)
	}

	return positionalArgs, nil
}