Skip to content

Commit

Permalink
Merge pull request #23 from shamaton/v2
Browse files Browse the repository at this point in the history
Update version to v2.0.0
  • Loading branch information
shamaton authored Feb 15, 2021
2 parents 066e4ae + 44a68c4 commit 3d3cf4a
Show file tree
Hide file tree
Showing 38 changed files with 61 additions and 94 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# MessagePack for Golang

[![Go Reference](https://pkg.go.dev/badge/github.com/shamaton/msgpack.svg)](https://pkg.go.dev/github.com/shamaton/msgpack)
[![Build Status](https://travis-ci.org/shamaton/msgpack.svg?branch=master)](https://travis-ci.org/shamaton/msgpack)
[![Coverage Status](https://coveralls.io/repos/github/shamaton/msgpack/badge.svg)](https://coveralls.io/github/shamaton/msgpack)
![test](https://github.com/shamaton/msgpack/workflows/test/badge.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/shamaton/msgpack)](https://goreportcard.com/report/github.com/shamaton/msgpack)
[![codecov](https://codecov.io/gh/shamaton/msgpack/branch/master/graph/badge.svg?token=9PD2JUK5V3)](https://codecov.io/gh/shamaton/msgpack)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fshamaton%2Fmsgpack.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fshamaton%2Fmsgpack?ref=badge_shield)

## Features
* Supported types : primitive / array / slice / struct / map / interface{} and time.Time
* Renaming fields via `msgpack:"field_name"`
* Omitting fields via `msgpack:"-"` or `msgpack:"ignore"`
* Omitting fields via `msgpack:"-"`
* Supports extend encoder / decoder
* Can also Encoding / Decoding struct as array

This package require more than golang version **1.9**
This package require more than golang version **1.13**

## Installation
```sh
Expand Down Expand Up @@ -73,7 +73,4 @@ BenchmarkCompareDecodeGob-4 36434 34308 ns/op

## License

This library is under the MIT License.


[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fshamaton%2Fmsgpack.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fshamaton%2Fmsgpack?ref=badge_large)
This library is under the MIT License.
12 changes: 1 addition & 11 deletions decode.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package msgpack

import "github.com/shamaton/msgpack/internal/decoding"
import "github.com/shamaton/msgpack/v2/internal/decoding"

// UnmarshalAsMap decodes data that is encoded as map format.
// This is the same thing that StructAsArray sets false.
Expand All @@ -13,13 +13,3 @@ func UnmarshalAsMap(data []byte, v interface{}) error {
func UnmarshalAsArray(data []byte, v interface{}) error {
return decoding.Decode(data, v, true)
}

// Deprecated: Use UnmarshalAsMap, this method will be deleted.
func DecodeStructAsMap(data []byte, v interface{}) error {
return UnmarshalAsMap(data, v)
}

// Deprecated: Use UnmarshalAsArray, this method will be deleted.
func DecodeStructAsArray(data []byte, v interface{}) error {
return UnmarshalAsArray(data, v)
}
14 changes: 2 additions & 12 deletions encode.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package msgpack

import (
"github.com/shamaton/msgpack/internal/encoding"
"github.com/shamaton/msgpack/v2/internal/encoding"
)

// MarshalAsMap encodes data as map format.
Expand All @@ -10,18 +10,8 @@ func MarshalAsMap(v interface{}) ([]byte, error) {
return encoding.Encode(v, false)
}

// EncodeStructAsArray encodes data as array format.
// MarshalAsArray encodes data as array format.
// This is the same thing that StructAsArray sets true.
func MarshalAsArray(v interface{}) ([]byte, error) {
return encoding.Encode(v, true)
}

// Deprecated: Use MarshalAsMap, this method will be deleted.
func EncodeStructAsMap(v interface{}) ([]byte, error) {
return MarshalAsMap(v)
}

// Deprecated: Use MarshalAsArray, this method will be deleted.
func EncodeStructAsArray(v interface{}) ([]byte, error) {
return MarshalAsArray(v)
}
2 changes: 1 addition & 1 deletion ext/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ext
import (
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

type Decoder interface {
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/shamaton/msgpack/v2

go 1.15
2 changes: 1 addition & 1 deletion internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Common struct {
func (c *Common) CheckField(field reflect.StructField) (bool, string) {
// A to Z
if c.isPublic(field.Name) {
if tag := field.Tag.Get("msgpack"); tag == "ignore" || tag == "-" {
if tag := field.Tag.Get("msgpack"); tag == "-" {
return false, ""
} else if len(tag) > 0 {
return true, tag
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"unsafe"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (d *decoder) isCodeBin(v byte) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package decoding
import (
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (d *decoder) asBool(offset int, k reflect.Kind) (bool, int, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (d *decoder) asComplex64(offset int, k reflect.Kind) (complex64, int, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/decoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"reflect"

"github.com/shamaton/msgpack/internal/common"
"github.com/shamaton/msgpack/v2/internal/common"
)

type decoder struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/decoding/ext.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package decoding

import (
"github.com/shamaton/msgpack/ext"
"github.com/shamaton/msgpack/time"
"github.com/shamaton/msgpack/v2/ext"
"github.com/shamaton/msgpack/v2/time"
)

var extCoderMap = map[int8]ext.Decoder{time.Decoder.Code(): time.Decoder}
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"math"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (d *decoder) asFloat32(offset int, k reflect.Kind) (float32, int, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/binary"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (d *decoder) isPositiveFixNum(v byte) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package decoding
import (
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (d *decoder) asInterface(offset int, k reflect.Kind) (interface{}, int, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/binary"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/nil.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package decoding

import "github.com/shamaton/msgpack/def"
import "github.com/shamaton/msgpack/v2/def"

func (d *decoder) isCodeNil(v byte) bool {
return def.Nil == v
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/read.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package decoding

import (
"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (d *decoder) readSize1(index int) (byte, int) {
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/binary"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"unsafe"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

var emptyString = ""
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"sync"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

type structCacheTypeMap struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/decoding/uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/binary"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (d *decoder) asUint(offset int, k reflect.Kind) (uint64, int, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/bool.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package encoding

import "github.com/shamaton/msgpack/def"
import "github.com/shamaton/msgpack/v2/def"

//func (e *encoder) calcBool() int {
// return 0
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/byte.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"math"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

var typeByte = reflect.TypeOf(byte(0))
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package encoding
import (
"math"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (e *encoder) calcComplex64() int {
Expand Down
4 changes: 2 additions & 2 deletions internal/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"math"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/internal/common"
"github.com/shamaton/msgpack/v2/def"
"github.com/shamaton/msgpack/v2/internal/common"
)

type encoder struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/encoding/ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package encoding
import (
"reflect"

"github.com/shamaton/msgpack/ext"
"github.com/shamaton/msgpack/time"
"github.com/shamaton/msgpack/v2/ext"
"github.com/shamaton/msgpack/v2/time"
)

var extCoderMap = map[reflect.Type]ext.Encoder{time.Encoder.Type(): time.Encoder}
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package encoding
import (
"math"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (e *encoder) calcFloat32(v float64) int {
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package encoding
import (
"math"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (e *encoder) isNegativeFixInt64(v int64) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (e *encoder) calcFixedMap(rv reflect.Value) (int, bool) {
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/nil.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package encoding

import "github.com/shamaton/msgpack/def"
import "github.com/shamaton/msgpack/v2/def"

func (e *encoder) writeNil(offset int) int {
offset = e.setByte1Int(def.Nil, offset)
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math"
"reflect"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (e *encoder) calcFixedSlice(rv reflect.Value) (int, bool) {
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math"
"unsafe"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (e *encoder) calcString(v string) int {
Expand Down
4 changes: 2 additions & 2 deletions internal/encoding/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"reflect"
"sync"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/internal/common"
"github.com/shamaton/msgpack/v2/def"
"github.com/shamaton/msgpack/v2/internal/common"
)

type structCache struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package encoding
import (
"math"

"github.com/shamaton/msgpack/def"
"github.com/shamaton/msgpack/v2/def"
)

func (e *encoder) calcUint(v uint64) int {
Expand Down
19 changes: 4 additions & 15 deletions msgpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package msgpack
import (
"fmt"

"github.com/shamaton/msgpack/def"

"github.com/shamaton/msgpack/ext"
"github.com/shamaton/msgpack/internal/decoding"
"github.com/shamaton/msgpack/internal/encoding"
"github.com/shamaton/msgpack/v2/def"
"github.com/shamaton/msgpack/v2/ext"
"github.com/shamaton/msgpack/v2/internal/decoding"
"github.com/shamaton/msgpack/v2/internal/encoding"
)

// StructAsArray is encoding option.
Expand All @@ -25,16 +24,6 @@ func Unmarshal(data []byte, v interface{}) error {
return decoding.Decode(data, v, StructAsArray)
}

// Deprecated: Use Marshal, this method will be deleted.
func Encode(v interface{}) ([]byte, error) {
return encoding.Encode(v, StructAsArray)
}

// Deprecated: Use Unmarshal, this method will be deleted.
func Decode(data []byte, v interface{}) error {
return decoding.Decode(data, v, StructAsArray)
}

// AddExtCoder adds encoders for extension types.
func AddExtCoder(e ext.Encoder, d ext.Decoder) error {
if e.Code() != d.Code() {
Expand Down
Loading

0 comments on commit 3d3cf4a

Please sign in to comment.