MCPcopy Create free account
hub / github.com/Restream/reindexer / SetObject

Method SetObject

query.go:1135–1176  ·  view source on GitHub ↗

SetObject adds update of object field request for update query

(field string, values any)

Source from the content-addressed store, hash-verified

1133
1134// SetObject adds update of object field request for update query
1135func (q *Query) SetObject(field string, values any) *Query {
1136 switch v := values.(type) {
1137 case nil:
1138 return q.putSetObjectBytes(field, emptyObjectJSON)
1139 case []byte:
1140 return q.putSetObjectBytes(field, v)
1141 case [][]byte:
1142 return q.putSetObjectBytesArray(field, v)
1143 }
1144
1145 size := 1
1146 isArray := false
1147 t := reflect.TypeOf(values)
1148 v := reflect.ValueOf(values)
1149 if t != reflect.TypeFor[[]byte]() && (t.Kind() == reflect.Array || t.Kind() == reflect.Slice) {
1150 size = v.Len()
1151 isArray = true
1152 }
1153 var jsonValue []byte
1154 var jsonValues [][]byte
1155 if isArray {
1156 jsonValues = make([][]byte, size)
1157 for i := range size {
1158 jsonValues[i] = getValueJSON(v.Index(i).Interface())
1159 }
1160 } else if size > 0 {
1161 jsonValue = getValueJSON(values)
1162 }
1163 q.putSetObjectHeader(field, size, isArray)
1164 for i := range size {
1165 // function/value flag
1166 q.ser.PutVarUInt(0)
1167 q.ser.PutVarCUInt(valueString)
1168 if isArray {
1169 q.ser.PutVBytes(jsonValues[i])
1170 } else {
1171 q.ser.PutVBytes(jsonValue)
1172 }
1173 }
1174
1175 return q
1176}
1177
1178func (q *Query) putSetObjectHeader(field string, size int, isArray bool) {
1179 q.ser.PutVarCUInt(queryUpdateObject)

Callers 3

SetMethod · 0.95

Calls 10

putSetObjectBytesMethod · 0.95
putSetObjectHeaderMethod · 0.95
getValueJSONFunction · 0.85
InterfaceMethod · 0.80
PutVarCUIntMethod · 0.80
PutVBytesMethod · 0.80
LenMethod · 0.45
IndexMethod · 0.45
PutVarUIntMethod · 0.45

Tested by 2