Files
opencloud/vendor/github.com/shamaton/msgpack/v2/msgpack.go
dependabot[bot] c2c740592d build(deps): bump github.com/shamaton/msgpack/v2 from 2.1.1 to 2.2.0
Bumps [github.com/shamaton/msgpack/v2](https://github.com/shamaton/msgpack) from 2.1.1 to 2.2.0.
- [Release notes](https://github.com/shamaton/msgpack/releases)
- [Commits](https://github.com/shamaton/msgpack/compare/v2.1.1...v2.2.0)

---
updated-dependencies:
- dependency-name: github.com/shamaton/msgpack/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-20 09:15:42 +01:00

85 lines
2.5 KiB
Go

package msgpack
import (
"fmt"
"io"
"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"
streamdecoding "github.com/shamaton/msgpack/v2/internal/stream/decoding"
streamencoding "github.com/shamaton/msgpack/v2/internal/stream/encoding"
)
// StructAsArray is encoding option.
// If this option sets true, default encoding sets to array-format.
var StructAsArray = false
// Marshal returns the MessagePack-encoded byte array of v.
func Marshal(v interface{}) ([]byte, error) {
return encoding.Encode(v, StructAsArray)
}
// MarshalWrite writes MessagePack-encoded byte array of v to writer.
func MarshalWrite(w io.Writer, v interface{}) error {
return streamencoding.Encode(w, v, StructAsArray)
}
// Unmarshal analyzes the MessagePack-encoded data and stores
// the result into the pointer of v.
func Unmarshal(data []byte, v interface{}) error {
return decoding.Decode(data, v, StructAsArray)
}
// UnmarshalRead reads the MessagePack-encoded data from reader and stores
// the result into the pointer of v.
func UnmarshalRead(r io.Reader, v interface{}) error {
return streamdecoding.Decode(r, v, StructAsArray)
}
// AddExtCoder adds encoders for extension types.
func AddExtCoder(e ext.Encoder, d ext.Decoder) error {
if e.Code() != d.Code() {
return fmt.Errorf("code different %d:%d", e.Code(), d.Code())
}
encoding.AddExtEncoder(e)
decoding.AddExtDecoder(d)
return nil
}
// AddExtStreamCoder adds stream encoders for extension types.
func AddExtStreamCoder(e ext.StreamEncoder, d ext.StreamDecoder) error {
if e.Code() != d.Code() {
return fmt.Errorf("code different %d:%d", e.Code(), d.Code())
}
streamencoding.AddExtEncoder(e)
streamdecoding.AddExtDecoder(d)
return nil
}
// RemoveExtCoder removes encoders for extension types.
func RemoveExtCoder(e ext.Encoder, d ext.Decoder) error {
if e.Code() != d.Code() {
return fmt.Errorf("code different %d:%d", e.Code(), d.Code())
}
encoding.RemoveExtEncoder(e)
decoding.RemoveExtDecoder(d)
return nil
}
// RemoveExtStreamCoder removes stream encoders for extension types.
func RemoveExtStreamCoder(e ext.StreamEncoder, d ext.StreamDecoder) error {
if e.Code() != d.Code() {
return fmt.Errorf("code different %d:%d", e.Code(), d.Code())
}
streamencoding.RemoveExtEncoder(e)
streamdecoding.RemoveExtDecoder(d)
return nil
}
// SetComplexTypeCode sets def.complexTypeCode
func SetComplexTypeCode(code int8) {
def.SetComplexTypeCode(code)
}