forked from mongodb/mongo-tools
/
unknown_op.go
49 lines (40 loc) · 1.21 KB
/
unknown_op.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package mongoreplay
import (
"fmt"
"io"
mgo "github.com/10gen/llmgo"
)
// UnknownOp is not a real mongo Op but represents an unrecognized or corrupted op
type UnknownOp struct {
Header MsgHeader
Body []byte
}
// Meta returns metadata about the UnknownOp, for which there is none
func (op *UnknownOp) Meta() OpMetadata {
return OpMetadata{"", "", "", nil}
}
func (op *UnknownOp) String() string {
return fmt.Sprintf("OpUnkown: %v", op.Header.OpCode)
}
// Abbreviated returns a serialization of the UnknownOp, abbreviated so it
// doesn't exceed the given number of characters.
func (op *UnknownOp) Abbreviated(chars int) string {
return fmt.Sprintf("%v", op)
}
// OpCode returns the OpCode for an UnknownOp.
func (op *UnknownOp) OpCode() OpCode {
return op.Header.OpCode
}
// FromReader extracts data from a serialized UnknownOp into its concrete structure.
func (op *UnknownOp) FromReader(r io.Reader) error {
if op.Header.MessageLength < MsgHeaderLen {
return nil
}
op.Body = make([]byte, op.Header.MessageLength-MsgHeaderLen)
_, err := io.ReadFull(r, op.Body)
return err
}
// Execute doesn't do anything for an UnknownOp
func (op *UnknownOp) Execute(session *mgo.Session) (*ReplyOp, error) {
return nil, nil
}