Skip to content

Commit

Permalink
test: add lambda test
Browse files Browse the repository at this point in the history
  • Loading branch information
Deng-Ran committed Oct 12, 2022
1 parent dc5c05f commit a02db28
Show file tree
Hide file tree
Showing 51 changed files with 321 additions and 139 deletions.
7 changes: 0 additions & 7 deletions src/main/java/org/indunet/fastproto/FormulaBuilder.java

This file was deleted.

11 changes: 11 additions & 0 deletions src/main/java/org/indunet/fastproto/ProtocolType.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ static ProtocolType proxy(Annotation typeAnnotation) {
.noneMatch(m -> m.getName().equals("length"))) {
return 0;
}
case "defaultJavaType":
try {
return (Class) typeAnnotation
.annotationType()
.getDeclaredField("DEFAULT_JAVA_TYPE")
.get(null);
} catch (IllegalAccessException | NoSuchFieldException e) {
return null;
}
default:
if (typeAnnotation.annotationType() == BoolType.class && method.getName().equals("offset")) {
return Arrays.stream(typeAnnotation.getClass().getMethods())
Expand Down Expand Up @@ -97,4 +106,6 @@ static ProtocolType proxy(Annotation typeAnnotation) {
Class<? extends Annotation> getType();

int size();

Class defaultJavaType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface BinaryType {
Class DEFAULT_JAVA_TYPE = byte[].class;

int offset();

int length() default -1;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/indunet/fastproto/annotation/BoolType.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface BoolType {
Class DEFAULT_JAVA_TYPE = Boolean.class;

int SIZE = 1;
int MAX_BIT_OFFSET = 7;
int MIN_BIT_OFFSET = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/indunet/fastproto/annotation/CharType.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CharType {
Class DEFAULT_JAVA_TYPE = Character.class;

int SIZE = Character.SIZE >> 3;

int offset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DoubleArrayType {
Class DEFAULT_JAVA_TYPE = double[].class;

int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DoubleType {
Class DEFAULT_JAVA_TYPE = Double.class;
int SIZE = Double.SIZE >> 3;
double MAX_VALUE = Double.MAX_VALUE;
double MIN_VALUE = Double.MIN_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EnumType {
Class DEFAULT_JAVA_TYPE = Enum.class;
int SIZE = Byte.SIZE >> 3;
int MAX_VALUE = Byte.MAX_VALUE - Byte.MIN_VALUE;
int MIN_VALUE = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface FloatArrayType {
Class DEFAULT_JAVA_TYPE = float[].class;
int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface FloatType {
Class DEFAULT_JAVA_TYPE = Float.class;
int SIZE = Float.SIZE >> 3;
float MAX_VALUE = Float.MAX_VALUE;
float MIN_VALUE = Float.MIN_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Int16ArrayType {
Class DEFAULT_JAVA_TYPE = int[].class;
int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Int16Type {
Class DEFAULT_JAVA_TYPE = Integer.class;
int SIZE = Short.SIZE >> 3;
int MAX_VALUE = Short.MAX_VALUE;
int MIN_VALUE = Short.MIN_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Int32ArrayType {
Class DEFAULT_JAVA_TYPE = int[].class;
int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Int32Type {
Class DEFAULT_JAVA_TYPE = Integer.class;
int SIZE = Integer.SIZE >> 3;
int MAX_VALUE = Integer.MAX_VALUE;
int MIN_VALUE = Integer.MIN_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Int64ArrayType {
Class DEFAULT_JAVA_TYPE = long[].class;
int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Int64Type {
Class DEFAULT_JAVA_TYPE = Long.class;
int SIZE = Long.SIZE >> 3;
long MAX_VALUE = Long.MAX_VALUE;
long MIN_VALUE = Long.MIN_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Int8ArrayType {
Class DEFAULT_JAVA_TYPE = int[].class;
int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Int8Type {
Class DEFAULT_JAVA_TYPE = Integer.class;
int SIZE = Byte.SIZE >> 3;
int MAX_VALUE = Byte.MAX_VALUE;
int MIN_VALUE = Byte.MIN_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface StringType {
Class DEFAULT_JAVA_TYPE = String.class;
int offset();

int length() default -1;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/indunet/fastproto/annotation/TimeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Date;

/**
* Timestamp type, corresponding to Java java.sql.Timestamp.
Expand All @@ -40,6 +41,8 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface TimeType {
Class DEFAULT_JAVA_TYPE = Date.class;

int SIZE = Long.SIZE >> 3;

int offset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface UInt16ArrayType {
Class DEFAULT_JAVA_TYPE = int[].class;
int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface UInt16Type {
Class DEFAULT_JAVA_TYPE = Integer.class;
int SIZE = Short.SIZE >> 3;
int MAX_VALUE = Short.MAX_VALUE - Short.MIN_VALUE;
int MIN_VALUE = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface UInt32ArrayType {
Class DEFAULT_JAVA_TYPE = long[].class;
int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface UInt32Type {
Class DEFAULT_JAVA_TYPE = long[].class;
int SIZE = Integer.SIZE >> 3;
long MAX_VALUE = (long) Integer.MAX_VALUE - Integer.MIN_VALUE;
int MIN_VALUE = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.math.BigInteger;

/**
* UInt64 array type
Expand All @@ -38,6 +39,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface UInt64ArrayType {
Class DEFAULT_JAVA_TYPE = BigInteger[].class;
int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface UInt64Type {
Class DEFAULT_JAVA_TYPE = BigInteger.class;
int SIZE = Long.SIZE >> 3;
BigInteger MAX_VALUE = new BigInteger(String.valueOf(Long.MAX_VALUE))
.subtract(new BigInteger(String.valueOf(Long.MIN_VALUE)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Date;

/**
* UInt8 array type
Expand All @@ -39,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface UInt8ArrayType {
Class DEFAULT_JAVA_TYPE = int[].class;
int offset();

int length() default -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface UInt8Type {
Class DEFAULT_JAVA_TYPE = Integer.class;
int SIZE = Byte.SIZE >> 3;
int MAX_VALUE = Byte.MAX_VALUE - Byte.MIN_VALUE;
int MIN_VALUE = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @author Deng Ran
* @since 3.2.1
*/
public class CodecFactory {
public class CodecMapper {
protected static ConcurrentHashMap<Class, Map<Predicate<Type>, Codec>> codecMap = new ConcurrentHashMap<>();
protected static ConcurrentHashMap<Class<? extends Function>, Function> formulas = new ConcurrentHashMap<>();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@
* @author Chance
* @since 1.0.0
*/
public class DecodeFormulaException extends DecodingException {
public DecodeFormulaException() {
public class FormulaException extends DecodingException {
public FormulaException() {

}

public DecodeFormulaException(CodecError error) {
public FormulaException(CodecError error) {
this(error.getMessage());
}

public DecodeFormulaException(String message) {
public FormulaException(String message) {
super(message);
}

public DecodeFormulaException(CodecError error, Throwable cause) {
public FormulaException(CodecError error, Throwable cause) {
this(error.getMessage(), cause);
}

public DecodeFormulaException(String message, Throwable cause) {
public FormulaException(String message, Throwable cause) {
super(message, cause);
}
}
Loading

0 comments on commit a02db28

Please sign in to comment.