dencoding

package
v2.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 12 Imported by: 0

README

dencoding - Dasel Encoding

This package provides encoding implementations for all supported file formats.

The main difference is that it aims to keep maps ordered, where the default encoders/decoders do not.

Support formats

Decoding

Custom decoders are required to ensure that map/object values are decoded into the Map type rather than a standard map[string]any.

Encoding

The Map type must have the appropriate Marshal func on it to ensure marshalling it in the desired format retains the ordering.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONDecoder

type JSONDecoder struct {
	// contains filtered or unexported fields
}

JSONDecoder wraps a standard json encoder to implement custom ordering logic.

func NewJSONDecoder

func NewJSONDecoder(r io.Reader, options ...JSONDecoderOption) *JSONDecoder

NewJSONDecoder returns a new dencoding JSONDecoder.

func (*JSONDecoder) Decode

func (decoder *JSONDecoder) Decode(v any) error

Decode decodes the next item found in the decoder and writes it to v.

type JSONDecoderOption

type JSONDecoderOption interface {
	ApplyDecoder(decoder *JSONDecoder)
}

JSONDecoderOption is identifies an option that can be applied to a JSON decoder.

type JSONEncoder

type JSONEncoder struct {
	// contains filtered or unexported fields
}

JSONEncoder wraps a standard json encoder to implement custom ordering logic.

func NewJSONEncoder

func NewJSONEncoder(w io.Writer, options ...JSONEncoderOption) *JSONEncoder

NewJSONEncoder returns a new dencoding JSONEncoder.

func (*JSONEncoder) Close

func (encoder *JSONEncoder) Close() error

Close cleans up the encoder.

func (*JSONEncoder) Encode

func (encoder *JSONEncoder) Encode(v any) error

Encode encodes the given value and writes the encodes bytes to the stream.

type JSONEncoderOption

type JSONEncoderOption interface {
	ApplyEncoder(encoder *JSONEncoder)
}

JSONEncoderOption is identifies an option that can be applied to a JSON encoder.

func JSONEncodeIndent

func JSONEncodeIndent(prefix string, indent string) JSONEncoderOption

JSONEncodeIndent sets the indentation when encoding JSON.

func JSONEscapeHTML

func JSONEscapeHTML(escape bool) JSONEncoderOption

JSONEscapeHTML enables or disables html escaping when encoding JSON.

type KeyValue

type KeyValue struct {
	Key   string
	Value any
}

KeyValue is a single key value pair from a *Map.

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map is a map implementation that maintains ordering of keys.

func FromMap

func FromMap(source map[string]any) *Map

FromMap creates a *Map from the input map. Note that while the contents will be ordered, the ordering is not guaranteed since the input map is unordered.

func NewMap

func NewMap() *Map

NewMap returns a new *Map that has its values initialised.

func (*Map) Delete

func (m *Map) Delete(key string) *Map

Delete deletes the value found under the given key.

func (*Map) Get

func (m *Map) Get(key string) (any, bool)

Get returns the value found under the given key.

func (*Map) KeyValues

func (m *Map) KeyValues() []KeyValue

KeyValues returns the KeyValue pairs within the map, in the order that they were added.

func (*Map) Keys

func (m *Map) Keys() []string

Keys returns all the keys from the map.

func (*Map) MarshalJSON

func (m *Map) MarshalJSON() ([]byte, error)

MarshalJSON JSON encodes the map and returns the bytes. This maintains ordering.

func (*Map) MarshalYAML

func (m *Map) MarshalYAML() (any, error)

MarshalYAML YAML encodes the map and returns the bytes. This maintains ordering.

func (*Map) Set

func (m *Map) Set(key string, value any) *Map

Set sets a value under the given key.

func (*Map) UnorderedData

func (m *Map) UnorderedData() map[string]any

UnorderedData returns all the data from the map.

type TOMLDecoder

type TOMLDecoder struct {
	// contains filtered or unexported fields
}

TOMLDecoder wraps a standard toml encoder to implement custom ordering logic.

func NewTOMLDecoder

func NewTOMLDecoder(r io.Reader, options ...TOMLDecoderOption) *TOMLDecoder

NewTOMLDecoder returns a new dencoding TOMLDecoder.

func (*TOMLDecoder) Decode

func (decoder *TOMLDecoder) Decode(v any) error

Decode decodes the next item found in the decoder and writes it to v.

type TOMLDecoderOption

type TOMLDecoderOption interface {
	ApplyDecoder(decoder *TOMLDecoder)
}

TOMLDecoderOption is identifies an option that can be applied to a TOML decoder.

type TOMLEncoder

type TOMLEncoder struct {
	// contains filtered or unexported fields
}

TOMLEncoder wraps a standard toml encoder to implement custom ordering logic.

func NewTOMLEncoder

func NewTOMLEncoder(w io.Writer, options ...TOMLEncoderOption) *TOMLEncoder

NewTOMLEncoder returns a new dencoding TOMLEncoder.

func (*TOMLEncoder) Close

func (encoder *TOMLEncoder) Close() error

Close cleans up the encoder.

func (*TOMLEncoder) Encode

func (encoder *TOMLEncoder) Encode(v any) error

Encode encodes the given value and writes the encodes bytes to the stream.

type TOMLEncoderOption

type TOMLEncoderOption interface {
	ApplyEncoder(encoder *TOMLEncoder)
}

TOMLEncoderOption is identifies an option that can be applied to a TOML encoder.

func TOMLIndentSymbol

func TOMLIndentSymbol(symbol string) TOMLEncoderOption

TOMLIndentSymbol sets the indentation when encoding TOML.

type YAMLDecoder

type YAMLDecoder struct {
	// contains filtered or unexported fields
}

YAMLDecoder wraps a standard yaml encoder to implement custom ordering logic.

func NewYAMLDecoder

func NewYAMLDecoder(r io.Reader, options ...YAMLDecoderOption) *YAMLDecoder

NewYAMLDecoder returns a new dencoding YAMLDecoder.

func (*YAMLDecoder) Decode

func (decoder *YAMLDecoder) Decode(v any) error

Decode decodes the next item found in the decoder and writes it to v.

type YAMLDecoderOption

type YAMLDecoderOption interface {
	ApplyDecoder(decoder *YAMLDecoder)
}

YAMLDecoderOption is identifies an option that can be applied to a YAML decoder.

type YAMLEncoder

type YAMLEncoder struct {
	// contains filtered or unexported fields
}

YAMLEncoder wraps a standard yaml encoder to implement custom ordering logic.

func NewYAMLEncoder

func NewYAMLEncoder(w io.Writer, options ...YAMLEncoderOption) *YAMLEncoder

NewYAMLEncoder returns a new dencoding YAMLEncoder.

func (*YAMLEncoder) Close

func (encoder *YAMLEncoder) Close() error

Close cleans up the encoder.

func (*YAMLEncoder) Encode

func (encoder *YAMLEncoder) Encode(v any) error

Encode encodes the given value and writes the encodes bytes to the stream.

type YAMLEncoderOption

type YAMLEncoderOption interface {
	ApplyEncoder(encoder *YAMLEncoder)
}

YAMLEncoderOption is identifies an option that can be applied to a YAML encoder.

func YAMLEncodeIndent

func YAMLEncodeIndent(spaces int) YAMLEncoderOption

YAMLEncodeIndent sets the indentation when encoding YAML.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL