當前位置: 首頁>>代碼示例>>Golang>>正文


Golang bson.Marshal函數代碼示例

本文整理匯總了Golang中launchpad/net/gobson/bson.Marshal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Marshal函數的具體用法?Golang Marshal怎麽用?Golang Marshal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Marshal函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: addBSON

func addBSON(b []byte, doc interface{}) ([]byte, os.Error) {
	data, err := bson.Marshal(doc)
	if err != nil {
		return b, err
	}
	return append(b, data...), nil
}
開發者ID:adamsxu,項目名稱:mgo,代碼行數:7,代碼來源:socket.go

示例2: TestMarshalOneWayItems

func (s *S) TestMarshalOneWayItems(c *C) {
	for _, item := range marshalItems {
		data, err := bson.Marshal(item.obj)
		c.Assert(err, IsNil)
		c.Assert(string(data), Equals, wrapInDoc(item.data))
	}
}
開發者ID:iron-io,項目名稱:gobson_temp,代碼行數:7,代碼來源:gobson_test.go

示例3: TestMarshalErrorItems

func (s *S) TestMarshalErrorItems(c *C) {
	for _, item := range marshalErrorItems {
		data, err := bson.Marshal(item.obj)
		c.Assert(err, Matches, item.data)
		c.Assert(data, IsNil)
	}
}
開發者ID:iron-io,項目名稱:gobson_temp,代碼行數:7,代碼來源:gobson_test.go

示例4: TestMarshalAllItems

func (s *S) TestMarshalAllItems(c *C) {
	for i, item := range allItems {
		data, err := bson.Marshal(item.obj)
		c.Assert(err, IsNil)
		c.Assert(string(data), Equals, wrapInDoc(item.data), Bug("Failed on item %d: %#v", i, item))
	}
}
開發者ID:iron-io,項目名稱:gobson_temp,代碼行數:7,代碼來源:gobson_test.go

示例5: TestMarshalSampleItems

func (s *S) TestMarshalSampleItems(c *C) {
	for i, item := range sampleItems {
		data, err := bson.Marshal(item.obj)
		c.Assert(err, IsNil)
		c.Assert(string(data), Equals, item.data,
			Bug("Failed on item %d", i))
	}
}
開發者ID:iron-io,項目名稱:gobson_temp,代碼行數:8,代碼來源:gobson_test.go

示例6: TestMarshalShortWithGetter

func (s *S) TestMarshalShortWithGetter(c *C) {
	obj := typeWithIntGetter{42}
	data, err := bson.Marshal(obj)
	c.Assert(err, IsNil)
	m := bson.M{}
	err = bson.Unmarshal(data, m)
	c.Assert(m["v"], Equals, 42)
}
開發者ID:iron-io,項目名稱:gobson_temp,代碼行數:8,代碼來源:gobson_test.go

示例7: testCrossPair

func testCrossPair(c *C, dump interface{}, load interface{}, bug interface{}) {
	//c.Logf("")
	zero := makeZeroDoc(load)
	data, err := bson.Marshal(dump)
	c.Assert(err, IsNil, bug)
	c.Logf("Data: %#v", string(data))
	err = bson.Unmarshal(data, zero)
	c.Assert(err, IsNil, bug)
	c.Assert(zero, Equals, load, bug)
}
開發者ID:iron-io,項目名稱:gobson_temp,代碼行數:10,代碼來源:gobson_test.go

示例8: SetInfo

// SetInfo changes the optional metadata associated with the file.
// For example:
//
//     file.SetInfo(bson.M{"inode": inode})
//
// It is a runtime error to call this function when the file is not open
// for writing.
func (file *GridFile) SetInfo(metadata interface{}) {
	file.assertMode(gfsWriting)
	data, err := bson.Marshal(metadata)
	file.m.Lock()
	if err != nil && file.err == nil {
		file.err = err
	} else {
		file.doc.Metadata = &bson.Raw{Data: data}
	}
	file.m.Unlock()
}
開發者ID:adamsxu,項目名稱:mgo,代碼行數:18,代碼來源:gridfs.go

示例9: TestMarshalAllItemsWithGetter

func (s *S) TestMarshalAllItemsWithGetter(c *C) {
	for i, item := range allItems {
		if item.data == "" {
			continue
		}
		obj := &docWithGetterField{}
		obj.Field = &typeWithGetter{item.obj.(bson.M)["_"]}
		data, err := bson.Marshal(obj)
		c.Assert(err, IsNil)
		c.Assert(string(data), Equals, wrapInDoc(item.data),
			Bug("Failed on item #%d", i))
	}
}
開發者ID:iron-io,項目名稱:gobson_temp,代碼行數:13,代碼來源:gobson_test.go

示例10: main

func main() {
	var inter [4]interface{}
	in1 := 1
	in2 := [...]int{1, 2, 3}
	in3 := []byte("womengde")
	in4 := "dfdfdfd"

	inter[0] = in1
	inter[1] = in2
	inter[2] = in3
	inter[3] = in4

	data, _ := bson.Marshal(inter)

	fmt.Printf("%#v\n", data)
	bson.Unmarshal(data, inter)

	fmt.Printf("%#v\n", inter)

}
開發者ID:notedit,項目名稱:code-snippets,代碼行數:20,代碼來源:test_interface.go

示例11: insertChunk

func (file *GridFile) insertChunk(data []byte) {
	n := file.chunk
	file.chunk++
	debugf("GridFile %p: adding to checksum: %q", file, string(data))
	file.wsum.Write(data)

	for file.doc.ChunkSize*file.wpending >= 1024*1024 {
		// Hold on.. we got a MB pending.
		file.c.Wait()
		if file.err != nil {
			return
		}
	}

	file.wpending++

	debugf("GridFile %p: inserting chunk %d with %d bytes", file, n, len(data))

	// We may not own the memory of data, so rather than
	// simply copying it, we'll marshal the document ahead of time.
	data, err := bson.Marshal(gfsChunk{bson.NewObjectId(), file.doc.Id, n, data})
	if err != nil {
		file.err = err
		return
	}

	go func() {
		err := file.gfs.Chunks.Insert(bson.Raw{Data: data})
		file.m.Lock()
		file.wpending--
		if err != nil && file.err == nil {
			file.err = err
		}
		file.c.Broadcast()
		file.m.Unlock()
	}()
}
開發者ID:adamsxu,項目名稱:mgo,代碼行數:37,代碼來源:gridfs.go

示例12: TestMarshalWholeDocumentWithGetter

func (s *S) TestMarshalWholeDocumentWithGetter(c *C) {
	obj := &typeWithGetter{sampleItems[0].obj}
	data, err := bson.Marshal(obj)
	c.Assert(err, IsNil)
	c.Assert(string(data), Equals, sampleItems[0].data)
}
開發者ID:iron-io,項目名稱:gobson_temp,代碼行數:6,代碼來源:gobson_test.go


注:本文中的launchpad/net/gobson/bson.Marshal函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。