> For the complete documentation index, see [llms.txt](https://docs.ionos.com/cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ionos.com/cloud/tools-terraform/vendor/github.com/vmihailenco/msgpack/v5.md).

# MessagePack encoding for Golang

[![Build Status](https://travis-ci.org/vmihailenco/msgpack.svg)](https://travis-ci.org/vmihailenco/msgpack) [![PkgGoDev](https://pkg.go.dev/badge/github.com/vmihailenco/msgpack/v5)](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5) [![Documentation](https://img.shields.io/badge/msgpack-documentation-informational)](https://msgpack.uptrace.dev/) [![Chat](https://discordapp.com/api/guilds/752070105847955518/widget.png)](https://discord.gg/rWtp5Aj)

> msgpack is brought to you by :star: [**uptrace/uptrace**](https://github.com/uptrace/uptrace). Uptrace is an [open source APM](https://uptrace.dev/get/open-source-apm.html) and blazingly fast [distributed tracing tool](https://get.uptrace.dev/compare/distributed-tracing-tools.html) powered by OpenTelemetry and ClickHouse. Give it a star as well!

## Resources

* [Documentation](https://msgpack.uptrace.dev)
* [Chat](https://discord.gg/rWtp5Aj)
* [Reference](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5)
* [Examples](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#pkg-examples)

## Features

* Primitives, arrays, maps, structs, time.Time and interface{}.
* Appengine \*datastore.Key and datastore.Cursor.
* [CustomEncoder](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#CustomEncoder)/[CustomDecoder](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#CustomDecoder) interfaces for custom encoding.
* [Extensions](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#example-RegisterExt) to encode type information.
* Renaming fields via `msgpack:"my_field_name"` and alias via `msgpack:"alias:another_name"`.
* Omitting individual empty fields via `msgpack:",omitempty"` tag or all [empty fields in a struct](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#example-Marshal-OmitEmpty).
* [Map keys sorting](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#Encoder.SetSortMapKeys).
* Encoding/decoding all [structs as arrays](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#Encoder.UseArrayEncodedStructs) or [individual structs](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#example-Marshal-AsArray).
* [Encoder.SetCustomStructTag](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#Encoder.SetCustomStructTag) with [Decoder.SetCustomStructTag](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#Decoder.SetCustomStructTag) can turn msgpack into drop-in replacement for any tag.
* Simple but very fast and efficient [queries](https://pkg.go.dev/github.com/vmihailenco/msgpack/v5#example-Decoder.Query).

## Installation

msgpack supports 2 last Go versions and requires support for [Go modules](https://github.com/golang/go/wiki/Modules). So make sure to initialize a Go module:

```shell
go mod init github.com/my/repo
```

And then install msgpack/v5 (note *v5* in the import; omitting it is a popular mistake):

```shell
go get github.com/vmihailenco/msgpack/v5
```

## Quickstart

```go
import "github.com/vmihailenco/msgpack/v5"

func ExampleMarshal() {
    type Item struct {
        Foo string
    }

    b, err := msgpack.Marshal(&Item{Foo: "bar"})
    if err != nil {
        panic(err)
    }

    var item Item
    err = msgpack.Unmarshal(b, &item)
    if err != nil {
        panic(err)
    }
    fmt.Println(item.Foo)
    // Output: bar
}
```

## See also

* [Golang ORM](https://github.com/uptrace/bun) for PostgreSQL, MySQL, MSSQL, and SQLite
* [Golang PostgreSQL](https://bun.uptrace.dev/postgres/)
* [Golang HTTP router](https://github.com/uptrace/bunrouter)
* [Golang ClickHouse ORM](https://github.com/uptrace/go-clickhouse)

## Contributors

Thanks to all the people who already contributed!

[![](https://contributors-img.web.app/image?repo=vmihailenco/msgpack)](https://github.com/vmihailenco/msgpack/graphs/contributors)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ionos.com/cloud/tools-terraform/vendor/github.com/vmihailenco/msgpack/v5.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
