edn

package module
v0.0.0-...-3634fe6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2016 License: BSD-3-Clause Imports: 15 Imported by: 0

README

Deprecation Notice

This is dead code. A more complete implementation is:

github.com/go-edn/edn

Package edn

This EDN encoding/decoding package is inspired and remixed from Go's excellent encoding/json package.

GoDoc

Warning: currently, it supports the following:

  • Marshal function that encodes a Go value into EDN.
  • TextMarshaler-implementing objects can be marshaled.
  • Encoder for writing EDN objects to an output stream.

Please inspect the project's issues to see what is missing or buggy.

Sets, Symbols and Keywords

Go lacks EDN sets, symbols and keywords. This package awkwardly attempts to remedy this deficiency by implementing: Set, Symbol, Keyword.

These types are not fully fleshed out and their programming interface will need to be improved, and will certainly change.

Bytes

Go []byte objects will be serialized like so:

#base64 "YW55ICsgb2xkICYgZGF0YQ=="

Note: I've taken a liberty here, and chose #base64 tag. This may change to something else when EDN spec gets updated to accommodate byte array objects.

Documentation

Overview

Package edn implements encoding and decoding of EDN values as defined in https://github.com/edn-format/edn

The mapping between EDN and Go values is described in the documentation for the Marshal and Unmarshal functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal returns the EDN encoding of v.

Marshal traverses the value v recursively, using the following type-dependent default encodings: (see https://github.com/edn-format/edn)

func MustMarshal

func MustMarshal(v interface{}) []byte

MustMarshal is a panicky version of Marshal.

Types

type Encoder

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

An Encoder writes EDN objects to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (enc *Encoder) Encode(v interface{}) error

Encode writes the EDN encoding of v to the stream.

See the documentation for Marshal for details about the conversion of Go values to EDN.

type KMap

type KMap map[string]interface{}

KMap is useful for generating EDN maps with Keywords as keys. For example: Marshal(KMap{"foo": 45, "bar": 3.14}) => {:foo 45, :bar 3.14}

type Keyword

type Keyword string

func K

func K(k string) Keyword

type MarshalerError

type MarshalerError struct {
	Type reflect.Type
	Err  error
}

func (*MarshalerError) Error

func (e *MarshalerError) Error() string

type Set

type Set map[interface{}]bool

func (Set) Add

func (set Set) Add(keys ...interface{}) Set

func (Set) Discard

func (set Set) Discard(k interface{})

func (Set) Has

func (set Set) Has(k interface{}) (ret bool)

type Symbol

type Symbol string

func S

func S(s string) Symbol

type UnsupportedTypeError

type UnsupportedTypeError struct {
	Type reflect.Type
}

An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

type UnsupportedValueError

type UnsupportedValueError struct {
	Value reflect.Value
	Str   string
}

func (*UnsupportedValueError) Error

func (e *UnsupportedValueError) Error() string

Jump to

Keyboard shortcuts

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