|
| 1 | +/* |
| 2 | + * Copyright 2024 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.r2dbc.postgresql.codec; |
| 18 | + |
| 19 | +import io.netty.buffer.ByteBuf; |
| 20 | +import io.r2dbc.postgresql.client.EncodedParameter; |
| 21 | +import io.r2dbc.postgresql.message.Format; |
| 22 | + |
| 23 | +import static io.r2dbc.postgresql.codec.PostgresqlObjectId.UNSPECIFIED; |
| 24 | +import static io.r2dbc.postgresql.message.Format.FORMAT_TEXT; |
| 25 | + |
| 26 | +final class ObjectCodec implements Codec<Object> { |
| 27 | + |
| 28 | + static final ObjectCodec INSTANCE = new ObjectCodec(); |
| 29 | + |
| 30 | + private ObjectCodec() { |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public EncodedParameter encodeNull() { |
| 35 | + return AbstractCodec.createNull(FORMAT_TEXT, UNSPECIFIED); |
| 36 | + } |
| 37 | + |
| 38 | + public EncodedParameter encodeNull(int dataType) { |
| 39 | + return new EncodedParameter(FORMAT_TEXT, dataType, EncodedParameter.NULL_VALUE); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public boolean canDecode(int dataType, Format format, Class<?> type) { |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public boolean canEncode(Object value) { |
| 49 | + return false; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public boolean canEncodeNull(Class<?> type) { |
| 54 | + return Object.class.equals(type); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public Object decode(ByteBuf buffer, int dataType, Format format, Class<?> type) { |
| 59 | + throw new UnsupportedOperationException(); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public EncodedParameter encode(Object value) { |
| 64 | + throw new UnsupportedOperationException(); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public EncodedParameter encode(Object value, int dataType) { |
| 69 | + throw new UnsupportedOperationException(); |
| 70 | + } |
| 71 | + |
| 72 | +} |
0 commit comments