// mongodump outputs collections as binary files with all the documents appended together.
// The first four bytes are the size of the full document, including the size bytes.
979985
func New(r io.Reader) *Scanner {
	scanner := NewScanner(r)
	scanner.Split(func(data []byte, atEOF bool) (int, []byte, error) {
		if len(data) < 4 {
			return needMoreData()
		}

		var size int32
		if err := binary.Read(bytes.NewBuffer(data[0:4]), binary.LittleEndian, &size); err != nil {
			return 0, nil, err
		}

		if int(size) > len(data) {
			return needMoreData()
		}

		return int(size), data[0:size], nil
	})
	return scanner
}
27972
func interfaceDump(ch api.Channel) {
	fmt.Println("Dumping interfaces")

	reqCtx := ch.SendMultiRequest(&interfaces.SwInterfaceDump{})

	for {
		msg := &interfaces.SwInterfaceDetails{}
		stop, err := reqCtx.ReceiveReply(msg)
		if stop {
			break
		}
		if err != nil {
			fmt.Println("ERROR:", err)
		}
		ifaceName := strings.TrimFunc(string(msg.InterfaceName), func(r rune) bool {
			return r == 0x00
		})
		fmt.Printf("Interface %q: %+v\n", ifaceName, msg)
	}
}
302207
func (o Output) DebugDump() {
	for _, f := range o.Files() {
		fmt.Println("--------------------------------------------------")
		fmt.Println(f)
		fmt.Println("--------------------------------------------------")
		fmt.Print(string(o.Data[f]))
		fmt.Println("--------------------------------------------------")
	}
}
386465
func (c *Chunk) AppendBytes(colIdx int, b []byte) {
	c.columns[colIdx].appendBytes(b)
}
72598
func BuildDump(ctx context.Context, cloud fi.Cloud, resources map[string]*Resource) (*Dump, error) {
	dump := &Dump{}
	op := &DumpOperation{
		Context: ctx,
		Cloud:   cloud,
		Dump:    dump,
	}

	for k, r := range resources {
		if r.Dumper == nil {
			glog.V(8).Infof("skipping dump of %q (does not implement Dumpable)", k)
			continue
		}

		err := r.Dumper(op, r)
		if err != nil {
			return nil, fmt.Errorf("error dumping %q: %v", k, err)
		}
	}

	sort.SliceStable(dump.Instances, func(i, j int) bool { return dump.Instances[i].Name < dump.Instances[j].Name })

	return dump, nil
}
715424
func ParseMongoVersion(versionInfo string) (Version, error) {
	m := mongoVersionRegex.FindStringSubmatch(versionInfo)
	if m == nil {
		return Version{}, errors.Errorf("'mongod --version' reported:\n%s", versionInfo)
	}
	if len(m) < 4 {
		return Version{}, errors.Errorf("did not find enough version parts in:\n%s", versionInfo)
	}
	var v Version
	var err error
	// Index '[0]' is the full matched string,
	// [1] is the Major
	// [2] is the Minor
	// [3] is the Point
	// [4] is the Patch to the end of the line
	if v.Major, err = strconv.Atoi(m[1]); err != nil {
		return Version{}, errors.Annotatef(err, "invalid major version: %q", versionInfo)
	}
	if v.Minor, err = strconv.Atoi(m[2]); err != nil {
		return Version{}, errors.Annotatef(err, "invalid minor version: %q", versionInfo)
	}
	if v.Point, err = strconv.Atoi(m[3]); err != nil {
		return Version{}, errors.Annotatef(err, "invalid point version: %q", versionInfo)
	}
	if len(m) > 4 {
		// strip off the beginning '.' or '-', and make sure there is something after it
		tail := m[4]
		if len(tail) > 1 {
			v.Patch = tail[1:]
		}
	}
	return v, nil
}
958315
func mongoInfo() mongo.MongoInfo {
	if gitjujutesting.MgoServer.Addr() == "" {
		panic("dummy environ state tests must be run with MgoTestPackage")
	}
	mongoPort := strconv.Itoa(gitjujutesting.MgoServer.Port())
	addrs := []string{net.JoinHostPort("localhost", mongoPort)}
	return mongo.MongoInfo{
		Info: mongo.Info{
			Addrs:      addrs,
			CACert:     testing.CACert,
			DisableTLS: !gitjujutesting.MgoServer.SSLEnabled(),
		},
	}
}
1262500
func preallocFileSizes(totalSize int) []int {
	// Divide the total size into 512MB chunks, and
	// then round up the remaining chunk to a multiple
	// of 4096 bytes.
	const maxChunkSize = 512 * 1024 * 1024
	var sizes []int
	remainder := totalSize % maxChunkSize
	if remainder > 0 {
		aligned := remainder + preallocAlign - 1
		aligned = aligned - (aligned % preallocAlign)
		sizes = []int{aligned}
	}
	for i := 0; i < totalSize/maxChunkSize; i++ {
		sizes = append(sizes, maxChunkSize)
	}
	return sizes
}
36563
func (l *Literal) Blob() ([]byte, error) {
	if l.t != Blob {
		return nil, fmt.Errorf("literal.Blob: literal is of type %v; cannot be converted to a []byte", l.t)
	}
	return l.v.([]byte), nil
}
91899
func (p *PreFilter) Dump(to []string) ([]string, int64) {
	p.mutex.RLock()
	defer p.mutex.RUnlock()
	for i := prefixesV4Dyn; i < mapCount; i++ {
		to = p.dumpOneMap(i, to)
	}
	return to, p.revision
}
1094644
func (db *Database) NewBulkDocument() *BulkDocument {
	b := &BulkDocument{}
	b.db = db
	return b
}
832221
func numChunks(b []byte) int {
	lenB := len(b)
	if lenB <= ChunkSize {
		return 1
	}
	return len(b)/chunkedDataLen + 1
}
1322334
func (f FibmapFile) Fibmap(block uint) (uint, syscall.Errno) {
	_, _, err := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), FIBMAP, uintptr(unsafe.Pointer(&block)))
	return block, err
}
1164946
func NewEmptySnapshot() *Snapshot {
	return &Snapshot{
		Modules: map[string]*SnapshotModule{
			"": &SnapshotModule{
				Files: map[string][]byte{},
			},
		},
	}
}
229848
func (b *BmPrefix) Dump(indent string) string {
	buf := &bytes.Buffer{}

	fmt.Fprintf(buf, "%sBM Pattern: %s\n%sPositive: ", indent, string(b.pattern), indent)
	for i := 0; i < len(b.positive); i++ {
		buf.WriteString(strconv.Itoa(b.positive[i]))
		buf.WriteRune(' ')
	}
	buf.WriteRune('\n')

	if b.negativeASCII != nil {
		buf.WriteString(indent)
		buf.WriteString("Negative table\n")
		for i := 0; i < len(b.negativeASCII); i++ {
			if b.negativeASCII[i] != len(b.pattern) {
				fmt.Fprintf(buf, "%s  %s %s\n", indent, Escape(string(rune(i))), strconv.Itoa(b.negativeASCII[i]))
			}
		}
	}

	return buf.String()
}
181455
func (m *Internal) NodeDump(args *structs.DCSpecificRequest,
	reply *structs.IndexedNodeDump) error {
	if done, err := m.srv.forward("Internal.NodeDump", args, args, reply); done {
		return err
	}

	filter, err := bexpr.CreateFilter(args.Filter, nil, reply.Dump)
	if err != nil {
		return err
	}

	return m.srv.blockingQuery(
		&args.QueryOptions,
		&reply.QueryMeta,
		func(ws memdb.WatchSet, state *state.Store) error {
			index, dump, err := state.NodeDump(ws)
			if err != nil {
				return err
			}

			reply.Index, reply.Dump = index, dump
			if err := m.srv.filterACL(args.Token, reply); err != nil {
				return err
			}

			raw, err := filter.Execute(reply.Dump)
			if err != nil {
				return err
			}

			reply.Dump = raw.(structs.NodeDump)
			return nil
		})
}
342725
func (r *multiModelRunner) mungeBsonDUpdate(updateDoc bson.D) (bson.D, error) {
	outDoc := make(bson.D, 0, len(updateDoc))
	for _, elem := range updateDoc {
		if elem.Name == "$set" {
			newSetDoc, err := mungeDocForMultiModel(elem.Value, r.modelUUID, 0)
			if err != nil {
				return nil, errors.Trace(err)
			}
			elem = bson.DocElem{elem.Name, newSetDoc}
		}
		outDoc = append(outDoc, elem)
	}
	return outDoc, nil
}