コード例 #1
0
ファイル: bson_test.go プロジェクト: shopsmart/mgo
func (s *S) TestObjectIdJSONUnmarshaling(c *C) {
	data := []byte(`{"Id":"4d88e15b60f486e428412dc9"}`)
	v := jsonType{}
	err := json.Unmarshal(data, &v)
	c.Assert(err, IsNil)
	c.Assert(*v.Id, Equals, bson.ObjectIdHex("4d88e15b60f486e428412dc9"))
}
コード例 #2
0
ファイル: bson_test.go プロジェクト: shopsmart/mgo
func (s *S) TestObjectIdJSONMarshaling(c *C) {
	id := bson.ObjectIdHex("4d88e15b60f486e428412dc9")
	v := jsonType{Id: &id}
	data, err := json.Marshal(&v)
	c.Assert(err, IsNil)
	c.Assert(string(data), Equals, `{"Id":"4d88e15b60f486e428412dc9"}`)
}
コード例 #3
0
ファイル: txn.go プロジェクト: shopsmart/mgo
func (tt token) id() bson.ObjectId { return bson.ObjectIdHex(string(tt[:24])) }
コード例 #4
0
ファイル: bson_test.go プロジェクト: shopsmart/mgo
func (s *S) TestObjectIdHex(c *C) {
	id := bson.ObjectIdHex("4d88e15b60f486e428412dc9")
	c.Assert(id.String(), Equals, `ObjectIdHex("4d88e15b60f486e428412dc9")`)
	c.Assert(id.Hex(), Equals, "4d88e15b60f486e428412dc9")
}
コード例 #5
0
ファイル: bson_test.go プロジェクト: shopsmart/mgo
}

// --------------------------------------------------------------------------
// ObjectId parts extraction tests.

type objectIdParts struct {
	id        bson.ObjectId
	timestamp int64
	machine   []byte
	pid       uint16
	counter   int32
}

var objectIds = []objectIdParts{
	objectIdParts{
		bson.ObjectIdHex("4d88e15b60f486e428412dc9"),
		1300816219,
		[]byte{0x60, 0xf4, 0x86},
		0xe428,
		4271561,
	},
	objectIdParts{
		bson.ObjectIdHex("000000000000000000000000"),
		0,
		[]byte{0x00, 0x00, 0x00},
		0x0000,
		0,
	},
	objectIdParts{
		bson.ObjectIdHex("00000000aabbccddee000001"),
		0,