<commit_before>// Copyright © 2015 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package gateway

import (
	"encoding/binary"
	"math/rand"
)

func genToken() []byte {
	b := make([]byte, 4)
	binary.BigEndian.PutUint32(b, rand.Uint32())
	return b[0:2]
}<commit_msg>[simulators.gateway] Add token generation method<commit_after>// Copyright © 2015 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.

package gateway

import (
	"bytes"
	"encoding/binary"
	"github.com/thethingsnetwork/core/lorawan/semtech"
	"math/rand"
)

func genToken() []byte {
	b := make([]byte, 4)
	binary.BigEndian.PutUint32(b, rand.Uint32())
	return b[0:2]
}

func ackToken(index int, packet semtech.Packet) [4]byte {
	buf := new(bytes.Buffer)
	var id byte
	if err := binary.Write(buf, binary.LittleEndian, uint16(index)); err != nil {
		id = 0xff
	} else {
		id = buf.Bytes()[0]
	}

	var kind byte
	switch packet.Identifier {
	case semtech.PUSH_ACK, semtech.PUSH_DATA:
		kind = 0x1
	case semtech.PULL_ACK, semtech.PULL_DATA, semtech.PULL_RESP:
		kind = 0x2
	}

	return [4]byte{id, kind, packet.Token[0], packet.Token[1]}
}
{'fraction_non_alphanumeric': 0.12937347436940602, 'fraction_numerical': 0.027664768104149716, 'mean_word_length': 4.189873417721519, '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': '7432006', 'n_tokens_mistral': 473, 'n_tokens_neox': 441, 'n_words': 132}