Skip to content

Commit

Permalink
init some interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gongxuanzhang committed Oct 31, 2023
1 parent 39b3b3d commit c6c439e
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

.idea
*.iml
*.DS_store
out
gen
target/
db/

5 changes: 5 additions & 0 deletions README.md
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
13 changes: 13 additions & 0 deletions easyByte-core/pom.xml
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>
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);


}
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();
}
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);
}
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 {


}
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;
}




}
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 {


}

0 comments on commit c6c439e

Please sign in to comment.