Esempio n. 1
0
// Function for parsing of storage group of commands.
// Receives array of string tokens.
// Returns pointer to Ascii_protocol_enum with bound fields.
func parseStorageCommands(args []string /*, data_block string*/) *Ascii_protocol_enum {
	protocol := new(Ascii_protocol_enum)
	if len(args) < 5 || /*len(data_block) == 0 ||*/ tools.In("", args) {
		return &Ascii_protocol_enum{error: ERROR_TEMP}
	}
	var err error
	//protocol.data_string = []byte(data_block)
	protocol.command = args[0]
	protocol.key = []string{args[1]}
	protocol.flags, err = tools.StringToInt32(args[2])
	protocol.exptime, err = tools.StringToInt64(args[3])
	protocol.exptime = tools.ToTimeStampFromNow(protocol.exptime)
	protocol.bytes, err = tools.StringToInt32(args[4])
	if args[0] == "cas" {
		if len(args) < 6 {
			err = errors.New("invalid arguments number")
		}
		protocol.cas_unique, err = tools.StringToInt64(args[5])
		if len(args) == 7 {
			protocol.noreply = (args[6] == "noreply")
		}
	} else {
		if len(args) == 6 {
			protocol.noreply = (args[5] == "noreply")
		}
	}
	if err != nil {
		return &Ascii_protocol_enum{error: ERROR_TEMP}
	}
	return protocol
}
Esempio n. 2
0
// Function for parsing of other group of commands.
// Receives array of string tokens.
// Returns pointer to Ascii_protocol_enum with bound fields.
func parseOtherCommands(args []string) *Ascii_protocol_enum {
	protocol := new(Ascii_protocol_enum)
	var err error
	err = nil
	if tools.In("", args) {
		err = errors.New("invalid arguments")
	}
	protocol.command = args[0]
	protocol.noreply = (args[len(args)-1] == "noreply")
	switch args[0] {
	case "delete":
		if len(args) < 2 {
			err = errors.New("invalid arguments number")
		} else {
			protocol.key = []string{args[1]}
		}
	case "touch":
		if len(args) < 3 {
			err = errors.New("invalid arguments number")
		} else {
			protocol.key = []string{args[1]}
			protocol.exptime, err = tools.StringToInt64(args[2])
		}
	case "flush_all":
		if len(args) >= 2 {
			protocol.exptime, err = tools.StringToInt64(args[1])
		}
	case "incr", "decr":
		if len(args) < 3 {
			err = errors.New("invalid arguments number")
		} else {
			protocol.key = []string{args[1]}
			protocol.data_string = []byte(args[2])
		}
		protocol.noreply = (args[len(args)-1] == "noreply")
	case "stats":
		protocol.key = args[1:]
	case "lru_crawler":
		if len(args) < 2 {
			err = errors.New("invalid arguments number")
		} else {
			protocol.key = args[1:]
		}
	}

	protocol.exptime = tools.ToTimeStampFromNow(protocol.exptime)
	if err != nil {
		return &Ascii_protocol_enum{error: ERROR_TEMP}
	}
	return protocol
}