MCPcopy
hub / github.com/perkeep/perkeep / populateParts

Function populateParts

pkg/schema/schema.go:739–766  ·  view source on GitHub ↗
(m map[string]interface{}, size int64, parts []BytesPart)

Source from the content-addressed store, hash-verified

737}
738
739func populateParts(m map[string]interface{}, size int64, parts []BytesPart) error {
740 sumSize := int64(0)
741 mparts := make([]map[string]interface{}, len(parts))
742 for idx, part := range parts {
743 mpart := make(map[string]interface{})
744 mparts[idx] = mpart
745 switch {
746 case part.BlobRef.Valid() && part.BytesRef.Valid():
747 return errors.New("schema: part contains both BlobRef and BytesRef")
748 case part.BlobRef.Valid():
749 mpart["blobRef"] = part.BlobRef.String()
750 case part.BytesRef.Valid():
751 mpart["bytesRef"] = part.BytesRef.String()
752 default:
753 return errors.New("schema: part must contain either a BlobRef or BytesRef")
754 }
755 mpart["size"] = part.Size
756 sumSize += int64(part.Size)
757 if part.Offset != 0 {
758 mpart["offset"] = part.Offset
759 }
760 }
761 if sumSize != size {
762 return fmt.Errorf("schema: declared size %d doesn't match sum of parts size %d", size, sumSize)
763 }
764 m["parts"] = mparts
765 return nil
766}
767
768func newBytes() *Builder {
769 return base(1, TypeBytes)

Callers 1

PopulatePartsMethod · 0.85

Calls 2

ValidMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected