func (mb *MultiBlock) GetBytes() ([]byte, error) { pbn := new(pb.Data) t := pb.Data_File pbn.Type = &t pbn.Filesize = proto.Uint64(uint64(len(mb.Data)) + mb.subtotal) pbn.Blocksizes = mb.blocksizes pbn.Data = mb.Data return proto.Marshal(pbn) }
func WrapData(b []byte) []byte { pbdata := new(pb.Data) typ := pb.Data_Raw pbdata.Data = b pbdata.Type = &typ out, err := proto.Marshal(pbdata) if err != nil { // This shouldnt happen. seriously. panic(err) } return out }
func FilePBData(data []byte, totalsize uint64) []byte { pbfile := new(pb.Data) typ := pb.Data_File pbfile.Type = &typ pbfile.Data = data pbfile.Filesize = proto.Uint64(totalsize) data, err := proto.Marshal(pbfile) if err != nil { // This really shouldnt happen, i promise // The only failure case for marshal is if required fields // are not filled out, and they all are. If the proto object // gets changed and nobody updates this function, the code // should panic due to programmer error panic(err) } return data }