提交 8ee4280f 作者: Mib Kd743naq

Switch unixfs.Metadata.MimeType to optional

*** THIS IS A BREAKING CHANGE *** as per [1]: "Required is forever"

Nevertheless this seems like a good idea at this time: there are no known
producers ( nor consumers ) of MetaData nodes, and the current requirement
of MimeType has an extremely narrow application scope.

This change could very well be rejected in lieu of implementing a new type
of node ( e.g. TheRealMetadata ) in the DataType enum.

Based on https://github.com/ipfs/go-ipfs/issues/3451#issuecomment-264246718

License: MIT
Signed-off-by: 's avatarMib Kd743naq <mib.kd743naq@gmail.com>

[1] https://developers.google.com/protocol-buffers/docs/proto#specifying-field-rules
上级 a7abc9cd
...@@ -15,10 +15,12 @@ It has these top-level messages: ...@@ -15,10 +15,12 @@ It has these top-level messages:
package unixfs_pb package unixfs_pb
import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
import fmt "fmt"
import math "math" import math "math"
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf var _ = math.Inf
type Data_DataType int32 type Data_DataType int32
...@@ -64,8 +66,8 @@ func (x *Data_DataType) UnmarshalJSON(data []byte) error { ...@@ -64,8 +66,8 @@ func (x *Data_DataType) UnmarshalJSON(data []byte) error {
} }
type Data struct { type Data struct {
Type *Data_DataType `protobuf:"varint,1,req,enum=unixfs.pb.Data_DataType" json:"Type,omitempty"` Type *Data_DataType `protobuf:"varint,1,req,name=Type,enum=unixfs.pb.Data_DataType" json:"Type,omitempty"`
Data []byte `protobuf:"bytes,2,opt" json:"Data,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=Data" json:"Data,omitempty"`
Filesize *uint64 `protobuf:"varint,3,opt,name=filesize" json:"filesize,omitempty"` Filesize *uint64 `protobuf:"varint,3,opt,name=filesize" json:"filesize,omitempty"`
Blocksizes []uint64 `protobuf:"varint,4,rep,name=blocksizes" json:"blocksizes,omitempty"` Blocksizes []uint64 `protobuf:"varint,4,rep,name=blocksizes" json:"blocksizes,omitempty"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
...@@ -104,7 +106,7 @@ func (m *Data) GetBlocksizes() []uint64 { ...@@ -104,7 +106,7 @@ func (m *Data) GetBlocksizes() []uint64 {
} }
type Metadata struct { type Metadata struct {
MimeType *string `protobuf:"bytes,1,req" json:"MimeType,omitempty"` MimeType *string `protobuf:"bytes,1,opt,name=MimeType" json:"MimeType,omitempty"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
} }
...@@ -120,5 +122,7 @@ func (m *Metadata) GetMimeType() string { ...@@ -120,5 +122,7 @@ func (m *Metadata) GetMimeType() string {
} }
func init() { func init() {
proto.RegisterType((*Data)(nil), "unixfs.pb.Data")
proto.RegisterType((*Metadata)(nil), "unixfs.pb.Metadata")
proto.RegisterEnum("unixfs.pb.Data_DataType", Data_DataType_name, Data_DataType_value) proto.RegisterEnum("unixfs.pb.Data_DataType", Data_DataType_name, Data_DataType_value)
} }
...@@ -16,5 +16,5 @@ message Data { ...@@ -16,5 +16,5 @@ message Data {
} }
message Metadata { message Metadata {
required string MimeType = 1; optional string MimeType = 1;
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论