1// +build !as_performance 2 3// Copyright 2013-2020 Aerospike, Inc. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// 9// http://www.apache.org/licenses/LICENSE-2.0 10// 11// Unless required by applicable law or agreed to in writing, software 12// distributed under the License is distributed on an "AS IS" BASIS, 13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14// See the License for the specific language governing permissions and 15// limitations under the License. 16 17package aerospike 18 19import ( 20 "reflect" 21 22 Buffer "github.com/aerospike/aerospike-client-go/utils/buffer" 23) 24 25// this function will only be set if the performance flag is not passed for build 26func init() { 27 multiObjectParser = batchParseObject 28 prepareReflectionData = concretePrepareReflectionData 29} 30 31func concretePrepareReflectionData(cmd *baseMultiCommand) { 32 // if a channel is assigned, assign its value type 33 if cmd.recordset != nil && !cmd.recordset.objChan.IsNil() { 34 // this channel must be of type chan *T 35 cmd.resObjType = cmd.recordset.objChan.Type().Elem().Elem() 36 cmd.resObjMappings = objectMappings.getMapping(cmd.recordset.objChan.Type().Elem().Elem()) 37 38 cmd.selectCases = []reflect.SelectCase{ 39 {Dir: reflect.SelectSend, Chan: cmd.recordset.objChan}, 40 {Dir: reflect.SelectRecv, Chan: reflect.ValueOf(cmd.recordset.cancelled)}, 41 } 42 } 43} 44 45func batchParseObject( 46 cmd *baseMultiCommand, 47 obj reflect.Value, 48 opCount int, 49 fieldCount int, 50 generation uint32, 51 expiration uint32, 52) error { 53 supportsFloat := cmd.node.cluster.supportsFloat.Get() 54 for i := 0; i < opCount; i++ { 55 if err := cmd.readBytes(8); err != nil { 56 err = newNodeError(cmd.node, err) 57 return err 58 } 59 60 opSize := int(Buffer.BytesToUint32(cmd.dataBuffer, 0)) 61 particleType := int(cmd.dataBuffer[5]) 62 nameSize := int(cmd.dataBuffer[7]) 63 64 if err := cmd.readBytes(nameSize); err != nil { 65 err = newNodeError(cmd.node, err) 66 return err 67 } 68 name := string(cmd.dataBuffer[:nameSize]) 69 70 particleBytesSize := opSize - (4 + nameSize) 71 if err := cmd.readBytes(particleBytesSize); err != nil { 72 err = newNodeError(cmd.node, err) 73 return err 74 } 75 value, err := bytesToParticle(particleType, cmd.dataBuffer, 0, particleBytesSize) 76 if err != nil { 77 err = newNodeError(cmd.node, err) 78 return err 79 } 80 81 iobj := indirect(obj) 82 if err := setObjectField(cmd.resObjMappings, iobj, name, value, supportsFloat); err != nil { 83 return err 84 } 85 86 if err := setObjectMetaFields(obj, expiration, generation); err != nil { 87 return err 88 } 89 } 90 91 return nil 92} 93