mcp: dedup wire type for image and audio (#149)
Factor out the wire type into a top-level struct.
This commit is contained in:
parent
c6fabbb3d3
commit
9ddad03891
1 changed files with 11 additions and 14 deletions
|
|
@ -63,13 +63,7 @@ func (c *ImageContent) MarshalJSON() ([]byte, error) {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
data = []byte{}
|
data = []byte{}
|
||||||
}
|
}
|
||||||
wire := struct {
|
wire := imageAudioWire{
|
||||||
Type string `json:"type"`
|
|
||||||
MIMEType string `json:"mimeType"`
|
|
||||||
Data []byte `json:"data"`
|
|
||||||
Meta Meta `json:"_meta,omitempty"`
|
|
||||||
Annotations *Annotations `json:"annotations,omitempty"`
|
|
||||||
}{
|
|
||||||
Type: "image",
|
Type: "image",
|
||||||
MIMEType: c.MIMEType,
|
MIMEType: c.MIMEType,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
|
@ -100,13 +94,7 @@ func (c AudioContent) MarshalJSON() ([]byte, error) {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
data = []byte{}
|
data = []byte{}
|
||||||
}
|
}
|
||||||
wire := struct {
|
wire := imageAudioWire{
|
||||||
Type string `json:"type"`
|
|
||||||
MIMEType string `json:"mimeType"`
|
|
||||||
Data []byte `json:"data"`
|
|
||||||
Meta Meta `json:"_meta,omitempty"`
|
|
||||||
Annotations *Annotations `json:"annotations,omitempty"`
|
|
||||||
}{
|
|
||||||
Type: "audio",
|
Type: "audio",
|
||||||
MIMEType: c.MIMEType,
|
MIMEType: c.MIMEType,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
|
@ -123,6 +111,15 @@ func (c *AudioContent) fromWire(wire *wireContent) {
|
||||||
c.Annotations = wire.Annotations
|
c.Annotations = wire.Annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Custom wire format to ensure required fields are always included, even when empty.
|
||||||
|
type imageAudioWire struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
MIMEType string `json:"mimeType"`
|
||||||
|
Data []byte `json:"data"`
|
||||||
|
Meta Meta `json:"_meta,omitempty"`
|
||||||
|
Annotations *Annotations `json:"annotations,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// ResourceLink is a link to a resource
|
// ResourceLink is a link to a resource
|
||||||
type ResourceLink struct {
|
type ResourceLink struct {
|
||||||
URI string
|
URI string
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue