forked from yurist/mqlambdatm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqtm.go
48 lines (39 loc) · 1.36 KB
/
mqtm.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
package main
/*
#cgo CFLAGS: -I/opt/mqm/inc -D_REENTRANT
#include <stdlib.h>
#include <string.h>
#include <cmqc.h>
*/
import "C"
import (
"unsafe"
)
// MQTM struct defines Go mapping of C MQTM struct
// JSON annotations are required so that the marshalled JSON object can be deserialized
// as a Java bean - capitalized field names do not work
type MQTM struct {
StrucId string `json:"strucId"`
Version int32 `json:"version"`
QName string `json:"qName"`
ProcessName string `json:"processName"`
TriggerData string `json:"triggerData"`
ApplType int32 `json:"applType"`
ApplId string `json:"applId"`
EnvData string `json:"envData"`
UserData string `json:"userData"`
}
// TMfromC function converts C MQTM buffer into Go MQTM struct
func TMfromC(buffer []byte) (gotm MQTM) {
mqtm := (C.PMQTM)(unsafe.Pointer(&buffer[0]))
gotm.StrucId = C.GoStringN((*C.char)(&mqtm.StrucId[0]), 4)
gotm.Version = int32(mqtm.Version)
gotm.QName = C.GoStringN((*C.char)(&mqtm.QName[0]), 48)
gotm.ProcessName = C.GoStringN((*C.char)(&mqtm.ProcessName[0]), 48)
gotm.TriggerData = C.GoStringN((*C.char)(&mqtm.TriggerData[0]), 64)
gotm.ApplType = int32(mqtm.ApplType)
gotm.ApplId = C.GoStringN((*C.char)(&mqtm.ApplId[0]), 256)
gotm.EnvData = C.GoStringN((*C.char)(&mqtm.EnvData[0]), 128)
gotm.UserData = C.GoStringN((*C.char)(&mqtm.UserData[0]), 128)
return
}