<commit_before>package riak

import (
	"fmt"
	"reflect"
	"time"

	rpbRiakDT "github.com/basho/riak-go-client/rpb/riak_dt"
	proto "github.com/golang/protobuf/proto"
)

// UpdateCounter
// DtUpdateReq
// DtUpdateResp

// UpdateCounterCommand is used to increment or decrement a counter data type in Riak KV
type UpdateCounterCommand struct {
	commandImpl
	Response *UpdateCounterResponse
	protobuf *rpbRiakDT.DtUpdateReq
}

// Name identifies this command
func (cmd *UpdateCounterCommand) Name() string {
	return "UpdateCounter"
}

func (cmd *UpdateCounterCommand) constructPbRequest() (proto.Message, error) {
	return cmd.protobuf, nil
}

func (cmd *UpdateCounterCommand) onSuccess(msg proto.Message) error {
	cmd.success = true
	if msg != nil {
		if rpbDtUpdateResp, ok := msg.(*rpbRiakDT.DtUpdateResp); ok {
			cmd.Response = &UpdateCounterResponse{
				GeneratedKey: string(rpbDtUpdateResp.GetKey()),
				CounterValue: rpbDtUpdateResp.GetCounterValue(),
			}
		} else {
			return fmt.Errorf("[UpdateCounterCommand] could not convert %v to DtUpdateResp", reflect.TypeOf(msg))
		}
	}
	return nil
}

func (cmd *UpdateCounterCommand) getRequestCode() byte {
	return rpbCode_DtUpdateReq
}

func (cmd *UpdateCounterCommand) getResponseCode() byte {
	return rpbCode_DtUpdateResp
}

func (cmd *UpdateCounterCommand) getResponseProtobufMessage() proto.Message {<commit_msg>Implement workaround for bug #31; ReturnBody is ignored<commit_after>package riak

import (
	"fmt"
	"reflect"
	"time"

	rpbRiakDT "github.com/basho/riak-go-client/rpb/riak_dt"
	rpbRiakKV "github.com/basho/riak-go-client/rpb/riak_kv"
	proto "github.com/golang/protobuf/proto"
)

// UpdateCounter
// DtUpdateReq
// DtUpdateResp

// UpdateCounterCommand is used to increment or decrement a counter data type in Riak KV
type UpdateCounterCommand struct {
	commandImpl
	Response *UpdateCounterResponse
	protobuf *rpbRiakDT.DtUpdateReq
}

// Name identifies this command
func (cmd *UpdateCounterCommand) Name() string {
	return "UpdateCounter"
}

func (cmd *UpdateCounterCommand) constructPbRequest() (proto.Message, error) {
	// workaround for bug #31
	if string(cmd.protobuf.GetType()) == "default" && cmd.protobuf.GetReturnBody() {
		return &rpbRiakKV.RpbCounterUpdateReq{
			Bucket:      cmd.protobuf.Bucket,
			Key:         cmd.protobuf.Key,
			Amount:      cmd.protobuf.Op.CounterOp.Increment,
			W:           cmd.protobuf.W,
			Dw:          cmd.protobuf.Dw,
			Pw:          cmd.protobuf.Pw,
			Returnvalue: cmd.protobuf.ReturnBody,
		}, nil
	}
	// end workaroundå
	return cmd.protobuf, nil
}

func (cmd *UpdateCounterCommand) onSuccess(msg proto.Message) error {
	cmd.success = true
	if msg != nil {
		if rpbDtUpdateResp, ok := msg.(*rpbRiakDT.DtUpdateResp); ok {
			cmd.Response = &UpdateCounterResponse{
				GeneratedKey: string(rpbDtUpdateResp.GetKey()),
				CounterValue: rpbDtUpdateResp.GetCounterValue(),
			}
		} else if rpbCounterUpdateResp, ok2 := msg.(*rpbRiakKV.RpbCounterUpdateResp); ok2 { // workaround for bug #31
			cmd.Response = &UpdateCounterResponse{
				CounterValue: rpbCounterUpdateResp.GetValue(),
			}
			// end workaround
		} else {
			return fmt.Errorf("[UpdateCounterCommand] could not convert %v to DtUpdateResp", reflect.TypeOf(msg))
		}
	}
	return nil
}

func (cmd *UpdateCounterCommand) getRequestCode() byte {
	// workaround for bug #31
	if string(cmd.protobuf.GetType()) == "default" && cmd.protobuf.GetReturnBody() {
		return rpbCode_RpbCounterUpdateReq
	}
	// end workaround
	return rpbCode_DtUpdateReq
}

func (cmd *UpdateCounterCommand) getResponseCode() byte {
	// workaround for bug #31
	if string(cmd.protobuf.GetType()) == "default" && cmd.protobuf.GetReturnBody() {
		return rpbCode_RpbCounterUpdateResp
	}
	// end workaround
	return rpbCode_DtUpdateResp
}

func (cmd *UpdateCounterCommand) getResponseProtobufMessage() proto.Message {
	// workaround for bug #31
	if string(cmd.protobuf.GetType()) == "default" && cmd.protobuf.GetReturnBody() {
		return &rpbRiakKV.RpbCounterUpdateResp{}
	}
	// end workaround
{'fraction_non_alphanumeric': 0.11149825783972125, 'fraction_numerical': 0.003484320557491289, 'mean_word_length': 4.453188602442334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6564126', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1331, 'n_words': 304}