(oid uint32, format int16, value any, depth int)
| 1224 | } |
| 1225 | |
| 1226 | func (m *Map) planEncode(oid uint32, format int16, value any, depth int) EncodePlan { |
| 1227 | if format == TextFormatCode { |
| 1228 | switch value.(type) { |
| 1229 | case string: |
| 1230 | return encodePlanStringToAnyTextFormat{} |
| 1231 | case TextValuer: |
| 1232 | return encodePlanTextValuerToAnyTextFormat{} |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | var dt *Type |
| 1237 | if dataType, ok := m.TypeForOID(oid); ok { |
| 1238 | dt = dataType |
| 1239 | } else { |
| 1240 | // If no type for the OID was found, then either it is unknowable (e.g. the simple protocol) or it is an |
| 1241 | // unregistered type. In either case try to find the type and OID that matches the value (e.g. a []byte would be |
| 1242 | // registered to PostgreSQL bytea). |
| 1243 | if dataType, ok := m.TypeForValue(value); ok { |
| 1244 | dt = dataType |
| 1245 | oid = dt.OID // Preserve assumed OID in case we are recursively called below. |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | if dt != nil { |
| 1250 | if plan := dt.Codec.PlanEncode(m, oid, format, value); plan != nil { |
| 1251 | return plan |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | for _, f := range m.TryWrapEncodePlanFuncs { |
| 1256 | if wrapperPlan, nextValue, ok := f(value); ok { |
| 1257 | if nextPlan := m.planEncodeDepth(oid, format, nextValue, depth+1); nextPlan != nil { |
| 1258 | wrapperPlan.SetNext(nextPlan) |
| 1259 | return wrapperPlan |
| 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | if _, ok := value.(driver.Valuer); ok { |
| 1265 | return &encodePlanDriverValuer{m: m, oid: oid, formatCode: format} |
| 1266 | } |
| 1267 | |
| 1268 | return nil |
| 1269 | } |
| 1270 | |
| 1271 | type encodePlanStringToAnyTextFormat struct{} |
| 1272 |
no test coverage detected