You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2019/01/14 03:18:11 UTC
[servicecomb-java-chassis] 05/16: [SCB-1071][WIP] avoid scalar
schemas always run as dynamic type
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit f60aa5be4368f896b042e951d80a4ee51f7ab370
Author: wujimin <wu...@huawei.com>
AuthorDate: Sat Jan 5 20:14:59 2019 +0800
[SCB-1071][WIP] avoid scalar schemas always run as dynamic type
---
.../foundation/protobuf/internal/ProtoConst.java | 2 +
.../foundation/protobuf/internal/ProtoUtils.java | 94 +++++++++++++++
.../EnumDeserializerSchema.java => EnumMeta.java} | 63 +++-------
.../scalar/AbstractScalarReadSchemas.java | 63 ++++++++++
.../deserializer/scalar/BoolReadSchemas.java | 78 +++++++++++++
.../deserializer/scalar/BytesReadSchemas.java | 57 +++++++++
.../deserializer/scalar/DoubleReadSchemas.java | 78 +++++++++++++
.../deserializer/scalar/EnumsReadSchemas.java | 113 ++++++++++++++++++
.../deserializer/scalar/Fixed32ReadSchemas.java | 72 ++++++++++++
.../deserializer/scalar/Fixed64ReadSchemas.java | 72 ++++++++++++
.../deserializer/scalar/FloatReadSchemas.java | 78 +++++++++++++
.../deserializer/scalar/Int32ReadSchemas.java | 72 ++++++++++++
.../deserializer/scalar/Int64ReadSchemas.java | 72 ++++++++++++
.../deserializer/scalar/SFixed32ReadSchemas.java | 72 ++++++++++++
.../deserializer/scalar/SFixed64ReadSchemas.java | 72 ++++++++++++
.../deserializer/scalar/SInt32ReadSchemas.java | 72 ++++++++++++
.../deserializer/scalar/SInt64ReadSchemas.java | 72 ++++++++++++
.../deserializer/scalar/StringReadSchemas.java | 57 +++++++++
.../deserializer/scalar/UInt32ReadSchemas.java | 72 ++++++++++++
.../deserializer/scalar/UInt64ReadSchemas.java | 72 ++++++++++++
.../internal/schema/scalar/BoolSchema.java | 70 -----------
.../internal/schema/scalar/BytesSchema.java | 55 ---------
.../internal/schema/scalar/DoubleSchema.java | 70 -----------
.../internal/schema/scalar/Fixed32Schema.java | 70 -----------
.../internal/schema/scalar/Fixed64Schema.java | 70 -----------
.../internal/schema/scalar/FloatSchema.java | 70 -----------
.../internal/schema/scalar/Int32Schema.java | 70 -----------
.../internal/schema/scalar/Int64Schema.java | 70 -----------
.../internal/schema/scalar/SFixed32Schema.java | 70 -----------
.../internal/schema/scalar/SFixed64Schema.java | 70 -----------
.../internal/schema/scalar/SInt32Schema.java | 70 -----------
.../internal/schema/scalar/SInt64Schema.java | 70 -----------
.../internal/schema/scalar/StringSchema.java | 63 ----------
.../internal/schema/scalar/UInt32Schema.java | 70 -----------
.../internal/schema/scalar/UInt64Schema.java | 70 -----------
.../schema/serializer/EnumSerializerSchema.java | 122 -------------------
.../schema/serializer/scalar/BoolWriteSchemas.java | 112 ++++++++++++++++++
.../serializer/scalar/BytesWriteSchemas.java | 71 ++++++++++++
.../serializer/scalar/DoubleWriteSchemas.java | 107 +++++++++++++++++
.../schema/serializer/scalar/EnumWriteSchemas.java | 129 +++++++++++++++++++++
.../serializer/scalar/Fixed32WriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/Fixed64WriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/FloatWriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/Int32WriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/Int64WriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/SFixed32WriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/SFixed64WriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/SInt32WriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/SInt64WriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/StringWriteSchemas.java | 79 +++++++++++++
.../serializer/scalar/UInt32WriteSchemas.java | 107 +++++++++++++++++
.../serializer/scalar/UInt64WriteSchemas.java | 107 +++++++++++++++++
52 files changed, 3034 insertions(+), 1194 deletions(-)
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoConst.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoConst.java
index 72f3764..426cb30 100644
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoConst.java
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoConst.java
@@ -42,6 +42,8 @@ public final class ProtoConst {
public static JavaType MAP_TYPE = TypeFactory.defaultInstance().constructType(LinkedHashMap.class);
+ public static JavaType OBJECT_TYPE = TypeFactory.defaultInstance().constructType(Object.class);
+
public static Proto ANY_PROTO;
public static Message ANY;
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoUtils.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoUtils.java
new file mode 100644
index 0000000..2afbe9d
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/ProtoUtils.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.compiler.model.DynamicMessage;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.compiler.model.FieldContainer;
+import io.protostuff.compiler.model.ScalarFieldType;
+import io.protostuff.compiler.model.Type;
+
+public final class ProtoUtils {
+ private ProtoUtils() {
+ }
+
+ public static boolean isAnyField(Field protoField) {
+ return protoField.getType().getCanonicalName().equals(ProtoConst.ANY.getCanonicalName());
+ }
+
+ public static boolean isWrapProperty(FieldContainer fieldContainer) {
+ return fieldContainer.getCommentLines().contains(ProtoConst.ANNOTATION_WRAP_PROPERTY);
+ }
+
+ /**
+ * all supported type, default to packed
+ * @param protoField
+ * @return
+ */
+ public static boolean isSupportPacked(Field protoField) {
+ if (protoField.getType().isEnum()) {
+ return true;
+ }
+
+ if (protoField.getType().isScalar()) {
+ ScalarFieldType scalarFieldType = (ScalarFieldType) protoField.getType();
+ return scalarFieldType != ScalarFieldType.STRING && scalarFieldType != ScalarFieldType.BYTES;
+ }
+
+ return false;
+ }
+
+ public static boolean isPacked(Field protoField) {
+ DynamicMessage.Value dynamicMessageValue = protoField.getOptions().get("packed");
+ if (dynamicMessageValue != null) {
+ return dynamicMessageValue.getBoolean();
+ }
+
+ return isSupportPacked(protoField);
+ }
+
+ public static void throwNotSupportWrite(Field protoField, Object value) throws IllegalStateException {
+ throwNotSupportWrite(protoField, value.getClass());
+ }
+
+ public static void throwNotSupportWrite(Field protoField, Class<?> cls) throws IllegalStateException {
+ throw new IllegalStateException(
+ String.format("not support serialize from %s to proto %s, field=%s:%s",
+ cls.getName(),
+ protoField.getTypeName(),
+ ((Type) protoField.getParent()).getCanonicalName(),
+ protoField.getName()));
+ }
+
+ public static void throwNotSupportMerge(Field protoField, JavaType javaType) throws IllegalStateException {
+ throw new IllegalStateException(
+ String.format("not support deserialize proto %s as %s, field=%s:%s",
+ protoField.getTypeName(),
+ javaType.toCanonical(),
+ ((Type) protoField.getParent()).getCanonicalName(),
+ protoField.getName()));
+ }
+
+ public static void throwNotSupportNullElement(Field protoField) throws IllegalStateException {
+ throw new IllegalStateException(
+ String.format("not support serialize null element, field=%s:%s",
+ ((Type) protoField.getParent()).getCanonicalName(),
+ protoField.getName()));
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/EnumDeserializerSchema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/EnumMeta.java
similarity index 52%
rename from foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/EnumDeserializerSchema.java
rename to foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/EnumMeta.java
index 943372d..d25cc88 100644
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/EnumDeserializerSchema.java
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/EnumMeta.java
@@ -14,30 +14,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer;
+package org.apache.servicecomb.foundation.protobuf.internal.schema;
-import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
import com.fasterxml.jackson.databind.JavaType;
-import io.protostuff.Input;
-import io.protostuff.Output;
+import io.protostuff.compiler.model.EnumConstant;
import io.protostuff.compiler.model.Field;
-import io.protostuff.compiler.model.Type;
-public class EnumDeserializerSchema extends FieldSchema {
- private final JavaType javaType;
+public class EnumMeta {
+ private Map<String, Integer> enumNameToValueMap = new HashMap<>();
+ // key is idl defined enum value
+ // value is Enum<?> or null
private Map<Integer, Enum<?>> enumValues = new HashMap<>();
- public EnumDeserializerSchema(Field protoField, JavaType javaType) {
- super(protoField);
- this.javaType = javaType;
+ public EnumMeta(Field protoField, JavaType javaType) {
+ io.protostuff.compiler.model.Enum enumType = (io.protostuff.compiler.model.Enum) protoField.getType();
+ for (EnumConstant enumConstant : enumType.getConstants()) {
+ enumNameToValueMap.put(enumConstant.getName(), enumConstant.getValue());
+ enumValues.put(enumConstant.getValue(), null);
+ }
if (!javaType.isEnumType()) {
return;
@@ -49,7 +49,7 @@ public class EnumDeserializerSchema extends FieldSchema {
Object[] values = (Object[]) method.invoke(null);
for (Object value : values) {
Enum<?> enumValue = (Enum<?>) value;
- enumValues.put(enumValue.ordinal(), enumValue);
+ enumValues.put(enumNameToValueMap.get(enumValue.name()), enumValue);
}
} catch (Throwable e) {
throw new IllegalStateException(
@@ -57,40 +57,15 @@ public class EnumDeserializerSchema extends FieldSchema {
}
}
- @Override
- public void writeTo(Output output, Object message) throws IOException {
- throw new UnsupportedOperationException();
+ public boolean containsValue(Integer value) {
+ return enumValues.containsKey(value);
}
- @Override
- public Object readFrom(Input input) throws IOException {
- int ordinal = input.readInt32();
- if (javaType.isEnumType()) {
- return enumValues.get(ordinal);
- }
-
- return ordinal;
+ public Enum<?> getEnumByValue(int enumValue) {
+ return enumValues.get(enumValue);
}
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- int ordinal = input.readInt32();
-
- if (javaType.isEnumType()) {
- Enum<?> enumValue = enumValues.get(ordinal);
- if (enumValue != null) {
- setter.set(message, enumValue);
- return;
- }
-
- throw new IllegalStateException(
- String.format("invalid enum ordinal value %d for %s, proto field=%s:%s",
- ordinal,
- javaType.getRawClass().getName(),
- ((Type) protoField.getParent()).getCanonicalName(),
- protoField.getName()));
- }
-
- setter.set(message, ordinal);
+ public Integer getValueByName(String name) {
+ return enumNameToValueMap.get(name);
}
}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/AbstractScalarReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/AbstractScalarReadSchemas.java
new file mode 100644
index 0000000..4ba1c6f
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/AbstractScalarReadSchemas.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import org.apache.servicecomb.foundation.common.utils.bean.IntSetter;
+import org.apache.servicecomb.foundation.common.utils.bean.LongSetter;
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class AbstractScalarReadSchemas {
+ static abstract class AbstractIntSchema<T> extends FieldSchema<T> {
+ protected final Setter<T, Integer> setter;
+
+ public AbstractIntSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+ }
+
+ static abstract class AbstractIntPrimitiveSchema<T> extends FieldSchema<T> {
+ protected final IntSetter<T> setter;
+
+ public AbstractIntPrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+ }
+
+ static abstract class AbstractLongSchema<T> extends FieldSchema<T> {
+ protected final Setter<T, Long> setter;
+
+ public AbstractLongSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+ }
+
+ static abstract class AbstractLongPrimitiveSchema<T> extends FieldSchema<T> {
+ protected final LongSetter<T> setter;
+
+ public AbstractLongPrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/BoolReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/BoolReadSchemas.java
new file mode 100644
index 0000000..a6b1e75
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/BoolReadSchemas.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.BoolSetter;
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class BoolReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (boolean.class.equals(javaType.getRawClass())) {
+ return new BooleanPrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Boolean.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new BooleanSchema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class BooleanSchema<T> extends FieldSchema<T> {
+ private final Setter<T, Boolean> setter;
+
+ public BooleanSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ boolean value = input.readBool();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class BooleanPrimitiveSchema<T> extends FieldSchema<T> {
+ private final BoolSetter<T> setter;
+
+ public BooleanPrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ boolean value = input.readBool();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/BytesReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/BytesReadSchemas.java
new file mode 100644
index 0000000..9c4ec6c
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/BytesReadSchemas.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class BytesReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (byte[].class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new BytesSchema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class BytesSchema<T> extends FieldSchema<T> {
+ private final Setter<T, byte[]> setter;
+
+ public BytesSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ byte[] value = input.readByteArray();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/DoubleReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/DoubleReadSchemas.java
new file mode 100644
index 0000000..dbac060
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/DoubleReadSchemas.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.DoubleSetter;
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class DoubleReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (double.class.equals(javaType.getRawClass())) {
+ return new DoublePrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Double.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new DoubleSchema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class DoubleSchema<T> extends FieldSchema<T> {
+ private final Setter<T, Double> setter;
+
+ public DoubleSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ double value = input.readDouble();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class DoublePrimitiveSchema<T> extends FieldSchema<T> {
+ private final DoubleSetter<T> setter;
+
+ public DoublePrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ double value = input.readDouble();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/EnumsReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/EnumsReadSchemas.java
new file mode 100644
index 0000000..1ca9fed
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/EnumsReadSchemas.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.IntSetter;
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.EnumMeta;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.compiler.model.Type;
+import io.protostuff.runtime.FieldSchema;
+
+public class EnumsReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (javaType.isEnumType()) {
+ return new EnumSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new IntEnumSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (int.class.equals(javaType.getRawClass())) {
+ return new IntPrimitiveEnumSchema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class EnumSchema<T> extends FieldSchema<T> {
+ private final Setter<T, Enum<?>> setter;
+
+ private final EnumMeta enumMeta;
+
+ public EnumSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ enumMeta = new EnumMeta(protoField, javaType);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readInt32();
+ Enum<?> enumValue = enumMeta.getEnumByValue(value);
+ if (enumValue != null) {
+ setter.set(message, enumValue);
+ return input.readFieldNumber();
+ }
+
+ throw new IllegalStateException(
+ String.format("invalid enum value %d for %s, proto field=%s:%s",
+ value,
+ javaType.getRawClass().getName(),
+ ((Type) protoField.getParent()).getCanonicalName(),
+ protoField.getName()));
+ }
+ }
+
+ private static class IntEnumSchema<T> extends FieldSchema<T> {
+ private final Setter<T, Integer> setter;
+
+ public IntEnumSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readInt32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class IntPrimitiveEnumSchema<T> extends FieldSchema<T> {
+ private final IntSetter<T> setter;
+
+ public IntPrimitiveEnumSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readInt32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Fixed32ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Fixed32ReadSchemas.java
new file mode 100644
index 0000000..dc88866
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Fixed32ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class Fixed32ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (int.class.equals(javaType.getRawClass())) {
+ return new Fixed32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new Fixed32Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class Fixed32Schema<T> extends AbstractIntSchema<T> {
+ public Fixed32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readFixed32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class Fixed32PrimitiveSchema<T> extends AbstractIntPrimitiveSchema<T> {
+ public Fixed32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readFixed32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Fixed64ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Fixed64ReadSchemas.java
new file mode 100644
index 0000000..bb52915
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Fixed64ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class Fixed64ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (long.class.equals(javaType.getRawClass())) {
+ return new Fixed64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new Fixed64Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class Fixed64Schema<T> extends AbstractLongSchema<T> {
+ public Fixed64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readFixed64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class Fixed64PrimitiveSchema<T> extends AbstractLongPrimitiveSchema<T> {
+ public Fixed64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readFixed64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/FloatReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/FloatReadSchemas.java
new file mode 100644
index 0000000..46879c1
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/FloatReadSchemas.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.FloatSetter;
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class FloatReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (float.class.equals(javaType.getRawClass())) {
+ return new FloatPrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Float.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new FloatSchema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class FloatSchema<T> extends FieldSchema<T> {
+ private final Setter<T, Float> setter;
+
+ public FloatSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ float value = input.readFloat();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class FloatPrimitiveSchema<T> extends FieldSchema<T> {
+ private final FloatSetter<T> setter;
+
+ public FloatPrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ float value = input.readFloat();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Int32ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Int32ReadSchemas.java
new file mode 100644
index 0000000..87177f6
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Int32ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class Int32ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (int.class.equals(javaType.getRawClass())) {
+ return new Int32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new Int32Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class Int32Schema<T> extends AbstractIntSchema<T> {
+ public Int32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readInt32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class Int32PrimitiveSchema<T> extends AbstractIntPrimitiveSchema<T> {
+ public Int32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readInt32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Int64ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Int64ReadSchemas.java
new file mode 100644
index 0000000..a998dcd
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/Int64ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class Int64ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (long.class.equals(javaType.getRawClass())) {
+ return new Int64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new Int64Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class Int64Schema<T> extends AbstractLongSchema<T> {
+ public Int64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readInt64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class Int64PrimitiveSchema<T> extends AbstractLongPrimitiveSchema<T> {
+ public Int64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readInt64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SFixed32ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SFixed32ReadSchemas.java
new file mode 100644
index 0000000..9831032
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SFixed32ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class SFixed32ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (int.class.equals(javaType.getRawClass())) {
+ return new SFixed32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new SFixed32Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class SFixed32Schema<T> extends AbstractIntSchema<T> {
+ public SFixed32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readSFixed32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class SFixed32PrimitiveSchema<T> extends AbstractIntPrimitiveSchema<T> {
+ public SFixed32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readSFixed32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SFixed64ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SFixed64ReadSchemas.java
new file mode 100644
index 0000000..e83a84f
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SFixed64ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class SFixed64ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (long.class.equals(javaType.getRawClass())) {
+ return new SFixed64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new SFixed64Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class SFixed64Schema<T> extends AbstractLongSchema<T> {
+ public SFixed64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readSFixed64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class SFixed64PrimitiveSchema<T> extends AbstractLongPrimitiveSchema<T> {
+ public SFixed64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readSFixed64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SInt32ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SInt32ReadSchemas.java
new file mode 100644
index 0000000..ae33b4f
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SInt32ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class SInt32ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (int.class.equals(javaType.getRawClass())) {
+ return new SInt32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new SInt32Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class SInt32Schema<T> extends AbstractIntSchema<T> {
+ public SInt32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readSInt32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class SInt32PrimitiveSchema<T> extends AbstractIntPrimitiveSchema<T> {
+ public SInt32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readSInt32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SInt64ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SInt64ReadSchemas.java
new file mode 100644
index 0000000..850d7fe
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/SInt64ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class SInt64ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (long.class.equals(javaType.getRawClass())) {
+ return new SInt64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new SInt64Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class SInt64Schema<T> extends AbstractLongSchema<T> {
+ public SInt64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readSInt64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class SInt64PrimitiveSchema<T> extends AbstractLongPrimitiveSchema<T> {
+ public SInt64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readSInt64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/StringReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/StringReadSchemas.java
new file mode 100644
index 0000000..2c9d0d4
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/StringReadSchemas.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Setter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class StringReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (String.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new StringSchema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class StringSchema<T> extends FieldSchema<T> {
+ private final Setter<T, String> setter;
+
+ public StringSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.setter = propertyDescriptor.getSetter();
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ String value = input.readString();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/UInt32ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/UInt32ReadSchemas.java
new file mode 100644
index 0000000..978986b
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/UInt32ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractIntSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class UInt32ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (int.class.equals(javaType.getRawClass())) {
+ return new UInt32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new UInt32Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class UInt32Schema<T> extends AbstractIntSchema<T> {
+ public UInt32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readUInt32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class UInt32PrimitiveSchema<T> extends AbstractIntPrimitiveSchema<T> {
+ public UInt32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ int value = input.readUInt32();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/UInt64ReadSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/UInt64ReadSchemas.java
new file mode 100644
index 0000000..0e11f81
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/deserializer/scalar/UInt64ReadSchemas.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongPrimitiveSchema;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.deserializer.scalar.AbstractScalarReadSchemas.AbstractLongSchema;
+
+import com.fasterxml.jackson.databind.JavaType;
+
+import io.protostuff.InputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class UInt64ReadSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ JavaType javaType = propertyDescriptor.getJavaType();
+ if (long.class.equals(javaType.getRawClass())) {
+ return new UInt64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(javaType.getRawClass()) || javaType.isJavaLangObject()) {
+ return new UInt64Schema<>(protoField, propertyDescriptor);
+ }
+
+ ProtoUtils.throwNotSupportMerge(protoField, propertyDescriptor.getJavaType());
+ return null;
+ }
+
+ private static class UInt64Schema<T> extends AbstractLongSchema<T> {
+ public UInt64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readUInt64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+
+ private static class UInt64PrimitiveSchema<T> extends AbstractLongPrimitiveSchema<T> {
+ public UInt64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+ }
+
+ @Override
+ public int mergeFrom(InputEx input, T message) throws IOException {
+ long value = input.readUInt64();
+ setter.set(message, value);
+ return input.readFieldNumber();
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/BoolSchema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/BoolSchema.java
deleted file mode 100644
index 3d5fc60..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/BoolSchema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class BoolSchema extends FieldSchema {
- public BoolSchema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readBool();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readBool());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Boolean) {
- output.writeBool(number, (Boolean) value, repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- boolean v = Boolean.parseBoolean(((String[]) value)[0]);
- output.writeBool(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- boolean v = Boolean.parseBoolean((String) value);
- output.writeBool(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/BytesSchema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/BytesSchema.java
deleted file mode 100644
index e354c7e..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/BytesSchema.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class BytesSchema extends FieldSchema {
- public BytesSchema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readByteArray();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readByteArray());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof byte[]) {
- output.writeByteArray(number, (byte[]) value, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/DoubleSchema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/DoubleSchema.java
deleted file mode 100644
index 45dbce3..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/DoubleSchema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class DoubleSchema extends FieldSchema {
- public DoubleSchema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readDouble();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readDouble());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeDouble(number, ((Number) value).doubleValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- double v = Double.parseDouble(((String[]) value)[0]);
- output.writeDouble(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- double v = Double.parseDouble((String) value);
- output.writeDouble(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Fixed32Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Fixed32Schema.java
deleted file mode 100644
index 168f39d..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Fixed32Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class Fixed32Schema extends FieldSchema {
- public Fixed32Schema(Field field) {
- super(field);
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeFixed32(number, ((Number) value).intValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- int v = Integer.parseInt(((String[]) value)[0], 10);
- output.writeFixed32(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- int v = Integer.parseInt((String) value, 10);
- output.writeFixed32(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readFixed32();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readFixed32());
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Fixed64Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Fixed64Schema.java
deleted file mode 100644
index 36138d0..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Fixed64Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class Fixed64Schema extends FieldSchema {
- public Fixed64Schema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readFixed64();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readFixed64());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeFixed64(number, ((Number) value).longValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- long v = Long.parseLong(((String[]) value)[0], 10);
- output.writeFixed64(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- long v = Long.parseLong((String) value, 10);
- output.writeFixed64(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/FloatSchema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/FloatSchema.java
deleted file mode 100644
index d587d40..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/FloatSchema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class FloatSchema extends FieldSchema {
- public FloatSchema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readFloat();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readFloat());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeFloat(number, ((Number) value).floatValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- float v = Float.parseFloat(((String[]) value)[0]);
- output.writeFloat(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- float v = Float.parseFloat((String) value);
- output.writeFloat(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Int32Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Int32Schema.java
deleted file mode 100644
index 526e850..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Int32Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class Int32Schema extends FieldSchema {
- public Int32Schema(Field protoField) {
- super(protoField);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readInt32();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readInt32());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeInt32(number, ((Number) value).intValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- int v = Integer.parseInt(((String[]) value)[0], 10);
- output.writeInt32(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- int v = Integer.parseInt((String) value, 10);
- output.writeInt32(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Int64Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Int64Schema.java
deleted file mode 100644
index 91b6d61..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/Int64Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class Int64Schema extends FieldSchema {
- public Int64Schema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readInt64();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readInt64());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeInt64(number, ((Number) value).longValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- long v = Long.parseLong(((String[]) value)[0], 10);
- output.writeInt64(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- long v = Long.parseLong((String) value, 10);
- output.writeInt64(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SFixed32Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SFixed32Schema.java
deleted file mode 100644
index c51758d..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SFixed32Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class SFixed32Schema extends FieldSchema {
- public SFixed32Schema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readSFixed32();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readSFixed32());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeSFixed32(number, ((Number) value).intValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- int v = Integer.parseInt(((String[]) value)[0], 10);
- output.writeSFixed32(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- int v = Integer.parseInt((String) value, 10);
- output.writeSFixed32(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SFixed64Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SFixed64Schema.java
deleted file mode 100644
index 97502ad..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SFixed64Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class SFixed64Schema extends FieldSchema {
- public SFixed64Schema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readSFixed64();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readSFixed64());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeSFixed64(number, ((Number) value).longValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- long v = Long.parseLong(((String[]) value)[0], 10);
- output.writeSFixed64(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- long v = Long.parseLong((String) value, 10);
- output.writeSFixed64(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SInt32Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SInt32Schema.java
deleted file mode 100644
index 602ba08..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SInt32Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class SInt32Schema extends FieldSchema {
- public SInt32Schema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readSInt32();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readSInt32());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeSInt32(number, ((Number) value).intValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- int v = Integer.parseInt(((String[]) value)[0], 10);
- output.writeSInt32(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- int v = Integer.parseInt((String) value, 10);
- output.writeSInt32(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SInt64Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SInt64Schema.java
deleted file mode 100644
index 2401b80..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/SInt64Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class SInt64Schema extends FieldSchema {
- public SInt64Schema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readSInt64();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readSInt64());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeSInt64(number, ((Number) value).longValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- long v = Long.parseLong(((String[]) value)[0], 10);
- output.writeSInt64(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- long v = Long.parseLong((String) value, 10);
- output.writeSInt64(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/StringSchema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/StringSchema.java
deleted file mode 100644
index 1b15520..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/StringSchema.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class StringSchema extends FieldSchema {
- public StringSchema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readString();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readString());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof String) {
- output.writeString(number, (String) value, repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- output.writeString(number, ((String[]) value)[0], repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/UInt32Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/UInt32Schema.java
deleted file mode 100644
index 215fccb..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/UInt32Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class UInt32Schema extends FieldSchema {
- public UInt32Schema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readUInt32();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readUInt32());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeUInt32(number, ((Number) value).intValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- int v = Integer.parseInt(((String[]) value)[0], 10);
- output.writeUInt32(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- int v = Integer.parseInt((String) value, 10);
- output.writeUInt32(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/UInt64Schema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/UInt64Schema.java
deleted file mode 100644
index 4c57d29..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/scalar/UInt64Schema.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.scalar;
-
-import java.io.IOException;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.Field;
-
-public class UInt64Schema extends FieldSchema {
- public UInt64Schema(Field field) {
- super(field);
- }
-
- @Override
- public Object readFrom(Input input) throws IOException {
- return input.readUInt64();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) throws IOException {
- setter.set(message, input.readUInt64());
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Number) {
- output.writeUInt64(number, ((Number) value).longValue(), repeated);
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
- long v = Long.parseLong(((String[]) value)[0], 10);
- output.writeUInt64(number, v, repeated);
- return;
- }
-
- if (value instanceof String) {
- long v = Long.parseLong((String) value, 10);
- output.writeUInt64(number, v, repeated);
- return;
- }
-
- throwNotSupportValue(value);
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/EnumSerializerSchema.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/EnumSerializerSchema.java
deleted file mode 100644
index 31f3862..0000000
--- a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/EnumSerializerSchema.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.servicecomb.foundation.protobuf.internal.schema.FieldSchema;
-
-import io.protostuff.Input;
-import io.protostuff.Output;
-import io.protostuff.compiler.model.EnumConstant;
-import io.protostuff.compiler.model.Field;
-import io.protostuff.compiler.model.Type;
-
-public class EnumSerializerSchema extends FieldSchema {
- private Map<String, Integer> enumNameToValueMap = new HashMap<>();
-
- private Set<Integer> enumValueSet = new HashSet<>();
-
- public EnumSerializerSchema(Field field) {
- super(field);
- io.protostuff.compiler.model.Enum enumType = (io.protostuff.compiler.model.Enum) field.getType();
- for (EnumConstant enumConstant : enumType.getConstants()) {
- enumNameToValueMap.put(enumConstant.getName(), enumConstant.getValue());
- enumValueSet.add(enumConstant.getValue());
- }
- }
-
- @Override
- public void writeTo(Output output, Object value) throws IOException {
- if (value == null) {
- return;
- }
-
- if (value instanceof Enum) {
- // already be a Enum, need to check if it is a valid Enum?
- // wrong case:
- // expect a Color enum, but be a Sharp enum?, who will do this?
- // for safe, check it......
- serializeFromString(output, ((Enum<?>) value).name());
- return;
- }
-
- if (value instanceof Number) {
- // need to check if it is a valid number
- // because maybe come from http request
- serializeFromNumber(output, ((Number) value).intValue());
- return;
- }
-
- if (value instanceof String[]) {
- if (((String[]) value).length == 0) {
- return;
- }
-
- serializeFromString(output, ((String[]) value)[0]);
- return;
- }
-
- if (value instanceof String) {
- serializeFromString(output, (String) value);
- return;
- }
-
- throwNotSupportValue(value);
- }
-
-
- protected void serializeFromNumber(Output output, int enumValue) throws IOException {
- if (!enumValueSet.contains(enumValue)) {
- throw new IllegalStateException(
- String.format("invalid enum value %d for proto %s, field=%s:%s",
- enumValue,
- protoField.getTypeName(),
- ((Type) protoField.getParent()).getCanonicalName(),
- protoField.getName()));
- }
-
- output.writeInt32(number, enumValue, repeated);
- }
-
- protected void serializeFromString(Output output, String enumName) throws IOException {
- Integer v = enumNameToValueMap.get(enumName);
- if (v == null) {
- throw new IllegalStateException(
- String.format("invalid enum name %s for proto %s, field=%s:%s",
- enumName,
- protoField.getTypeName(),
- ((Type) protoField.getParent()).getCanonicalName(),
- protoField.getName()));
- }
- output.writeInt32(number, v, repeated);
- }
-
- @Override
- public Object readFrom(Input input) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void mergeFrom(Input input, Object message) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/BoolWriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/BoolWriteSchemas.java
new file mode 100644
index 0000000..a687a82
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/BoolWriteSchemas.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.BoolGetter;
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class BoolWriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (boolean.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new BooleanPrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Boolean.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new BooleanSchema<>(protoField, propertyDescriptor);
+ }
+
+ return new BooleanDynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class BooleanDynamicSchema<T> extends FieldSchema<T> {
+ public BooleanDynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Boolean) {
+ output.writeScalarBool(tag, tagSize, (boolean) value);
+ return;
+ }
+
+ if (value instanceof Number) {
+ output.writeScalarBool(tag, tagSize, ((Number) value).longValue() == 1);
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ boolean parsedValue = Boolean.parseBoolean(((String[]) value)[0]);
+ output.writeScalarBool(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ boolean parsedValue = Boolean.parseBoolean((String) value);
+ output.writeScalarBool(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class BooleanSchema<T> extends BooleanDynamicSchema<T> {
+ protected final Getter<T, Boolean> getter;
+
+ public BooleanSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Boolean value = getter.get(message);
+ if (value != null) {
+ output.writeScalarBool(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class BooleanPrimitiveSchema<T> extends BooleanDynamicSchema<T> {
+ private final BoolGetter<T> primitiveGetter;
+
+ public BooleanPrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ boolean value = primitiveGetter.get(message);
+ output.writeScalarBool(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/BytesWriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/BytesWriteSchemas.java
new file mode 100644
index 0000000..03352c5
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/BytesWriteSchemas.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class BytesWriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (byte[].class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new BytesSchema<>(protoField, propertyDescriptor);
+ }
+
+ return new BytesDynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class BytesDynamicSchema<T> extends FieldSchema<T> {
+ public BytesDynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof byte[]) {
+ output.writeByteArray(tag, tagSize, (byte[]) value);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class BytesSchema<T> extends BytesDynamicSchema<T> {
+ protected final Getter<T, byte[]> getter;
+
+ public BytesSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ byte[] value = getter.get(message);
+ if (value != null) {
+ output.writeByteArray(tag, tagSize, value);
+ }
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/DoubleWriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/DoubleWriteSchemas.java
new file mode 100644
index 0000000..5839ba0
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/DoubleWriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.DoubleGetter;
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class DoubleWriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (double.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new DoublePrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Double.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new DoubleSchema<>(protoField, propertyDescriptor);
+ }
+
+ return new DoubleDynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class DoubleDynamicSchema<T> extends FieldSchema<T> {
+ public DoubleDynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarDouble(tag, tagSize, ((Number) value).doubleValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ double parsedValue = Double.parseDouble(((String[]) value)[0]);
+ output.writeScalarDouble(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ double parsedValue = Double.parseDouble((String) value);
+ output.writeScalarDouble(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class DoubleSchema<T> extends DoubleDynamicSchema<T> {
+ protected final Getter<T, Double> getter;
+
+ public DoubleSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Double value = getter.get(message);
+ if (value != null) {
+ output.writeScalarDouble(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class DoublePrimitiveSchema<T> extends DoubleDynamicSchema<T> {
+ private final DoubleGetter<T> primitiveGetter;
+
+ public DoublePrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ double value = primitiveGetter.get(message);
+ output.writeScalarDouble(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/EnumWriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/EnumWriteSchemas.java
new file mode 100644
index 0000000..09f26f4
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/EnumWriteSchemas.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+import org.apache.servicecomb.foundation.protobuf.internal.schema.EnumMeta;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.compiler.model.Type;
+import io.protostuff.runtime.FieldSchema;
+
+public class EnumWriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (propertyDescriptor.getJavaType().isEnumType()) {
+ return new EnumSchema<>(protoField, propertyDescriptor);
+ }
+
+ return new EnumDynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class EnumDynamicSchema<T> extends FieldSchema<T> {
+ private EnumMeta enumMeta;
+
+ public EnumDynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ this.enumMeta = new EnumMeta(protoField, javaType);
+ }
+
+ protected final void numberWrite(OutputEx output, Number value) throws IOException {
+ int enumValue = value.intValue();
+ if (!enumMeta.containsValue(enumValue)) {
+ throw new IllegalStateException(
+ String.format("invalid enum value %d for proto %s, field=%s:%s",
+ enumValue,
+ protoField.getTypeName(),
+ ((Type) protoField.getParent()).getCanonicalName(),
+ protoField.getName()));
+ }
+
+ output.writeScalarInt32(tag, tagSize, enumValue);
+ }
+
+ protected final void stringWrite(OutputEx output, String enumName) throws IOException {
+ Integer enumValue = enumMeta.getValueByName(enumName);
+ if (enumValue == null) {
+ throw new IllegalStateException(
+ String.format("invalid enum name %s for proto %s, field=%s:%s",
+ enumName,
+ protoField.getTypeName(),
+ ((Type) protoField.getParent()).getCanonicalName(),
+ protoField.getName()));
+ }
+
+ output.writeScalarInt32(tag, tagSize, enumValue);
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Enum) {
+ stringWrite(output, ((Enum<?>) value).name());
+ return;
+ }
+
+ if (value instanceof Number) {
+ // need to check if it is a valid number
+ // because maybe come from http request
+ numberWrite(output, ((Number) value).intValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+
+ stringWrite(output, ((String[]) value)[0]);
+ return;
+ }
+
+ if (value instanceof String) {
+ stringWrite(output, (String) value);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class EnumSchema<T> extends EnumDynamicSchema<T> {
+ protected final Getter<T, Enum<?>> getter;
+
+ public EnumSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ // already be a Enum, need to check if it is a valid Enum?
+ // wrong case:
+ // expect a Color enum, but be a Sharp enum?, who will do this?
+ // for safe, check it......
+ Enum<?> value = getter.get(message);
+ if (value != null) {
+ stringWrite(output, value.name());
+ }
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Fixed32WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Fixed32WriteSchemas.java
new file mode 100644
index 0000000..f4c6f6e
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Fixed32WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.IntGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class Fixed32WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (int.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new Fixed32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new Fixed32Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new Fixed32DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class Fixed32DynamicSchema<T> extends FieldSchema<T> {
+ public Fixed32DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarFixed32(tag, tagSize, ((Number) value).intValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ int parsedValue = Integer.parseInt(((String[]) value)[0], 10);
+ output.writeScalarFixed32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ int parsedValue = Integer.parseInt((String) value, 10);
+ output.writeScalarFixed32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class Fixed32Schema<T> extends Fixed32DynamicSchema<T> {
+ protected final Getter<T, Integer> getter;
+
+ public Fixed32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Integer value = getter.get(message);
+ if (value != null) {
+ output.writeScalarFixed32(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class Fixed32PrimitiveSchema<T> extends Fixed32DynamicSchema<T> {
+ private final IntGetter<T> primitiveGetter;
+
+ public Fixed32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ int value = primitiveGetter.get(message);
+ output.writeScalarFixed32(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Fixed64WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Fixed64WriteSchemas.java
new file mode 100644
index 0000000..b3addeb
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Fixed64WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.LongGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class Fixed64WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new Fixed64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new Fixed64Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new Fixed64DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class Fixed64DynamicSchema<T> extends FieldSchema<T> {
+ public Fixed64DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarFixed64(tag, tagSize, ((Number) value).longValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ long parsedValue = Long.parseLong(((String[]) value)[0], 10);
+ output.writeScalarFixed64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ long parsedValue = Long.parseLong((String) value, 10);
+ output.writeScalarFixed64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class Fixed64Schema<T> extends Fixed64DynamicSchema<T> {
+ protected final Getter<T, Long> getter;
+
+ public Fixed64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Long value = getter.get(message);
+ if (value != null) {
+ output.writeScalarFixed64(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class Fixed64PrimitiveSchema<T> extends Fixed64DynamicSchema<T> {
+ private final LongGetter<T> primitiveGetter;
+
+ public Fixed64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ long value = primitiveGetter.get(message);
+ output.writeScalarFixed64(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/FloatWriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/FloatWriteSchemas.java
new file mode 100644
index 0000000..7687c4d
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/FloatWriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.FloatGetter;
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class FloatWriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (float.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new FloatPrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Float.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new FloatSchema<>(protoField, propertyDescriptor);
+ }
+
+ return new FloatDynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class FloatDynamicSchema<T> extends FieldSchema<T> {
+ public FloatDynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarFloat(tag, tagSize, ((Number) value).floatValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ float parsedValue = Float.parseFloat(((String[]) value)[0]);
+ output.writeScalarFloat(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ float parsedValue = Float.parseFloat((String) value);
+ output.writeScalarFloat(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class FloatSchema<T> extends FloatDynamicSchema<T> {
+ protected final Getter<T, Float> getter;
+
+ public FloatSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Float value = getter.get(message);
+ if (value != null) {
+ output.writeScalarFloat(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class FloatPrimitiveSchema<T> extends FloatDynamicSchema<T> {
+ private final FloatGetter<T> primitiveGetter;
+
+ public FloatPrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ float value = primitiveGetter.get(message);
+ output.writeScalarFloat(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Int32WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Int32WriteSchemas.java
new file mode 100644
index 0000000..42b2f55
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Int32WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.IntGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public final class Int32WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (int.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new Int32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new Int32Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new Int32DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class Int32DynamicSchema<T> extends FieldSchema<T> {
+ public Int32DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarInt32(tag, tagSize, ((Number) value).intValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ int parsedValue = Integer.parseInt(((String[]) value)[0], 10);
+ output.writeScalarInt32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ int parsedValue = Integer.parseInt((String) value, 10);
+ output.writeScalarInt32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class Int32Schema<T> extends Int32DynamicSchema<T> {
+ protected final Getter<T, Integer> getter;
+
+ public Int32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Integer value = getter.get(message);
+ if (value != null) {
+ output.writeScalarInt32(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static final class Int32PrimitiveSchema<T> extends Int32DynamicSchema<T> {
+ private final IntGetter<T> primitiveGetter;
+
+ public Int32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ int value = primitiveGetter.get(message);
+ output.writeScalarInt32(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Int64WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Int64WriteSchemas.java
new file mode 100644
index 0000000..c442d55
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/Int64WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.LongGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class Int64WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new Int64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new Int64Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new Int64DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class Int64DynamicSchema<T> extends FieldSchema<T> {
+ public Int64DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarInt64(tag, tagSize, ((Number) value).longValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ long parsedValue = Long.parseLong(((String[]) value)[0], 10);
+ output.writeScalarInt64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ long parsedValue = Long.parseLong((String) value, 10);
+ output.writeScalarInt64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class Int64Schema<T> extends Int64DynamicSchema<T> {
+ protected final Getter<T, Long> getter;
+
+ public Int64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Long value = getter.get(message);
+ if (value != null) {
+ output.writeScalarInt64(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static final class Int64PrimitiveSchema<T> extends Int64DynamicSchema<T> {
+ private final LongGetter<T> primitiveGetter;
+
+ public Int64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ long value = primitiveGetter.get(message);
+ output.writeScalarInt64(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SFixed32WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SFixed32WriteSchemas.java
new file mode 100644
index 0000000..b803b07
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SFixed32WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.IntGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class SFixed32WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (int.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new SFixed32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new SFixed32Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new SFixed32DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class SFixed32DynamicSchema<T> extends FieldSchema<T> {
+ public SFixed32DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarSFixed32(tag, tagSize, ((Number) value).intValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ int parsedValue = Integer.parseInt(((String[]) value)[0], 10);
+ output.writeScalarSFixed32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ int parsedValue = Integer.parseInt((String) value, 10);
+ output.writeScalarSFixed32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class SFixed32Schema<T> extends SFixed32DynamicSchema<T> {
+ protected final Getter<T, Integer> getter;
+
+ public SFixed32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Integer value = getter.get(message);
+ if (value != null) {
+ output.writeScalarSFixed32(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class SFixed32PrimitiveSchema<T> extends SFixed32DynamicSchema<T> {
+ private final IntGetter<T> primitiveGetter;
+
+ public SFixed32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ int value = primitiveGetter.get(message);
+ output.writeScalarSFixed32(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SFixed64WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SFixed64WriteSchemas.java
new file mode 100644
index 0000000..7803f55
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SFixed64WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.LongGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class SFixed64WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new SFixed64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new SFixed64Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new SFixed64DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class SFixed64DynamicSchema<T> extends FieldSchema<T> {
+ public SFixed64DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarSFixed64(tag, tagSize, ((Number) value).longValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ long parsedValue = Long.parseLong(((String[]) value)[0], 10);
+ output.writeScalarSFixed64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ long parsedValue = Long.parseLong((String) value, 10);
+ output.writeScalarSFixed64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class SFixed64Schema<T> extends SFixed64DynamicSchema<T> {
+ protected final Getter<T, Long> getter;
+
+ public SFixed64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Long value = getter.get(message);
+ if (value != null) {
+ output.writeScalarSFixed64(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class SFixed64PrimitiveSchema<T> extends SFixed64DynamicSchema<T> {
+ private final LongGetter<T> primitiveGetter;
+
+ public SFixed64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ long value = primitiveGetter.get(message);
+ output.writeScalarSFixed64(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SInt32WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SInt32WriteSchemas.java
new file mode 100644
index 0000000..343926d
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SInt32WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.IntGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class SInt32WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (int.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new SInt32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new SInt32Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new SInt32DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class SInt32DynamicSchema<T> extends FieldSchema<T> {
+ public SInt32DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarSInt32(tag, tagSize, ((Number) value).intValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ int parsedValue = Integer.parseInt(((String[]) value)[0], 10);
+ output.writeScalarSInt32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ int parsedValue = Integer.parseInt((String) value, 10);
+ output.writeScalarSInt32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class SInt32Schema<T> extends SInt32DynamicSchema<T> {
+ protected final Getter<T, Integer> getter;
+
+ public SInt32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Integer value = getter.get(message);
+ if (value != null) {
+ output.writeScalarSInt32(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class SInt32PrimitiveSchema<T> extends SInt32DynamicSchema<T> {
+ private final IntGetter<T> primitiveGetter;
+
+ public SInt32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ int value = primitiveGetter.get(message);
+ output.writeScalarSInt32(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SInt64WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SInt64WriteSchemas.java
new file mode 100644
index 0000000..16a41fc
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/SInt64WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.LongGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class SInt64WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new SInt64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new SInt64Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new SInt64DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class SInt64DynamicSchema<T> extends FieldSchema<T> {
+ public SInt64DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarSInt64(tag, tagSize, ((Number) value).longValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ long parsedValue = Long.parseLong(((String[]) value)[0], 10);
+ output.writeScalarSInt64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ long parsedValue = Long.parseLong((String) value, 10);
+ output.writeScalarSInt64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class SInt64Schema<T> extends SInt64DynamicSchema<T> {
+ protected final Getter<T, Long> getter;
+
+ public SInt64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Long value = getter.get(message);
+ if (value != null) {
+ output.writeScalarSInt64(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class SInt64PrimitiveSchema<T> extends SInt64DynamicSchema<T> {
+ private final LongGetter<T> primitiveGetter;
+
+ public SInt64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ long value = primitiveGetter.get(message);
+ output.writeScalarSInt64(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/StringWriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/StringWriteSchemas.java
new file mode 100644
index 0000000..77f18a9
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/StringWriteSchemas.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class StringWriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (String.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new StringSchema<>(protoField, propertyDescriptor);
+ }
+
+ return new StringDynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class StringDynamicSchema<T> extends FieldSchema<T> {
+ public StringDynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof String) {
+ output.writeScalarString(tag, tagSize, (String) value);
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ output.writeScalarString(tag, tagSize, ((String[]) value)[0]);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class StringSchema<T> extends StringDynamicSchema<T> {
+ protected final Getter<T, String> getter;
+
+ public StringSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = javaType.isPrimitive() ? null : propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ String value = getter.get(message);
+ if (value != null) {
+ output.writeScalarString(tag, tagSize, value);
+ }
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/UInt32WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/UInt32WriteSchemas.java
new file mode 100644
index 0000000..9d89b5f
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/UInt32WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.IntGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class UInt32WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (int.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new UInt32PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Integer.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new UInt32Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new UInt32DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class UInt32DynamicSchema<T> extends FieldSchema<T> {
+ public UInt32DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarUInt32(tag, tagSize, ((Number) value).intValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ int parsedValue = Integer.parseInt(((String[]) value)[0], 10);
+ output.writeScalarUInt32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ int parsedValue = Integer.parseInt((String) value, 10);
+ output.writeScalarUInt32(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class UInt32Schema<T> extends UInt32DynamicSchema<T> {
+ protected final Getter<T, Integer> getter;
+
+ public UInt32Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Integer value = getter.get(message);
+ if (value != null) {
+ output.writeScalarUInt32(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class UInt32PrimitiveSchema<T> extends UInt32DynamicSchema<T> {
+ private final IntGetter<T> primitiveGetter;
+
+ public UInt32PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ int value = primitiveGetter.get(message);
+ output.writeScalarUInt32(tag, tagSize, value);
+ }
+ }
+}
diff --git a/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/UInt64WriteSchemas.java b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/UInt64WriteSchemas.java
new file mode 100644
index 0000000..4234d46
--- /dev/null
+++ b/foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/scalar/UInt64WriteSchemas.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar;
+
+import java.io.IOException;
+
+import org.apache.servicecomb.foundation.common.utils.bean.Getter;
+import org.apache.servicecomb.foundation.common.utils.bean.LongGetter;
+import org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils;
+import org.apache.servicecomb.foundation.protobuf.internal.bean.PropertyDescriptor;
+
+import io.protostuff.OutputEx;
+import io.protostuff.compiler.model.Field;
+import io.protostuff.runtime.FieldSchema;
+
+public class UInt64WriteSchemas {
+ public static <T> FieldSchema<T> create(Field protoField, PropertyDescriptor propertyDescriptor) {
+ if (long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new UInt64PrimitiveSchema<>(protoField, propertyDescriptor);
+ }
+
+ if (Long.class.equals(propertyDescriptor.getJavaType().getRawClass())) {
+ return new UInt64Schema<>(protoField, propertyDescriptor);
+ }
+
+ return new UInt64DynamicSchema<>(protoField, propertyDescriptor);
+ }
+
+ private static class UInt64DynamicSchema<T> extends FieldSchema<T> {
+ public UInt64DynamicSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor.getJavaType());
+ }
+
+ @Override
+ public final void writeTo(OutputEx output, Object value) throws IOException {
+ if (value instanceof Number) {
+ output.writeScalarUInt64(tag, tagSize, ((Number) value).longValue());
+ return;
+ }
+
+ if (value instanceof String[]) {
+ if (((String[]) value).length == 0) {
+ return;
+ }
+ long parsedValue = Long.parseLong(((String[]) value)[0], 10);
+ output.writeScalarUInt64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ if (value instanceof String) {
+ long parsedValue = Long.parseLong((String) value, 10);
+ output.writeScalarUInt64(tag, tagSize, parsedValue);
+ return;
+ }
+
+ ProtoUtils.throwNotSupportWrite(protoField, value);
+ }
+ }
+
+ private static class UInt64Schema<T> extends UInt64DynamicSchema<T> {
+ protected final Getter<T, Long> getter;
+
+ public UInt64Schema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ this.getter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ Long value = getter.get(message);
+ if (value != null) {
+ output.writeScalarUInt64(tag, tagSize, value);
+ }
+ }
+ }
+
+ private static class UInt64PrimitiveSchema<T> extends UInt64DynamicSchema<T> {
+ private final LongGetter<T> primitiveGetter;
+
+ public UInt64PrimitiveSchema(Field protoField, PropertyDescriptor propertyDescriptor) {
+ super(protoField, propertyDescriptor);
+
+ primitiveGetter = propertyDescriptor.getGetter();
+ }
+
+ @Override
+ public final void getAndWriteTo(OutputEx output, T message) throws IOException {
+ long value = primitiveGetter.get(message);
+ output.writeScalarUInt64(tag, tagSize, value);
+ }
+ }
+}