@@ -75,3 +75,35 @@ func MakeReply(doc bsoncore.Document) []byte {
75
75
dst = append (dst , doc ... )
76
76
return bsoncore .UpdateLength (dst , idx , int32 (len (dst [idx :])))
77
77
}
78
+
79
+ // GetCommandFromQueryWireMessage returns the command sent in an OP_QUERY wire message.
80
+ func GetCommandFromQueryWireMessage (wm []byte ) (bsoncore.Document , error ) {
81
+ var ok bool
82
+ _ , _ , _ , _ , wm , ok = wiremessage .ReadHeader (wm )
83
+ if ! ok {
84
+ return nil , errors .New ("could not read header" )
85
+ }
86
+ _ , wm , ok = wiremessage .ReadQueryFlags (wm )
87
+ if ! ok {
88
+ return nil , errors .New ("could not read flags" )
89
+ }
90
+ _ , wm , ok = wiremessage .ReadQueryFullCollectionName (wm )
91
+ if ! ok {
92
+ return nil , errors .New ("could not read fullCollectionName" )
93
+ }
94
+ _ , wm , ok = wiremessage .ReadQueryNumberToSkip (wm )
95
+ if ! ok {
96
+ return nil , errors .New ("could not read numberToSkip" )
97
+ }
98
+ _ , wm , ok = wiremessage .ReadQueryNumberToReturn (wm )
99
+ if ! ok {
100
+ return nil , errors .New ("could not read numberToReturn" )
101
+ }
102
+
103
+ var query bsoncore.Document
104
+ query , wm , ok = wiremessage .ReadQueryQuery (wm )
105
+ if ! ok {
106
+ return nil , errors .New ("could not read query" )
107
+ }
108
+ return query , nil
109
+ }
0 commit comments