package httpsfv

import (
	
	
)

// ErrInvalidBooleanFormat is returned when a boolean format is invalid.
var ErrInvalidBooleanFormat = errors.New("invalid boolean format")

// marshalBoolean serializes as defined in
// https://httpwg.org/specs/rfc9651.html#ser-boolean.
func marshalBoolean( io.StringWriter,  bool) error {
	if  {
		,  := .WriteString("?1")

		return 
	}

	,  := .WriteString("?0")

	return 
}

// parseBoolean parses as defined in
// https://httpwg.org/specs/rfc9651.html#parse-boolean.
func parseBoolean( *scanner) (bool, error) {
	if .eof() || .data[.off] != '?' {
		return false, &UnmarshalError{.off, ErrInvalidBooleanFormat}
	}
	.off++

	if .eof() {
		return false, &UnmarshalError{.off, ErrInvalidBooleanFormat}
	}

	switch .data[.off] {
	case '0':
		.off++

		return false, nil
	case '1':
		.off++

		return true, nil
	}

	return false, &UnmarshalError{.off, ErrInvalidBooleanFormat}
}