<commit_before>package teff

import (
	"bytes"
	"fmt"
	"h12.me/teff/core"
	"reflect"
	"strconv"
)

func Marshal(v interface{}) ([]byte, error) {
	if v == nil {
		return []byte("nil"), nil
	}
	list, err := marshalList(reflectValue(reflect.ValueOf(v)))
	if err != nil {
		return nil, err
	}
	return list.Marshal("", "\t")
}

func Unmarshal(data []byte, v interface{}) error {
	if string(data) == "nil" {
		return nil
	}
	list, err := core.Parse(bytes.NewBuffer(data))
	if err != nil {
		return err
	}
	return unmarshalList(list, reflect.ValueOf(v))
}

func marshalList(v reflect.Value) (core.List, error) {
	switch v.Type().Kind() {
	case reflect.Int, reflect.String:<commit_msg>add MarshalIndent.<commit_after>package teff

import (
	"bytes"
	"fmt"
	"h12.me/teff/core"
	"reflect"
	"strconv"
)

func Marshal(v interface{}) ([]byte, error) {
	return MarshalIndent(v, "", "\t")
}

func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
	if v == nil {
		return []byte("nil"), nil
	}
	list, err := marshalList(reflectValue(reflect.ValueOf(v)))
	if err != nil {
		return nil, err
	}
	return list.Marshal(prefix, indent)
}

func Unmarshal(data []byte, v interface{}) error {
	if string(data) == "nil" {
		return nil
	}
	list, err := core.Parse(bytes.NewBuffer(data))
	if err != nil {
		return err
	}
	return unmarshalList(list, reflect.ValueOf(v))
}

func marshalList(v reflect.Value) (core.List, error) {
	switch v.Type().Kind() {
	case reflect.Int, reflect.String:
{'fraction_non_alphanumeric': 0.17320703653585928, 'fraction_numerical': 0.0027063599458728013, 'mean_word_length': 4.301075268817204, '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': '5575872', 'n_tokens_mistral': 571, 'n_tokens_neox': 556, 'n_words': 137}