For representing full identifiers of system and member. Signed-off-by: Yonah <contrib@gensokyo.uk>
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
// Package ident is the reference implementation of system and member
|
|
// identifiers.
|
|
package ident
|
|
|
|
import (
|
|
"encoding"
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
// ErrNewline is returned for identifiers found to contain newline characters.
|
|
var ErrNewline = errors.New("identifier contains newline characters")
|
|
|
|
// UnexpectedSizeError describes a malformed string representation of an
|
|
// identifier, with unexpected length.
|
|
type UnexpectedSizeError struct {
|
|
Data []byte
|
|
Want int
|
|
}
|
|
|
|
func (e *UnexpectedSizeError) Error() string {
|
|
return "got " + strconv.Itoa(len(e.Data)) + " bytes for " +
|
|
"a " + strconv.Itoa(e.Want) + "-byte identifier"
|
|
}
|
|
|
|
// MS is a system or member identifier.
|
|
type MS interface {
|
|
encoding.TextMarshaler
|
|
encoding.TextUnmarshaler
|
|
fmt.Stringer
|
|
|
|
// EncodedSize returns the number of bytes appended by Encode.
|
|
EncodedSize() int
|
|
// Encode appends the canonical string representation of MS to dst and
|
|
// returns the extended buffer.
|
|
Encode(dst []byte) []byte
|
|
|
|
// ident is a no-op function but serves to distinguish types that are
|
|
// identifiers from ordinary types with custom marshaler/unmarshaler
|
|
// behaviour: a type is an identifier part if it has an ident method.
|
|
ident()
|
|
}
|