-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchunk.go
41 lines (38 loc) · 1.06 KB
/
chunk.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
package imux
import (
log "github.com/Sirupsen/logrus"
"github.com/hkparker/TLB"
"gopkg.in/mgo.v2/bson"
)
// A chunk represents a piece of information exchanged between a
// socket on the client side and a socket on the server size. A
// session ID defines sockets that are part of one imux session,
// while the socket ID specifies which socket a chunk should queue
// into, ordered by the Sequence ID.
type Chunk struct {
SessionID string
SocketID string
SequenceID uint64
Data []byte
Close bool
Setup bool
}
// TLB code to unpack Chunk data into an interface
func buildChunk(data []byte, _ tlb.TLBContext) interface{} {
chunk := &Chunk{}
err := bson.Unmarshal(data, &chunk)
if err != nil {
log.WithFields(log.Fields{
"at": "BuildChunk",
"error": err.Error(),
}).Error("error unmarshaling chunk data")
return nil
}
log.WithFields(log.Fields{
"at": "BuildChunk",
"sequence_id": chunk.SequenceID,
"socket_id": chunk.SocketID,
"session_id": chunk.SessionID,
}).Debug("unmarshalled chunk data")
return chunk
}