generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.go
32 lines (27 loc) · 850 Bytes
/
packet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package marshalkit
import (
"github.com/dogmatiq/marshalkit/internal/mimex"
)
// Packet is a container of marshaled data and its related meta-data.
type Packet struct {
// MediaType is a MIME media-type describing the content and encoding of the
// binary data.
MediaType string
// Data is the marshaled binary data.
Data []byte
}
// NewPacket returns a new packet.
//
// mt is the MIME media-type describing the content and encoding of the binary
// data. n is the marshaled value's portable type name.
func NewPacket(mt string, n string, data []byte) Packet {
return Packet{
mimex.FormatMediaType(mt, n),
data,
}
}
// ParseMediaType returns the media-type and the portable type name encoded in
// the packet's MIME media-type.
func (p *Packet) ParseMediaType() (string, string, error) {
return mimex.ParseMediaType(p.MediaType)
}