<commit_before>package socketio

import (
	"errors"
	"strconv"
	"strings"
)

type IOMessage struct {
	Type     int
	Id       string
	Endpoint *Endpoint
	Data     string
}

func NewIOMessage(rawMsg string) (*IOMessage, error) {
	if len(rawMsg) == 0 {
		return nil, errors.New("Empty message")
	}

	msgType, err := strconv.Atoi(string(rawMsg[0]))
	if err != nil {
		return nil, err
	}

	switch msgType {
	case 3, 4, 5:
		parts := strings.SplitN(rawMsg, ":", 4)
		id := parts[1]
		return &IOMessage{msgType, id, nil, parts[3]}, nil
	default:
		return &IOMessage{Type: msgType}, nil
	}
}

func (m IOMessage) String() string {
	raw := strconv.Itoa(m.Type)

	raw += ":" + m.Id

	raw += ":"
	if m.Endpoint != nil {
		raw += m.Endpoint.String()
	}

	if m.Data != "" {
		raw += ":" + m.Data
	}

	return raw
}

func NewDisconnect() *IOMessage {
	return &IOMessage{Type: 0}
}

func NewConnect(endpoint *Endpoint) *IOMessage {
	return &IOMessage{Type: 1, Endpoint: endpoint}
}

func NewHeartbeat() *IOMessage {
	return &IOMessage{Type: 2}
}

func NewMessage(endpoint *Endpoint, data string) *IOMessage {
	return &IOMessage{Type: 3, Endpoint: endpoint, Data: data}
}

func NewJSONMessage(endpoint *Endpoint, data string) *IOMessage {
	return &IOMessage{Type: 4, Endpoint: endpoint, Data: data}
}

func NewEvent(endpoint *Endpoint, data string) *IOMessage {
	return &IOMessage{Type: 5, Endpoint: endpoint, Data: data}
}

func NewACK(endpoint *Endpoint, data string) *IOMessage {
	return &IOMessage{Type: 6, Endpoint: endpoint, Data: data}
}

func NewError(endpoint *Endpoint, data string) *IOMessage {
	return &IOMessage{Type: 7, Endpoint: endpoint, Data: data}
}

func NewNoop() *IOMessage {
	return &IOMessage{Type: 8}
}<commit_msg>Improve IOMessage creators<commit_after>package socketio

import (
	"errors"
	"strconv"
	"strings"
)

type IOMessage struct {
	Type     int
	Id       string
	Endpoint *Endpoint
	Data     string
}

func NewIOMessage(rawMsg string) (*IOMessage, error) {
	if len(rawMsg) == 0 {
		return nil, errors.New("Empty message")
	}

	msgType, err := strconv.Atoi(string(rawMsg[0]))
	if err != nil {
		return nil, err
	}

	switch msgType {
	case 3, 4, 5:
		parts := strings.SplitN(rawMsg, ":", 4)
		id := parts[1]
		return &IOMessage{msgType, id, nil, parts[3]}, nil
	default:
		return &IOMessage{Type: msgType}, nil
	}
}

func (m IOMessage) String() string {
	raw := strconv.Itoa(m.Type)

	raw += ":" + m.Id

	raw += ":"
	if m.Endpoint != nil {
		raw += m.Endpoint.String()
	}

	if m.Data != "" {
		raw += ":" + m.Data
	}

	return raw
}

func NewDisconnect() *IOMessage {
	return &IOMessage{Type: 0}
}

func NewConnect(endpoint *Endpoint) *IOMessage {
	return &IOMessage{Type: 1, Endpoint: endpoint}
}

func NewHeartbeat() *IOMessage {
	return &IOMessage{Type: 2}
}

func NewMessage(endpoint *Endpoint, msg string) *IOMessage {
	return &IOMessage{Type: 3, Endpoint: endpoint, Data: msg}
}

func NewJSONMessage(endpoint *Endpoint, data string) *IOMessage {
	return &IOMessage{Type: 4, Endpoint: endpoint, Data: data}
}

func NewEvent(endpoint *Endpoint, name string, args string) *IOMessage {
	return &IOMessage{Type: 5, Endpoint: endpoint, Data: args}
}

func NewACK(data string) *IOMessage {
	return &IOMessage{Type: 6, Data: data}
}

func NewError(endpoint *Endpoint, reason string, advice string) *IOMessage {
	return &IOMessage{Type: 7, Endpoint: endpoint, Data: reason + advice}
}

func NewNoop() *IOMessage {
	return &IOMessage{Type: 8}
}
{'fraction_non_alphanumeric': 0.14223638470451913, 'fraction_numerical': 0.009849362688296639, 'mean_word_length': 4.3534883720930235, 'pattern_counts': {'":': 8, '<': 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': '6216645', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1285, 'n_words': 349}