Skip to content

Commit 16b792f

Browse files
committed
Add ByteString and StringFilter as PCF output types
1 parent 3c8efed commit 16b792f

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

ibmmq/mqiPCF.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,50 @@ func (p *PCFParameter) Bytes() []byte {
280280
endian.PutUint32(buf[offset:], uint32(len(p.String[0])))
281281
offset += 4
282282
copy(buf[offset:], []byte(p.String[0]))
283+
284+
case C.MQCFT_STRING_FILTER:
285+
// Use "\000" as the string if you need an empty/null parameter
286+
fv := p.Filter.FilterValue.(string)
287+
288+
buf = make([]byte, C.MQCFSF_STRUC_LENGTH_FIXED+roundTo4(int32(len(fv))))
289+
offset := 0
290+
endian.PutUint32(buf[offset:], uint32(p.Type))
291+
offset += 4
292+
endian.PutUint32(buf[offset:], uint32(len(buf)))
293+
offset += 4
294+
endian.PutUint32(buf[offset:], uint32(p.Filter.Parameter))
295+
offset += 4
296+
endian.PutUint32(buf[offset:], uint32(p.Filter.Operator))
297+
offset += 4
298+
endian.PutUint32(buf[offset:], uint32(C.MQCCSI_DEFAULT))
299+
offset += 4
300+
endian.PutUint32(buf[offset:], uint32(len(fv)))
301+
offset += 4
302+
copy(buf[offset:], []byte(fv))
303+
304+
// Expect to be given a string that can be decoded into bytes. For example, "aabb12".
305+
// Return nil if the bytestring cannot be converted from the hex
306+
case C.MQCFT_BYTE_STRING:
307+
bs, err := hex.DecodeString(p.String[0])
308+
if err != nil {
309+
// Can't easily change to return or report the error without breaking existing apps.
310+
logError("Trying to serialise PCF ByteString parameter \"%s\" : %v\n", p.String[0], err)
311+
return nil
312+
}
313+
buf = make([]byte, C.MQCFST_STRUC_LENGTH_FIXED+roundTo4(int32(len(bs))))
314+
offset := 0
315+
endian.PutUint32(buf[offset:], uint32(p.Type))
316+
offset += 4
317+
endian.PutUint32(buf[offset:], uint32(len(buf)))
318+
offset += 4
319+
endian.PutUint32(buf[offset:], uint32(p.Parameter))
320+
offset += 4
321+
endian.PutUint32(buf[offset:], uint32(len(bs)))
322+
offset += 4
323+
copy(buf[offset:], bs)
324+
283325
default:
284-
fmt.Printf("mqiPCF.go: Trying to serialise PCF parameter. Unknown PCF type %d\n", p.Type)
326+
logError("mqiPCF.go: Trying to serialise PCF parameter. Unknown PCF type %d\n", p.Type)
285327
}
286328
return buf
287329
}

ibmmq/mqiattrs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ int addNewCharAttrs(MQLONG a[],MQLONG l[]) {
5959
*/
6060
import "C"
6161
import (
62-
"fmt"
6362
"os"
6463
"sync"
6564
)
@@ -150,7 +149,7 @@ func getAttrInfo(attrs []int32) (int, int, int) {
150149

151150
if addedAttrs < 0 {
152151
// Force an immediate exit if the arrays are not large enough.
153-
fmt.Printf("Error: mqiattrs.go: MAX_NEW_MQCA_ATTRS is too small. Increase from %d\n", C.MAX_NEW_MQCA_ATTRS)
152+
logError("mqiattrs.go: MAX_NEW_MQCA_ATTRS is too small. Increase from %d\n", C.MAX_NEW_MQCA_ATTRS)
154153
os.Exit(1)
155154
}
156155
for i := 0; i < addedAttrs; i++ {

ibmmq/mqitrace.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ func SetTrace(b bool) {
3939
}
4040

4141
func logTrace(format string, v ...interface{}) {
42-
if tracing {
42+
logInternal(tracing, format, v...)
43+
}
44+
45+
func logError(format string, v ...interface{}) {
46+
logInternal(true, "ERROR: "+format, v...)
47+
}
48+
49+
func logInternal(force bool, format string, v ...interface{}) {
50+
if force {
4351
d := time.Now().Format("2006-01-02T15:04:05.000")
4452
fmt.Fprintf(os.Stderr, "[ibmmq] %s : ", d)
4553
fmt.Fprintf(os.Stderr, format, v...)

0 commit comments

Comments
 (0)