Skip to content

Commit 3603ec7

Browse files
committed
Merge branch 'pr/85'
Change-Id: Iba05860c670857bdaadb394a5d05e410d3746fab
2 parents cf1b35a + 83d7a3a commit 3603ec7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

bson/value.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,16 @@ func (v *Value) Binary() (subtype byte, data []byte) {
553553
return st, b
554554
}
555555

556+
// BinaryOK is the same as Binary, except it returns a boolean instead of
557+
// panicking.
558+
func (v *Value) BinaryOK() (subtype byte, data []byte, ok bool) {
559+
if v == nil || v.offset == 0 || v.data == nil || Type(v.data[v.start]) != TypeBinary {
560+
return 0x00, nil, false
561+
}
562+
st, b := v.Binary()
563+
return st, b, true
564+
}
565+
556566
// ObjectID returns the BSON objectid value the Value represents. It panics if the value is a BSON
557567
// type other than objectid.
558568
func (v *Value) ObjectID() objectid.ObjectID {

0 commit comments

Comments
 (0)