Documentation
¶
Overview ¶
Package xmlwire provides bounded XML encoding and decoding with explicit namespace, root-element, strictness, and character-set policy.
Index ¶
- Constants
- Variables
- func CharsetReader(label string, input io.Reader) (io.Reader, error)
- func CharsetReaderWithLimit(label string, input io.Reader, maxBytes int64) (io.Reader, error)
- func Decode(payload []byte, target any, options DecodeOptions) error
- func DecodeReader(reader io.Reader, target any, options DecodeOptions) error
- func Encode(value any, options EncodeOptions) ([]byte, error)
- func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error
- func Root(payload []byte, options DecodeOptions) (xml.Name, error)
- type DecodeOptions
- type EncodeOptions
Constants ¶
const ( // DefaultMaxBytes is the default maximum XML document size. DefaultMaxBytes int64 = 1 << 20 // DefaultMaxDepth is the default maximum nested XML element depth. DefaultMaxDepth = 1000 )
Variables ¶
var ErrNestingTooDeep = errors.New("XML nesting exceeds depth limit")
ErrNestingTooDeep identifies XML documents over the configured depth limit.
var ErrPayloadTooLarge = errors.New("payload exceeds size limit")
ErrPayloadTooLarge identifies XML documents over the configured limit.
Functions ¶
func CharsetReader ¶
CharsetReader converts a deliberately limited set of common vendor encodings to UTF-8 with DefaultMaxBytes as the raw input limit. Labels are limited to 64 bytes before normalization. Conversion may produce up to three UTF-8 bytes per input byte. Caller reader code must return promptly.
func CharsetReaderWithLimit ¶
CharsetReaderWithLimit converts supported encodings with an inclusive raw input byte quota. Zero uses DefaultMaxBytes; negative limits are invalid. Unsupported or overlong labels are rejected without reading input. Errors expose categories only; wrapped reader causes are trusted diagnostics.
func Decode ¶
func Decode(payload []byte, target any, options DecodeOptions) error
Decode parses one complete XML document into target.
func DecodeReader ¶
func DecodeReader(reader io.Reader, target any, options DecodeOptions) error
DecodeReader reads a bounded stream and parses one complete XML document.
func Encode ¶
func Encode(value any, options EncodeOptions) ([]byte, error)
Encode serializes value using encoding/xml's deterministic struct traversal.
func EncodeWriter ¶
func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error
EncodeWriter serializes value and writes the complete XML document to writer.
Types ¶
type DecodeOptions ¶
type DecodeOptions struct {
MaxBytes int64
MaxDepth int
AllowNonStrict bool
ExpectedRoot xml.Name
CharsetReader func(string, io.Reader) (io.Reader, error)
}
DecodeOptions controls XML parsing and validation.
type EncodeOptions ¶
EncodeOptions controls XML serialization.