@@ -598,9 +598,9 @@ how long each field in that buffer will be.
598
598
The caller passes in how many integer selectors are expected to be
599
599
returned, as well as the maximum length of the char buffer to be returned
600
600
601
- This function is a direct mapping of the MQI C function. It should be considered
601
+ Deprecated: This function is a direct mapping of the MQI C function. It should be considered
602
602
deprecated. In preference, use the InqMap function which provides a more convenient
603
- API.
603
+ API. In a future version of this package, Inq will be replaced by InqMap
604
604
*/
605
605
func (object MQObject ) Inq (goSelectors []int32 , intAttrCount int , charAttrLen int ) ([]int32 ,
606
606
[]byte , error ) {
@@ -656,6 +656,8 @@ func (object MQObject) Inq(goSelectors []int32, intAttrCount int, charAttrLen in
656
656
* and the return value consists of a map whose elements are
657
657
* a) accessed via the selector
658
658
* b) varying datatype (integer, string, string array) based on the selector
659
+ * In a future breaking update, this function will become the default Inq()
660
+ * implementation.
659
661
*/
660
662
func (object MQObject ) InqMap (goSelectors []int32 ) (map [int32 ]interface {}, error ) {
661
663
var mqrc C.MQLONG
@@ -701,7 +703,7 @@ func (object MQObject) InqMap(goSelectors []int32) (map[int32]interface{}, error
701
703
return nil , & mqreturn
702
704
}
703
705
704
- // Create a map of the selectors to the returned values
706
+ // Create a map of the selectors to the returned values
705
707
returnedMap := make (map [int32 ]interface {})
706
708
707
709
// Get access to the returned character data
@@ -736,7 +738,7 @@ func (object MQObject) InqMap(goSelectors []int32) (map[int32]interface{}, error
736
738
charLength = C .MQ_OBJECT_NAME_LENGTH
737
739
names := make ([]string , c )
738
740
for j := 0 ; j < c ; j ++ {
739
- name := string (goCharAttrs [charOffset : charOffset + charLength ])
741
+ name := string (goCharAttrs [charOffset : charOffset + charLength ])
740
742
idx := strings .IndexByte (name , 0 )
741
743
if idx != - 1 {
742
744
name = name [0 :idx ]
@@ -750,7 +752,7 @@ func (object MQObject) InqMap(goSelectors []int32) (map[int32]interface{}, error
750
752
}
751
753
} else {
752
754
charLength = getAttrLength (s )
753
- name := string (goCharAttrs [charOffset : charOffset + charLength ])
755
+ name := string (goCharAttrs [charOffset : charOffset + charLength ])
754
756
idx := strings .IndexByte (name , 0 )
755
757
if idx != - 1 {
756
758
name = name [0 :idx ]
@@ -765,6 +767,108 @@ func (object MQObject) InqMap(goSelectors []int32) (map[int32]interface{}, error
765
767
return returnedMap , nil
766
768
}
767
769
770
+ /*
771
+ * Set is the function that wraps MQSET. The single parameter is a map whose
772
+ * elements contain an MQIA/MQCA selector with either a string or an int32 for
773
+ * the value.
774
+ */
775
+ func (object MQObject ) Set (goSelectors map [int32 ]interface {}) error {
776
+ var mqrc C.MQLONG
777
+ var mqcc C.MQLONG
778
+
779
+ var charAttrs []byte
780
+ var charAttrsPtr C.PMQCHAR
781
+ var intAttrs []int32
782
+ var intAttrsPtr C.PMQLONG
783
+ var charOffset int
784
+ var charLength int
785
+
786
+ // Pass through the map twice. First time lets us
787
+ // create an array of selector names from map keys which is then
788
+ // used to calculate the character buffer that's needed
789
+ selectors := make ([]int32 , len (goSelectors ))
790
+ i := 0
791
+ for k , _ := range goSelectors {
792
+ selectors [i ] = k
793
+ i ++
794
+ }
795
+
796
+ intAttrCount , _ , charAttrLen := getAttrInfo (selectors )
797
+
798
+ // Create the areas to be used for the separate char and int values
799
+ if intAttrCount > 0 {
800
+ intAttrs = make ([]int32 , intAttrCount )
801
+ intAttrsPtr = (C .PMQLONG )(unsafe .Pointer (& intAttrs [0 ]))
802
+ } else {
803
+ intAttrsPtr = nil
804
+ }
805
+
806
+ if charAttrLen > 0 {
807
+ charAttrs = make ([]byte , charAttrLen )
808
+ charAttrsPtr = (C .PMQCHAR )(unsafe .Pointer (& charAttrs [0 ]))
809
+ } else {
810
+ charAttrsPtr = nil
811
+ }
812
+
813
+ // Walk through the map a second time
814
+ charOffset = 0
815
+ intAttr := 0
816
+ for i := 0 ; i < len (selectors ); i ++ {
817
+ s := selectors [i ]
818
+ if s >= C .MQCA_FIRST && s <= C .MQCA_LAST {
819
+ // The character processing is a bit OTT since there is in reality
820
+ // only a single attribute that can ever be SET. But a general purpose
821
+ // function looks more like the MQINQ operation
822
+ v := goSelectors [s ].(string )
823
+ charLength = getAttrLength (s )
824
+ vBytes := []byte (v )
825
+ b := byte (0 )
826
+ for j := 0 ; j < charLength ; j ++ {
827
+ if j < len (vBytes ) {
828
+ b = vBytes [j ]
829
+ } else {
830
+ b = 0
831
+ }
832
+ charAttrs [charOffset + j ] = b
833
+ }
834
+ charOffset += charLength
835
+ } else if s >= C .MQIA_FIRST && s <= C .MQIA_LAST {
836
+ vv := int32 (0 )
837
+ v := goSelectors [s ]
838
+ // Force the returned value from the map to be int32 because we
839
+ // can't check it at compile time.
840
+ if _ ,ok := v .(int32 );ok {
841
+ vv = v .(int32 )
842
+ } else if _ ,ok := v .(int );ok {
843
+ vv = int32 (v .(int ))
844
+ }
845
+ intAttrs [intAttr ] = vv
846
+ intAttr ++
847
+ }
848
+ }
849
+
850
+ // Pass in the selectors
851
+ C .MQSET (object .qMgr .hConn , object .hObj ,
852
+ C .MQLONG (len (selectors )),
853
+ C .PMQLONG (unsafe .Pointer (& selectors [0 ])),
854
+ C .MQLONG (intAttrCount ),
855
+ intAttrsPtr ,
856
+ C .MQLONG (charAttrLen ),
857
+ charAttrsPtr ,
858
+ & mqcc , & mqrc )
859
+
860
+ mqreturn := MQReturn {MQCC : int32 (mqcc ),
861
+ MQRC : int32 (mqrc ),
862
+ verb : "MQSET" ,
863
+ }
864
+
865
+ if mqcc != C .MQCC_OK {
866
+ return & mqreturn
867
+ }
868
+
869
+ return nil
870
+ }
871
+
768
872
/*********** Message Handles and Properties ****************/
769
873
770
874
/*
0 commit comments