<commit_before>package class

import (
	"encoding/binary"
	"io"
)

var byteOrder = binary.BigEndian

var initFuncs = []func(*ClassFile, io.Reader) error{
	(*ClassFile).readMagic,
	(*ClassFile).readVersion,
	(*ClassFile).readConstPool,
}

const (
	ConstUTF8               ConstInfoTag = 1
	ConstInteger                         = 3
	ConstFloat                           = 4
	ConstLong                            = 5
	ConstDouble                          = 6
	ConstClass                           = 7
	ConstString                          = 8
	ConstFieldRef                        = 9
	ConstMethodRef                       = 10
	ConstInterfaceMehtodRef              = 11
	ConstNameAndType                     = 12
	ConstMethodHandle                    = 15
	ConstMethodType                      = 16
	ConstInvokeDynamik                   = 18
)

func Parse(r io.Reader) (*ClassFile, error) {
	c := &ClassFile{}

	var err error

	for _, f := range initFuncs {
		err = f(c, r)
		if err != nil {
			return nil, err
		}
	}

	return c, nil
}

func (c *ClassFile) readMagic(r io.Reader) error {
	return binary.Read(r, byteOrder, &c.Magic)
}

func (c *ClassFile) readVersion(r io.Reader) error {
	err := binary.Read(r, byteOrder, &c.MinorVersion)
	if err != nil {
		return err
	}

	return binary.Read(r, byteOrder, &c.MajorVersion)
}

func (c *ClassFile) readConstPool(r io.Reader) error {
	err := binary.Read(r, byteOrder, &c.ConstPoolSize)
	if err != nil {
		return err
	}

	c.ConstPool = make([]*ConstInfo, 0, c.ConstPoolSize)

	for i := uint16(1); i < c.ConstPoolSize; i++ {
		info, err := c.readConstInfo(r)
		if err != nil {
			return err
		}

		c.ConstPool = append(c.ConstPool, info)
	}

	return nil
}

func (c *ClassFile) readConstInfo(r io.Reader) (*ConstInfo, error) {
	info := &ConstInfo{}

	err := binary.Read(r, byteOrder, &info.Tag)
	if err != nil {
		return nil, err
	}

	switch info.Tag {
	case ConstClass:
		panic("hello!")
	}
	return nil, nil
}<commit_msg>Implemented cp_info struct parsing.<commit_after>package class

import (
	"encoding/binary"
	"io"
)

var byteOrder = binary.BigEndian

var initFuncs = []func(*ClassFile, io.Reader) error{
	(*ClassFile).readMagic,
	(*ClassFile).readVersion,
	(*ClassFile).readConstPool,
}

const (
	ConstUTF8               ConstInfoTag = 1
	ConstInteger                         = 3
	ConstFloat                           = 4
	ConstLong                            = 5
	ConstDouble                          = 6
	ConstClass                           = 7
	ConstString                          = 8
	ConstFieldRef                        = 9
	ConstMethodRef                       = 10
	ConstInterfaceMehtodRef              = 11
	ConstNameAndType                     = 12
	ConstMethodHandle                    = 15
	ConstMethodType                      = 16
	ConstInvokeDynamic                   = 18
)

func Parse(r io.Reader) (*ClassFile, error) {
	c := &ClassFile{}

	var err error

	for _, f := range initFuncs {
		err = f(c, r)
		if err != nil {
			return nil, err
		}
	}

	return c, nil
}

func (c *ClassFile) readMagic(r io.Reader) error {
	return binary.Read(r, byteOrder, &c.Magic)
}

func (c *ClassFile) readVersion(r io.Reader) error {
	err := binary.Read(r, byteOrder, &c.MinorVersion)
	if err != nil {
		return err
	}

	return binary.Read(r, byteOrder, &c.MajorVersion)
}

func (c *ClassFile) readConstPool(r io.Reader) error {
	err := binary.Read(r, byteOrder, &c.ConstPoolSize)
	if err != nil {
		return err
	}

	c.ConstPool = make([]*ConstInfo, 0, c.ConstPoolSize)

	for i := uint16(1); i < c.ConstPoolSize; i++ {
		info, err := c.readConstInfo(r)
		if err != nil {
			return err
		}

		c.ConstPool = append(c.ConstPool, info)
	}

	return nil
}

func (c *ClassFile) readConstInfo(r io.Reader) (*ConstInfo, error) {
	info := &ConstInfo{}

	err := binary.Read(r, byteOrder, &info.Tag)
	if err != nil {
		return nil, err
	}

	bytesToRead := uint16(0)
	switch info.Tag {
	case ConstClass, ConstString, ConstMethodType:
		bytesToRead = 2

	case ConstMethodHandle:
		bytesToRead = 3

	case ConstFieldRef, ConstMethodRef,
		ConstInterfaceMehtodRef, ConstInteger,
		ConstFloat, ConstNameAndType, ConstInvokeDynamic:
		bytesToRead = 4

	case ConstLong, ConstDouble:
		bytesToRead = 8

	case ConstUTF8:
		err = binary.Read(r, byteOrder, &bytesToRead)
		if err != nil {
			return nil, err
		}

	default:
		panic("unknown tag in class file!")
	}

	info.Info = make([]uint8, bytesToRead)

	err = binary.Read(r, byteOrder, &info.Info)
	if err != nil {
		return nil, err
	}

	return info, nil
}
{'fraction_non_alphanumeric': 0.1114052503860578, 'fraction_numerical': 0.013015662916390912, 'mean_word_length': 2.1862262825017567, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4251910', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1500, 'n_words': 390}