From e94be522d89ba2057d8b12796e4f3cfbeed7fe37 Mon Sep 17 00:00:00 2001 From: Mib Kd743naq Date: Fri, 2 Dec 2016 06:37:11 +0100 Subject: [PATCH] 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: Mib Kd743naq [1] https://developers.google.com/protocol-buffers/docs/proto#specifying-field-rules --- pb/unixfs.pb.go | 10 +++++++--- pb/unixfs.proto | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pb/unixfs.pb.go b/pb/unixfs.pb.go index 55348ad76..ffd3bb905 100644 --- a/pb/unixfs.pb.go +++ b/pb/unixfs.pb.go @@ -15,10 +15,12 @@ It has these top-level messages: package unixfs_pb import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" +import fmt "fmt" import math "math" // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal +var _ = fmt.Errorf var _ = math.Inf type Data_DataType int32 @@ -64,8 +66,8 @@ func (x *Data_DataType) UnmarshalJSON(data []byte) error { } type Data struct { - Type *Data_DataType `protobuf:"varint,1,req,enum=unixfs.pb.Data_DataType" json:"Type,omitempty"` - Data []byte `protobuf:"bytes,2,opt" json:"Data,omitempty"` + Type *Data_DataType `protobuf:"varint,1,req,name=Type,enum=unixfs.pb.Data_DataType" json:"Type,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=Data" json:"Data,omitempty"` Filesize *uint64 `protobuf:"varint,3,opt,name=filesize" json:"filesize,omitempty"` Blocksizes []uint64 `protobuf:"varint,4,rep,name=blocksizes" json:"blocksizes,omitempty"` XXX_unrecognized []byte `json:"-"` @@ -104,7 +106,7 @@ func (m *Data) GetBlocksizes() []uint64 { } 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:"-"` } @@ -120,5 +122,7 @@ func (m *Metadata) GetMimeType() string { } 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) } diff --git a/pb/unixfs.proto b/pb/unixfs.proto index 4a52c3af5..2e4d47947 100644 --- a/pb/unixfs.proto +++ b/pb/unixfs.proto @@ -16,5 +16,5 @@ message Data { } message Metadata { - required string MimeType = 1; + optional string MimeType = 1; }