当前位置: 首页>>代码示例>>Golang>>正文


Golang Raw.Data方法代码示例

本文整理汇总了Golang中gopkg/in/mgo/v2/bson.Raw.Data方法的典型用法代码示例。如果您正苦于以下问题:Golang Raw.Data方法的具体用法?Golang Raw.Data怎么用?Golang Raw.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gopkg/in/mgo/v2/bson.Raw的用法示例。


在下文中一共展示了Raw.Data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Debug

func (bd *BSONDump) Debug() error {
	stream, err := bd.init()
	if err != nil {
		return err
	}

	defer stream.Close()

	reusableBuf := make([]byte, db.MaxBSONSize)
	var result bson.Raw
	for {
		hasDoc, docSize := stream.LoadNextInto(reusableBuf)
		if !hasDoc {
			break
		}
		result.Kind = reusableBuf[0]
		result.Data = reusableBuf[0:docSize]
		err = DebugBSON(result, 0, os.Stdout)
		if err != nil {
			return err
		}
	}
	if err := stream.Err(); err != nil {
		return err
	}
	return nil
}
开发者ID:shelman,项目名称:mongo-tools-proto,代码行数:27,代码来源:bsondump.go

示例2: Debug

// Debug iterates through the BSON file and for each document it finds,
// recursively descends into objects and arrays and prints a human readable
// BSON representation containing the type and size of each field.
// It returns the number of documents processed and a non-nil error if one is
// encountered before the end of the file is reached.
func (bd *BSONDump) Debug() (int, error) {
	numFound := 0

	if bd.bsonSource == nil {
		panic("Tried to call Debug() before opening file")
	}

	defer bd.bsonSource.Close()

	reusableBuf := make([]byte, db.MaxBSONSize)
	var result bson.Raw
	for {
		hasDoc, docSize := bd.bsonSource.LoadNextInto(reusableBuf)
		if !hasDoc {
			break
		}
		result.Data = reusableBuf[0:docSize]

		if bd.BSONDumpOptions.ObjCheck {
			validated := bson.M{}
			err := bson.Unmarshal(result.Data, &validated)
			if err != nil {
				// ObjCheck is turned on and we hit an error, so short-circuit now.
				return numFound, fmt.Errorf("failed to validate bson during objcheck: %v", err)
			}
		}
		err := printBSON(result, 0, bd.Out)
		if err != nil {
			log.Logf(log.Always, "encountered error debugging BSON data: %v", err)
		}
		numFound++
	}

	if err := bd.bsonSource.Err(); err != nil {
		// This error indicates the BSON document header is corrupted;
		// either the 4-byte header couldn't be read in full, or
		// the size in the header would require reading more bytes
		// than the file has left
		return numFound, err
	}
	return numFound, nil
}
开发者ID:eshujiushiwo,项目名称:mongo-tools,代码行数:47,代码来源:bsondump.go


注:本文中的gopkg/in/mgo/v2/bson.Raw.Data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。