<commit_before>// Package command provides commands for querying both, server and client.
package command

import (
	"encoding/json"
	"gofire/message"
	"gofire/user"
)

type CommandType int

const (
	REGISTER CommandType = iota //Register a user
	//Text-Messaging Commands
	BMESSAGE //Broadcast-Message
	UMESSAGE //Unicast-Message
	MMESSAGE //Multicast-Message
	//System Commands
	BLOGIN  //Broadcast-Login
	BLOGOUT //Broadcast-Logout
)

//Every Command has a type and a value for sending arbitrary data.
type Command struct {
	Type  CommandType
	Value []byte
}

//This Function wraps a message in a command.
//This is a shortcut.
//If something went wrong, nil and a error are returned.
func PrepareMessage(tp CommandType, usr *user.User, msg []byte) (*Command, error) {
	mMessage, err := json.Marshal(message.Message{User: usr, Msg: msg})
	if err != nil {
		return nil, err
	}

	return &Command{tp, mMessage}, nil
}
//This Function wraps everything into a Command.
//It returns either nil and a error or a command pointer and nil
func Wrap(tp CommandType, v interface{}) (*Command, error){
	mStruct, err := json.Marshal(v)
	if err != nil {
		return nil, err
	}

	return &Command{tp, mStruct}, nil
}<commit_msg>comment<commit_after>// Package command provides commands for querying both, server and client.
package command

import (
	"encoding/json"
	"gofire/message"
	"gofire/user"
)

type CommandType int

const (
	REGISTER CommandType = iota //Register a user
	//Text-Messaging Commands
	BMESSAGE //Broadcast-Message
	UMESSAGE //Unicast-Message
	MMESSAGE //Multicast-Message
	//System Commands
	BLOGIN  //Broadcast-Login
	BLOGOUT //Broadcast-Logout
)

//Every Command has a type and a value for sending arbitrary data.
type Command struct {
	Type  CommandType
	Value []byte
}

//This Function wraps a message in a command.
//This is a shortcut for Wrap.
//If something went wrong, nil and a error are returned.
func PrepareMessage(tp CommandType, usr *user.User, msg []byte) (*Command, error) {
	mMessage, err := json.Marshal(message.Message{User: usr, Msg: msg})
	if err != nil {
		return nil, err
	}

	return &Command{tp, mMessage}, nil
}
//This Function wraps everything into a Command.
//It returns either nil and a error or a command pointer and nil
func Wrap(tp CommandType, v interface{}) (*Command, error){
	mStruct, err := json.Marshal(v)
	if err != nil {
		return nil, err
	}

	return &Command{tp, mStruct}, nil
}
{'fraction_non_alphanumeric': 0.10548001648125258, 'fraction_numerical': 0.0, 'mean_word_length': 3.885311871227364, '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': '2336517', 'n_tokens_mistral': 782, 'n_tokens_neox': 770, 'n_words': 296}