You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: marshal.go
    path of file: ./repos/octant/vendor/github.com/pelletier/go-toml
    
    the code of the file until where you have to start completion: package toml

import (
	"bytes"
	"encoding"
	"errors"
	"fmt"
	"io"
	"reflect"
	"sort"
	"strconv"
	"strings"
	"time"
)

const (
	tagFieldName    = "toml"
	tagFieldComment = "comment"
	tagCommented    = "commented"
	tagMultiline    = "multiline"
	tagLiteral      = "literal"
	tagDefault      = "default"
)

type tomlOpts struct {
	name         string
	nameFromTag  bool
	comment      string
	commented    bool
	multiline    bool
	literal      bool
	include      bool
	omitempty    bool
	defaultValue string
}

type encOpts struct {
	quoteMapKeys            bool
	arraysOneElementPerLine bool
}

var encOptsDefaults = encOpts{
	quoteMapKeys: false,
}

type annotation struct {
	tag          string
	comment      string
	commented    string
	multiline    string
	literal      string
	defaultValue string
}

var annotationDefault = annotation{
	tag:          tagFieldName,
	comment:      tagFieldComment,
	commented:    tagCommented,
	multiline:    tagMultiline,
	literal:      tagLiteral,
	defaultValue: tagDefault,
}

type MarshalOrder int

// Orders the Encoder can write the fields to the output stream.
const (
	// Sort fields alphabetically.
	OrderAlphabetical MarshalOrder = iota + 1
	// Preserve the order the fields are encountered. For example, the order of fields in
	// a struct.
	OrderPreserve
)

var timeType = reflect.TypeOf(time.Time{})
var marshalerType = reflect.TypeOf(new(Marshaler)).Elem()
var unmarshalerType = reflect.TypeOf(new(Unmarshaler)).Elem()
var textMarshalerType = reflect.TypeOf(new(encoding.TextMarshaler)).Elem()
var textUnmarshalerType = reflect.TypeOf(new(encoding.TextUnmarshaler)).Elem()
var localDateType = reflect.TypeOf(LocalDate{})
var localTimeType = reflect.TypeO
    
func (e *Encoder) valueToTree(mtype reflect.Type, mval reflect.Value) (*Tree, error) {
	if mtype.Kind() == reflect.Ptr {
		return e.valueToTree(mtype.Elem(), mval.Elem())
	}
	tval := e.nextTree()
	switch mtype.Kind() {
	case reflect.Struct:
		switch mval.Interface().(type) {
		case Tree:
			reflect.ValueOf(tval).Elem().Set(mval)
		default:
			for i := 0; i < mtype.NumField(); i++ {
				mtypef, mvalf := mtype.Field(i), mval.Field(i)
				opts := tomlOptions(mtypef, e.annotation)
				if opts.include && ((mtypef.Type.Kind() != reflect.Interface && !opts.omitempty) || !isZero(mvalf)) {
					val, err := e.valueToToml(mtypef.Type, mvalf)
					if err != nil {
						return nil, err
					}
					if tree, ok := val.(*Tree); ok && mtypef.Anonymous && !opts.nameFromTag && !e.promoteAnon {
						e.appendTree(tval, tree)
					} else {
						val = e.wrapTomlValue(val, tval)
						tval.SetPathWithOptions([]string{opts.name}, SetOptions{
							Comment:   opts.comment,
							Commented: opts.commented,
							Multiline: opts.multiline,
							Literal:   opts.literal,
						}, val)
					}
				}
			}
		}
	case reflect.Map:
		keys := mval.MapKeys()
		if e.order == OrderPreserve && len(keys) > 0 {
			// Sorting []reflect.Value is not straight forward.
			//
			// OrderPreserve will support deterministic results when string is used
			// as the key to maps.
			typ := keys[0].Type()
			kind := keys[0].Kind()
			if kind == reflect.String {
				ikeys := make([]string, len(keys))
				for i := range keys {
					ikeys[i] = keys[i].Interface().(string)
				}
				sort.Strings(ikeys)
				for i := range ikeys {
					keys[i] = reflect.ValueOf(ikeys[i]).Convert(typ)
				}
			}
		}
		for _, key := range keys {
			mvalf := mval.MapIndex(key)
			if (mtype.Elem().Kind() == reflect.Ptr || mtype.Elem().Kind() == reflect.Interface) && mvalf.IsNil() {
				continue
			}
			val, err := e.valueToToml(mtype.Elem(), mvalf)
			if err != nil {
				return nil, err
			}
			val = e.wrapTomlValue(val, tval)
			if e.quoteMapKeys {
				keyStr, err := tomlValueStringRepresentation(key.String(), "", "", e.order, e.arraysOneElementPerLine)
				if err != nil {
					return nil, err
				}
				tval.SetPath([]string{keyStr}, val)
			} else {
				tval.SetPath([]string{key.String()}, val)
			}
		}
	}
	return tval, nil
}