-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39b3b3d
commit c6c439e
Showing
9 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# easyByte | ||
Helps you manipulate bytes more easily | ||
|
||
|
||
1 .支持基本类型的append | ||
2. 支持对象的append | ||
3. 支持集合append |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>easyByte-core</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
|
||
|
||
</project> |
18 changes: 18 additions & 0 deletions
18
easyByte-core/src/main/java/org/gongxuanzhang/easybyte/core/ByteConvert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.gongxuanzhang.easybyte.core; | ||
|
||
/** | ||
* @author gxz [email protected] | ||
**/ | ||
@FunctionalInterface | ||
public interface ByteConvert<V> { | ||
|
||
/** | ||
* convert sth to byte array | ||
* | ||
* @param v can convert value | ||
* @return byte array not null ,may be length is zero | ||
**/ | ||
byte[] toBytes(V v); | ||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
easyByte-core/src/main/java/org/gongxuanzhang/easybyte/core/ByteWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.gongxuanzhang.easybyte.core; | ||
|
||
/** | ||
* @author gxz [email protected] | ||
**/ | ||
@FunctionalInterface | ||
public interface ByteWrapper { | ||
|
||
/** | ||
* serialize my self | ||
* | ||
* @return byte array not null,may be length is zero | ||
**/ | ||
byte[] toBytes(); | ||
} |
101 changes: 101 additions & 0 deletions
101
easyByte-core/src/main/java/org/gongxuanzhang/easybyte/core/DynamicByteBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package org.gongxuanzhang.easybyte.core; | ||
|
||
import org.gongxuanzhang.easybyte.core.exception.WrapperNotFoundException; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* @author gxz [email protected] | ||
**/ | ||
public interface DynamicByteBuffer { | ||
|
||
|
||
/** | ||
* put a byte | ||
* | ||
* @param b a byte | ||
* @return this | ||
**/ | ||
DynamicByteBuffer put(byte b); | ||
|
||
/** | ||
* put a short | ||
* | ||
* @param s a short | ||
* @return this | ||
**/ | ||
DynamicByteBuffer putShort(short s); | ||
|
||
/** | ||
* put a int | ||
* | ||
* @param i a int | ||
* @return this | ||
**/ | ||
DynamicByteBuffer putInt(int i); | ||
|
||
|
||
/** | ||
* put a long | ||
* | ||
* @param l a long | ||
* @return this | ||
**/ | ||
DynamicByteBuffer putLong(long l); | ||
|
||
/** | ||
* put a float | ||
* | ||
* @param f a float | ||
* @return this | ||
**/ | ||
DynamicByteBuffer putFloat(float f); | ||
|
||
/** | ||
* put a double | ||
* | ||
* @param d a double | ||
* @return this | ||
**/ | ||
DynamicByteBuffer putDouble(double d); | ||
|
||
/** | ||
* put a char | ||
* | ||
* @param c a char | ||
* @return this | ||
**/ | ||
DynamicByteBuffer putChar(char c); | ||
|
||
/** | ||
* put a boolean | ||
* | ||
* @param bool a boolean | ||
* @return this | ||
**/ | ||
DynamicByteBuffer putBoolean(boolean bool); | ||
|
||
|
||
/** | ||
* put a collection | ||
* the order of puts depends on the order of traversal | ||
* item in collection will converted to byte array for put buffer | ||
* primitive type and packing type will invoke corresponding method | ||
* reference type will find convert or wrapper to invoke method | ||
* if neither convert nor wrapper can be found,an {@link WrapperNotFoundException} will be throw | ||
* | ||
* @param collection use for put | ||
* @return this | ||
**/ | ||
DynamicByteBuffer putCollection(Collection<?> collection); | ||
|
||
/** | ||
* specify a converter to convert item | ||
* {@link this#putCollection(Collection)} | ||
* | ||
* @param collection a collection | ||
* @param convert specify convert | ||
* @return this | ||
**/ | ||
<V> DynamicByteBuffer putCollection(Collection<V> collection, ByteConvert<V> convert); | ||
} |
13 changes: 13 additions & 0 deletions
13
easyByte-core/src/main/java/org/gongxuanzhang/easybyte/core/EasyByteConguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.gongxuanzhang.easybyte.core; | ||
|
||
/** | ||
* | ||
* easy byte configuration | ||
* register for wrapper | ||
* and so on | ||
* @author gxz [email protected] | ||
**/ | ||
public interface EasyByteConguration { | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
easyByte-core/src/main/java/org/gongxuanzhang/easybyte/core/GlobalConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.gongxuanzhang.easybyte.core; | ||
|
||
/** | ||
* Applies to global configuration | ||
* it is the last item in the configuration | ||
* | ||
* @author gxz [email protected] | ||
**/ | ||
public class GlobalConfig { | ||
|
||
private static volatile GlobalConfig INSTANCE = null; | ||
|
||
public static GlobalConfig getInstance() { | ||
if (INSTANCE == null) { | ||
synchronized (GlobalConfig.class) { | ||
if (INSTANCE == null) { | ||
INSTANCE = new GlobalConfig(); | ||
} | ||
} | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
|
||
|
||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...ore/src/main/java/org/gongxuanzhang/easybyte/core/exception/WrapperNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.gongxuanzhang.easybyte.core.exception; | ||
|
||
/** | ||
* @author gxz [email protected] | ||
**/ | ||
public class WrapperNotFoundException extends RuntimeException { | ||
|
||
|
||
} |