<commit_before>package gocbcore

import (
	"encoding/binary"
)

// **INTERNAL**
// Stores a document along with setting some internal Couchbase meta-data.
func (c *Agent) SetMeta(key, value, extra []byte, options, flags, expiry uint32, cas, revseqno uint64, cb StoreCallback) (PendingOp, error) {
	handler := func(resp *memdResponse, err error) {
		if err != nil {
			cb(0, MutationToken{}, err)
			return
		}

		mutToken := MutationToken{}
		if len(resp.Extras) >= 16 {
			mutToken.VbUuid = VbUuid(binary.BigEndian.Uint64(resp.Extras[0:]))
			mutToken.SeqNo = SeqNo(binary.BigEndian.Uint64(resp.Extras[8:]))
		}

		cb(Cas(resp.Cas), mutToken, nil)
	}

	extraBuf := make([]byte, 30+len(extra))
	binary.BigEndian.PutUint32(extraBuf[0:], flags)
	binary.BigEndian.PutUint32(extraBuf[4:], expiry)
	binary.BigEndian.PutUint64(extraBuf[8:], revseqno)
	binary.BigEndian.PutUint64(extraBuf[16:], cas)
	binary.BigEndian.PutUint32(extraBuf[24:], options)
	binary.BigEndian.PutUint16(extraBuf[28:], uint16(len(extra)))
	copy(extraBuf[26:], extra)
	req := &memdQRequest{
		memdRequest: memdRequest{
			Magic:    ReqMagic,
			Opcode:   CmdSetMeta,
			Datatype: 0,
			Cas:      0,
			Extras:   extraBuf,
			Key:      key,
			Value:    value,
		},
		Callback: handler,
	}
	return c.dispatchOp(req)
}

// **INTERNAL**
// Deletes a document along with setting some internal Couchbase meta-data.
func (c *Agent) DeleteMeta(key, extra []byte, options, flags, expiry uint32, cas, revseqno uint64, cb RemoveCallback) (PendingOp, error) {
	handler := func(resp *memdResponse, err error) {
		if err != nil {
			cb(0, MutationToken{}, err)
			return
		}

		mutToken := MutationToken{}
		if len(resp.Extras) >= 16 {
			mutToken.VbUuid = VbUuid(binary.BigEndian.Uint64(resp.Extras[0:]))
			mutToken.SeqNo = SeqNo(binary.BigEndian.Uint64(resp.Extras[8:]))
		}

		cb(Cas(resp.Cas), mutToken, nil)
	}

	extraBuf := make([]byte, 26+len(extra))
	binary.BigEndian.PutUint32(extraBuf[0:], flags)
	binary.BigEndian.PutUint32(extraBuf[4:], expiry)
	binary.BigEndian.PutUint64(extraBuf[8:], revseqno)
	binary.BigEndian.PutUint64(extraBuf[16:], cas)
	binary.BigEndian.PutUint32(extraBuf[24:], options)
	binary.BigEndian.PutUint16(extraBuf[28:], uint16(len(extra)))
	copy(extraBuf[26:], extra)
	req := &memdQRequest{
		memdRequest: memdRequest{
			Magic:    ReqMagic,
			Opcode:   CmdDelMeta,
			Datatype: 0,
			Cas:      0,
			Extras:   extraBuf,
			Key:      key,
			Value:    nil,
		},
		Callback: handler,
	}
	return c.dispatchOp(req)<commit_msg>MB-21942: Fix incorrect buffer size in set/del meta<commit_after>package gocbcore

import (
	"encoding/binary"
)

// **INTERNAL**
// Stores a document along with setting some internal Couchbase meta-data.
func (c *Agent) SetMeta(key, value, extra []byte, options, flags, expiry uint32, cas, revseqno uint64, cb StoreCallback) (PendingOp, error) {
	handler := func(resp *memdResponse, err error) {
		if err != nil {
			cb(0, MutationToken{}, err)
			return
		}

		mutToken := MutationToken{}
		if len(resp.Extras) >= 16 {
			mutToken.VbUuid = VbUuid(binary.BigEndian.Uint64(resp.Extras[0:]))
			mutToken.SeqNo = SeqNo(binary.BigEndian.Uint64(resp.Extras[8:]))
		}

		cb(Cas(resp.Cas), mutToken, nil)
	}

	extraBuf := make([]byte, 30+len(extra))
	binary.BigEndian.PutUint32(extraBuf[0:], flags)
	binary.BigEndian.PutUint32(extraBuf[4:], expiry)
	binary.BigEndian.PutUint64(extraBuf[8:], revseqno)
	binary.BigEndian.PutUint64(extraBuf[16:], cas)
	binary.BigEndian.PutUint32(extraBuf[24:], options)
	binary.BigEndian.PutUint16(extraBuf[28:], uint16(len(extra)))
	copy(extraBuf[30:], extra)
	req := &memdQRequest{
		memdRequest: memdRequest{
			Magic:    ReqMagic,
			Opcode:   CmdSetMeta,
			Datatype: 0,
			Cas:      0,
			Extras:   extraBuf,
			Key:      key,
			Value:    value,
		},
		Callback: handler,
	}
	return c.dispatchOp(req)
}

// **INTERNAL**
// Deletes a document along with setting some internal Couchbase meta-data.
func (c *Agent) DeleteMeta(key, extra []byte, options, flags, expiry uint32, cas, revseqno uint64, cb RemoveCallback) (PendingOp, error) {
	handler := func(resp *memdResponse, err error) {
		if err != nil {
			cb(0, MutationToken{}, err)
			return
		}

		mutToken := MutationToken{}
		if len(resp.Extras) >= 16 {
			mutToken.VbUuid = VbUuid(binary.BigEndian.Uint64(resp.Extras[0:]))
			mutToken.SeqNo = SeqNo(binary.BigEndian.Uint64(resp.Extras[8:]))
		}

		cb(Cas(resp.Cas), mutToken, nil)
	}

	extraBuf := make([]byte, 30+len(extra))
	binary.BigEndian.PutUint32(extraBuf[0:], flags)
	binary.BigEndian.PutUint32(extraBuf[4:], expiry)
	binary.BigEndian.PutUint64(extraBuf[8:], revseqno)
	binary.BigEndian.PutUint64(extraBuf[16:], cas)
	binary.BigEndian.PutUint32(extraBuf[24:], options)
	binary.BigEndian.PutUint16(extraBuf[28:], uint16(len(extra)))
	copy(extraBuf[30:], extra)
	req := &memdQRequest{
		memdRequest: memdRequest{
			Magic:    ReqMagic,
			Opcode:   CmdDelMeta,
			Datatype: 0,
			Cas:      0,
			Extras:   extraBuf,
			Key:      key,
			Value:    nil,
		},
		Callback: handler,
	}
	return c.dispatchOp(req)
{'fraction_non_alphanumeric': 0.1499407348873963, 'fraction_numerical': 0.03417621493480837, 'mean_word_length': 4.3976545842217485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3840748', 'n_tokens_mistral': 2183, 'n_tokens_neox': 1938, 'n_words': 380}