// BuildZipkinThrift builds thrift span based on internal span.
173992
func BuildZipkinThrift(s *Span) *z.Span {
	span := &zipkinSpan{Span: s}
	span.handleSpecialTags()
	parentID := int64(span.context.parentID)
	var ptrParentID *int64
	if parentID != 0 {
		ptrParentID = &parentID
	}
	traceIDHigh := int64(span.context.traceID.High)
	var ptrTraceIDHigh *int64
	if traceIDHigh != 0 {
		ptrTraceIDHigh = &traceIDHigh
	}
	timestamp := utils.TimeToMicrosecondsSinceEpochInt64(span.startTime)
	duration := span.duration.Nanoseconds() / int64(time.Microsecond)
	endpoint := &z.Endpoint{
		ServiceName: span.tracer.serviceName,
		Ipv4:        int32(span.tracer.hostIPv4)}
	thriftSpan := &z.Span{
		TraceID:           int64(span.context.traceID.Low),
		TraceIDHigh:       ptrTraceIDHigh,
		ID:                int64(span.context.spanID),
		ParentID:          ptrParentID,
		Name:              span.operationName,
		Timestamp:         &timestamp,
		Duration:          &duration,
		Debug:             span.context.IsDebug(),
		Annotations:       buildAnnotations(span, endpoint),
		BinaryAnnotations: buildBinaryAnnotations(span, endpoint)}
	return thriftSpan
}
1141544
func (p *StoragePool) Build(flags StoragePoolBuildFlags) error {
	var err C.virError
	result := C.virStoragePoolBuildWrapper(p.ptr, C.uint(flags), &err)
	if result == -1 {
		return makeError(&err)
	}
	return nil
}
738904
func FromThriftToPrimaryKey(key *dosarpc.PrimaryKey) *dosa.PrimaryKey {
	pk := key.PartitionKeys
	ck := make([]*dosa.ClusteringKey, len(key.ClusteringKeys))
	for i, v := range key.ClusteringKeys {
		ck[i] = &dosa.ClusteringKey{
			Name:       *v.Name,
			Descending: !*v.Asc,
		}
	}

	return &dosa.PrimaryKey{
		PartitionKeys:  pk,
		ClusteringKeys: ck,
	}
}
277167
func PackBytesGzip(box string, name string, bb []byte) error {
	// TODO: this function never did what it was supposed to do!
	PackBytes(box, name, bb)
	return nil
}
638914
func BuildJaegerProcessThrift(span *Span) *j.Process {
	span.Lock()
	defer span.Unlock()
	return buildJaegerProcessThrift(span.tracer)
}
771454
func (f *FileAssetsBuilder) Build(c *fi.ModelBuilderContext) error {
	// used to keep track of previous file, so a instanceGroup can override a cluster wide one
	tracker := make(map[string]bool, 0)

	// ensure the default path exists
	c.EnsureTask(&nodetasks.File{
		Path: f.FileAssetsDefaultPath(),
		Type: nodetasks.FileType_Directory,
		Mode: s("0755"),
	})

	// do we have any instanceGroup file assets
	if f.InstanceGroup.Spec.FileAssets != nil {
		if err := f.buildFileAssets(c, f.InstanceGroup.Spec.FileAssets, tracker); err != nil {
			return err
		}
	}
	if f.Cluster.Spec.FileAssets != nil {
		if err := f.buildFileAssets(c, f.Cluster.Spec.FileAssets, tracker); err != nil {
			return err
		}
	}

	return nil
}
1153668
func AddToZip(zipWriter *zip.Writer, source string, rootSource string, logger *logrus.Logger) error {
	return AnnotateAddToZip(zipWriter, source, rootSource, nil, logger)
}
673673
func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error {
	if !strings.HasPrefix(fn.Runtime, "clojure") {
		return nil
	}

	jar := filepath.Join(fn.Path, "target", jarFile)
	if _, err := os.Stat(jar); err != nil {
		return errors.Errorf("missing jar file %q", jar)
	}

	fn.Log.Debug("appending compiled files")
	reader, err := azip.OpenReader(jar)
	if err != nil {
		return errors.Wrap(err, "opening zip")
	}
	defer reader.Close()

	for _, file := range reader.File {
		parts := strings.Split(file.Name, ".")
		ext := parts[len(parts)-1]

		if ext == "clj" || ext == "cljx" || ext == "cljc" {
			continue
		}

		r, err := file.Open()
		if err != nil {
			return errors.Wrap(err, "opening file")
		}

		b, err := ioutil.ReadAll(r)
		if err != nil {
			return errors.Wrap(err, "reading file")
		}
		r.Close()

		zip.AddBytes(file.Name, b)
	}

	return nil
}
1061620
func SerializeThrift(s athrift.TStruct) ([]byte, error) {
	var b []byte
	var buffer = bytes.NewBuffer(b)

	transport := athrift.NewStreamTransportW(buffer)
	if err := s.Write(athrift.NewTBinaryProtocolTransport(transport)); err != nil {
		return nil, err
	}

	if err := transport.Flush(); err != nil {
		return nil, err
	}
	return buffer.Bytes(), nil
}
393736
func writeZip(writer io.Writer, files []fileEntry) error {
	zipWriter := zip.NewWriter(writer)
	defer zipWriter.Close()

	for _, file := range files {
		zipFile, err := zipWriter.Create(file.name)
		if err != nil {
			return err
		}

		_, err = zipFile.Write(file.data)
		if err != nil {
			return err
		}
	}

	return zipWriter.Close()
}
1154754
func WriteZip(w io.Writer, fs VFS) error {
	zw := zip.NewWriter(w)
	err := copyVFS(fs, func(p string, info os.FileInfo, f io.Reader) error {
		hdr, err := zip.FileInfoHeader(info)
		if err != nil {
			return err
		}
		hdr.Name = p
		fw, err := zw.CreateHeader(hdr)
		if err != nil {
			return err
		}
		_, err = io.Copy(fw, f)
		return err
	})
	if err != nil {
		return err
	}
	return zw.Close()
}
795453
func (IndexingNotSupported) Build(context.Context, Transaction, ast.Ref) (Index, error) {
	return nil, indexingNotSupportedError()
}
1033819
func buildHeap(stuff Sortable) {
	for i := stuff.Len()/2 - 1; i >= 0; i-- { // start at first non leaf (equiv. to parent of last leaf)
		shuffleDown(stuff, i, stuff.Len())
	}
}
999112
func WriteTarGzip(w io.Writer, fs VFS) error {
	gw, err := gzip.NewWriterLevel(w, gzip.BestCompression)
	if err != nil {
		return err
	}
	if err := WriteTar(gw, fs); err != nil {
		return err
	}
	return gw.Close()
}
971904
func (p *IndexFiles) TagKeyIterator(name []byte) (TagKeyIterator, error) {
	a := make([]TagKeyIterator, 0, len(*p))
	for _, f := range *p {
		itr := f.TagKeyIterator(name)
		if itr == nil {
			continue
		}
		a = append(a, itr)
	}
	return MergeTagKeyIterators(a...), nil
}
1096667
func (p *parser) build(t *Token) (Pattern, Error) {
	// attempt to create a valid pattern
	switch t.Type {
	// we have a negated pattern
	case NEGATION:
		return p.negation(t)

	// attempt to build a path specification
	default:
		return p.path(t)
	}
}
863502
func (i *Index) TagKeyIterator(name []byte) (tsdb.TagKeyIterator, error) {
	a := make([]tsdb.TagKeyIterator, 0, len(i.partitions))
	for _, p := range i.partitions {
		itr, err := p.TagKeyIterator(name)
		if err != nil {
			for _, itr := range a {
				itr.Close()
			}
			return nil, err
		} else if itr != nil {
			a = append(a, itr)
		}
	}
	return tsdb.MergeTagKeyIterators(a...), nil
}