这是indexloc提供的服务,不要输入任何密码
Skip to content

penril0326/myMessagePack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

myMessagePack

Trying to implement a converter that can convert from JSON to MessagePack and from MessagePack to JSON.

Support type

Encode

bool, int family, uint family, string, float32, float64, array, slice, map, timestamp

Decode

bool, uint family,int family, string, float32, float64, primitive array/slice/map

How to use

func main() {
    // Encode: Declare a map as a JSON object
    m := map[string]interface{}{
        "compact": true,
        "schema" 0,
    }

    b, err := encoder.JsonToMsgPack(json)
	if err != nil {
		log.Fatalf("Convert JSON to msgpack occured error: %s", err.Error())
	}

	fmt.Printf("%x\n", b) // output: 82a7c3a600

    // Decode
    m2 := map[string]interface{}{}
    err := decoder.MsgPackToJson(b, &m2)
    if err != nil {
		log.Fatalf("Convert msgpack to JSON occured error: %s", err.Error())
	}

    fmt.Println(m2)
}

Run test

Test encoding

$ cd internal/encoder
$ go test -v .

Test decoding

$ cd internal/dncoder
$ go test -v .

Known issue

Some complicated types are not supported such as nested slice/array/map with interface.

About

Trying to implement MessagePack encoder and decoder

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages