<commit_before>package generator

const byteWriterInterface = `
type ByteWriter interface {
	Grow(int)
	WriteByte(byte) error
} 
`

const writeBoolMethod = `

func writeBool(r bool, w io.Writer) error {
	var b byte
	if r {
		b = byte(1)
	}

	var err error
	if bw, ok := w.(ByteWriter); ok {
		err = bw.WriteByte(b)
	} else {
		bb := make([]byte, 1)
		bb[0] = b
		_, err = w.Write(bb)
	}
	if err != nil {
		return err
	}
	return nil
}
`

const readBoolMethod = `
func readBool(r io.Reader) (bool, error) {
	b := make([]byte, 1)
	_, err := r.Read(b)
	if err != nil {
		return false, err
	}
	return b[0] == 1, nil
}
`

type boolField struct {
	name         string
	defaultValue bool
	hasDefault   bool
}

func (s *boolField) Name() string {
	return toPublicName(s.name)
}

func (s *boolField) FieldType() string {
	return "Bool"
}

func (s *boolField) GoType() string {
	return "bool"
}

func (s *boolField) SerializerMethod() string {
	return "writeBool"
}

func (s *boolField) DeserializerMethod() string {
	return "readBool"
}

func (s *boolField) AddStruct(*Package) {}

func (s *boolField) AddSerializer(p *Package) {
	p.addStruct(UTIL_FILE, "ByteWriter", byteWriterInterface)
	p.addFunction(UTIL_FILE, "", "writeBool", writeBoolMethod)
	p.addImport(UTIL_FILE, "io")
}

func (s *boolField) AddDeserializer(p *Package) {
	p.addFunction(UTIL_FILE, "", "readBool", readBoolMethod)
	p.addImport(UTIL_FILE, "io")
}
<commit_msg>Add ByteReader cast for booleans<commit_after>package generator

const byteWriterInterface = `
type ByteWriter interface {
	Grow(int)
	WriteByte(byte) error
} 
`

const byteReaderInterface = `
type ByteReader interface {
	ReadByte() (byte, error)
} 
`

const writeBoolMethod = `

func writeBool(r bool, w io.Writer) error {
	var b byte
	if r {
		b = byte(1)
	}

	var err error
	if bw, ok := w.(ByteWriter); ok {
		err = bw.WriteByte(b)
	} else {
		bb := make([]byte, 1)
		bb[0] = b
		_, err = w.Write(bb)
	}
	if err != nil {
		return err
	}
	return nil
}
`

const readBoolMethod = `
func readBool(r io.Reader) (bool, error) {
	var b byte
	var err error
	if br, ok := r.(ByteReader); ok {
		b, err = br.ReadByte()
	} else {
		bs := make([]byte, 1)
		_, err = io.ReadFull(r, bs)
		if err != nil {
			return false, err
		}
		b = bs[0]
	}
	return b == 1, nil
}
`

type boolField struct {
	name         string
	defaultValue bool
	hasDefault   bool
}

func (s *boolField) Name() string {
	return toPublicName(s.name)
}

func (s *boolField) FieldType() string {
	return "Bool"
}

func (s *boolField) GoType() string {
	return "bool"
}

func (s *boolField) SerializerMethod() string {
	return "writeBool"
}

func (s *boolField) DeserializerMethod() string {
	return "readBool"
}

func (s *boolField) AddStruct(*Package) {}

func (s *boolField) AddSerializer(p *Package) {
	p.addStruct(UTIL_FILE, "ByteWriter", byteWriterInterface)
	p.addFunction(UTIL_FILE, "", "writeBool", writeBoolMethod)
	p.addImport(UTIL_FILE, "io")
}

func (s *boolField) AddDeserializer(p *Package) {
	p.addStruct(UTIL_FILE, "ByteReader", byteReaderInterface)
	p.addFunction(UTIL_FILE, "", "readBool", readBoolMethod)
	p.addImport(UTIL_FILE, "io")
}

{'fraction_non_alphanumeric': 0.14144632048423064, 'fraction_numerical': 0.003822873526600828, 'mean_word_length': 3.9920508744038155, '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': '3990211', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1203, 'n_words': 319}