json

package module
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2020 License: MIT Imports: 5 Imported by: 1

README

Go goreport

yomo-json-codec

{"KEY":"VALUE"}\n in json format yomo codec, used for YoMo development only

How to Use

New Codec
codec := NewCodec("name") // observed 'name'
Decode from bytes
data := []byte("{\"id\":1,\"name\":\"yomo\"}\n")
codec.Decoder(data)
Read Observe value
var v string
v, _ = codec.Read()
fmt.Println(strings.Compare("yomo", v))
// 0
Set new value and Encode it
b, _ := codec.Marshal("hello")
v2 := codec.Encoder(b, "")
fmt.Println(string(v2))
// {"id":1,"name":"hello"}

Test

go test -v

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEnd added in v0.1.0

func GetEnd() byte

Types

type Codec

type Codec struct {
	Key          string
	Value        []byte
	Sbuf         []byte
	Observe      string
	Result       [][]byte
	OriginResult [][]byte
}

func NewCodec added in v0.1.0

func NewCodec(observe string) *Codec

func (*Codec) Decoder

func (codec *Codec) Decoder(buf []byte)

func (*Codec) Encoder

func (codec *Codec) Encoder(buf []byte, mold interface{}) []byte

func (*Codec) IsDecoder added in v0.1.0

func (codec *Codec) IsDecoder(buf []byte) bool

is decoded flag

func (*Codec) Marshal added in v0.1.0

func (codec *Codec) Marshal(T interface{}) ([]byte, error)

func (*Codec) Read added in v0.1.0

func (codec *Codec) Read(mold interface{}) (interface{}, error)

func (*Codec) Refresh added in v0.2.1

func (codec *Codec) Refresh(w io.Writer) (int, error)

Avoid memory overflows due to excessive caching

func (*Codec) Unmarshal added in v0.1.0

func (codec *Codec) Unmarshal(data []byte, mold interface{}) error

func (*Codec) Write added in v0.1.0

func (codec *Codec) Write(w io.Writer, T interface{}, mold interface{}) (int, error)

Jump to

Keyboard shortcuts

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