MCPcopy
hub / github.com/dgraph-io/dgraph / marshalVectorEntry

Function marshalVectorEntry

dgraph/cmd/bulk/vector_indexer.go:93–115  ·  view source on GitHub ↗

marshalVectorEntry serializes a vectorEntry into a byte slice.

(dst []byte, ve *vectorEntry)

Source from the content-addressed store, hash-verified

91
92// marshalVectorEntry serializes a vectorEntry into a byte slice.
93func marshalVectorEntry(dst []byte, ve *vectorEntry) {
94 offset := 0
95
96 // Write predicate length and bytes
97 binary.BigEndian.PutUint32(dst[offset:offset+4], uint32(len(ve.pred)))
98 offset += 4
99 copy(dst[offset:], ve.pred)
100 offset += len(ve.pred)
101
102 // Write UID
103 binary.BigEndian.PutUint64(dst[offset:offset+8], ve.uid)
104 offset += 8
105
106 // Write vector length
107 binary.BigEndian.PutUint32(dst[offset:offset+4], uint32(len(ve.vector)))
108 offset += 4
109
110 // Write vector data
111 for _, v := range ve.vector {
112 binary.BigEndian.PutUint32(dst[offset:offset+4], math.Float32bits(v))
113 offset += 4
114 }
115}
116
117// unmarshalVectorEntry deserializes a vectorEntry from a byte slice.
118// Returns nil if the data is malformed or too short.

Callers 1

toListMethod · 0.85

Calls 1

copyFunction · 0.85

Tested by

no test coverage detected