Пример #1
0
func (c *Command) decodeSetCommand(msg protocol.Command) error {
	subCmd, err := msg.SubCommand().Set()
	if err != nil {
		return err
	}

	key, err := subCmd.Key()
	if err != nil {
		return err
	}

	value, err := subCmd.Value()
	if err != nil {
		return err
	}

	expiry := subCmd.Expiry()
	if err != nil {
		return err
	}

	c.SubCommand = NewSetCommand(key, value, expiry)
	c.Action = c.SubCommand.getAction()
	return nil
}
Пример #2
0
func (c HandshakeCommand) encode(root *protocol.Command, s *capnp.Segment) error {
	cmd, err := protocol.NewCommand_HandshakeCommand(s)
	if err != nil {
		return err
	}
	cmd.SetUserAgent(c.UserAgent)

	root.SubCommand().SetHandshake(cmd)
	return nil
}
Пример #3
0
func (c GetCommand) encode(root *protocol.Command, s *capnp.Segment) error {
	cmd, err := protocol.NewCommand_GetCommand(s)
	if err != nil {
		return err
	}
	cmd.SetKey(c.Key)

	root.SubCommand().SetGet(cmd)
	return nil
}
Пример #4
0
func (c SetCommand) encode(root *protocol.Command, s *capnp.Segment) error {
	cmd, err := protocol.NewCommand_SetCommand(s)
	if err != nil {
		return err
	}
	cmd.SetKey(c.Key)
	cmd.SetValue(c.Value)
	cmd.SetExpiry(c.Expiry)

	root.SubCommand().SetSet(cmd)
	return nil
}
Пример #5
0
func (c *Command) decodeHandshakeCommand(msg protocol.Command) error {
	subCmd, err := msg.SubCommand().Handshake()
	if err != nil {
		return err
	}

	userAgent, err := subCmd.UserAgent()
	if err != nil {
		return err
	}

	c.SubCommand = NewHandshakeCommand(userAgent)
	c.Action = c.SubCommand.getAction()
	return nil
}
Пример #6
0
func (c *Command) decodeGetCommand(msg protocol.Command) error {
	getCmd, err := msg.SubCommand().Get()
	if err != nil {
		return err
	}

	key, err := getCmd.Key()
	if err != nil {
		return err
	}

	c.SubCommand = NewGetCommand(key)
	c.Action = c.SubCommand.getAction()
	return nil
}