Skip to content

Commit

Permalink
add readme and example
Browse files Browse the repository at this point in the history
  • Loading branch information
gongxuanzhang committed Nov 8, 2023
1 parent 3e35800 commit d969a6c
Show file tree
Hide file tree
Showing 7 changed files with 500 additions and 683 deletions.
876 changes: 202 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

79 changes: 74 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,76 @@
# easyByte
Helps you manipulate bytes more easily
<p align="center">
<img src="image/logo.png" align="center" alt="GitHub Readme Stats" />
<h2 align="center"></h2>
</p>

[![Java 8+](https://img.shields.io/badge/java-8+-4c7e9f.svg)](http://java.oracle.com)
[![Apache License 2](https://img.shields.io/badge/license-APL2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.txt)

[中文文档](./README_zh.md)

## What is EasyByte?

EasyByte is a ByteBuffer operate library. Simple,easy to use

## Why EasyByte?

- JDK's native ByteBuffer that after allocate can't update capacity, `EasyByte` can create a dynamic ByteBuffer.
- Strings are something we need to add frequently but ByteBuffer only support byte array.
- If you have a container like List,Map,must design a format policy,`EasyByte` can easy to use.
- Annoyed by the read and write mode of the native ByteBuffer. ByteBuffer created from `EasyByte` is read-write separated.




## Some API

[source,java,indent=0]
----

import org.gongxuanzhang.easybyte.core.DynamicByteBuffer;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class HowToUse {

public static void main(String[] args) {
DynamicByteBuffer allocate = DynamicByteBuffer.allocate();
allocate.appendString("hello world");
allocate.appendCollection(helloList());
allocate.appendMap(helloMap());

String helloWorld = allocate.getString();
List<String> list = allocate.getCollection(String.class);
Map<String, String> map = allocate.getMap(String.class, String.class);
System.out.println(helloWorld); // hello world
System.out.println(list); // [hello, world]
System.out.println(map); // {hello=world}
}

private static List<String> helloList() {
return Arrays.asList("hello", "world");
}

private static Map<String, String> helloMap() {
return Collections.singletonMap("hello", "world");
}
}

----






## Contributing

If you like EasyByte, star it please.

Please feel free to submit an [issue](https://github.com/gongxuanzhang/EasyByte/issues/new).

Fork and [PR](https://github.com/gongxuanzhang/EasyByte/pulls) are always welcomed.

1 .支持基本类型的append
2. 支持对象的append
3. 支持集合append
76 changes: 76 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<p align="center">
<img src="image/logo.png" align="center" alt="GitHub Readme Stats" />
<h2 align="center"></h2>
</p>

[![Java 8+](https://img.shields.io/badge/java-8+-4c7e9f.svg)](http://java.oracle.com)
[![Apache License 2](https://img.shields.io/badge/license-APL2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.txt)

[English](./README.md)

## EasyByte是什么?

EasyByte是一个ByteBuffer的操作库,简单好用。

## 为什么使用EasyByte?

- JDK原生的ByteBuffer在创建之后不能修改容量,`EasyByte`可以创建一个动态的ByteBuffer
- String是我们需要频繁添加的类型,但是原生ByteBuffer只能添加字节数组
- 如果你有一个集合,比如说List,Map,必须设计一些格式化方法,`EasyByte`可以让你很容易添加。
- 你对原生的ByteBuffer的读写模式很头疼,`EasyByte`创建的ByteBuffer是一个读写分离的




## 一些API

[source,java,indent=0]
----

import org.gongxuanzhang.easybyte.core.DynamicByteBuffer;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class HowToUse {

public static void main(String[] args) {
DynamicByteBuffer allocate = DynamicByteBuffer.allocate();
allocate.appendString("hello world");
allocate.appendCollection(helloList());
allocate.appendMap(helloMap());

String helloWorld = allocate.getString();
List<String> list = allocate.getCollection(String.class);
Map<String, String> map = allocate.getMap(String.class, String.class);
System.out.println(helloWorld); // hello world
System.out.println(list); // [hello, world]
System.out.println(map); // {hello=world}
}

private static List<String> helloList() {
return Arrays.asList("hello", "world");
}

private static Map<String, String> helloMap() {
return Collections.singletonMap("hello", "world");
}
}

----






## 贡献代码

若觉得不错,请Star.

有问题和需求请直接提[issue](https://github.com/gongxuanzhang/EasyByte/issues/new).

和我一起改进,请提交 [PR](https://github.com/gongxuanzhang/EasyByte/pulls)

29 changes: 29 additions & 0 deletions easyByte-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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>
<parent>
<groupId>org.gongxuanzhang</groupId>
<artifactId>easy-byte</artifactId>
<version>0.0.1</version>
</parent>

<groupId>com.zhonghaiwenda</groupId>
<artifactId>easyByte-example</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.gongxuanzhang</groupId>
<artifactId>easyByte-core</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.gongxuanzhang.easybyte.example;

import org.gongxuanzhang.easybyte.core.DynamicByteBuffer;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* @author [email protected]
**/
public class HowToUse {

public static void main(String[] args) {
DynamicByteBuffer allocate = DynamicByteBuffer.allocate();
allocate.appendString("hello world");
allocate.appendCollection(helloList());
allocate.appendMap(helloMap());

String helloWorld = allocate.getString();
List<String> list = allocate.getCollection(String.class);
Map<String, String> map = allocate.getMap(String.class, String.class);
System.out.println(helloWorld); // hello world
System.out.println(list); // [hello, world]
System.out.println(map); // {hello=world}
}

private static List<String> helloList() {
return Arrays.asList("hello", "world");
}

private static Map<String, String> helloMap() {
return Collections.singletonMap("hello", "world");
}
}
Binary file added image/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 83 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,59 @@
<packaging>pom</packaging>

<properties>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>8</java.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.release>8</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.0</junit.version>
<slf4j.version>2.0.9</slf4j.version>
<logback.version>1.4.11</logback.version>
<maven-source-plugin.version>3.0.0</maven-source-plugin.version>
</properties>


<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://172.16.1.10:8084/repository/gaea/</url>
</snapshotRepository>
<repository>
<id>nexus-releases</id>
<url>http://172.16.1.10:8084/repository/gaea/</url>
</repository>
</distributionManagement>

<!-- <distributionManagement>-->
<!-- <snapshotRepository>-->
<!-- <id>ossrh</id>-->
<!-- <url>https://oss.sonatype.org/content/repositories/snapshots</url>-->
<!-- </snapshotRepository>-->
<!-- <repository>-->
<!-- <id>ossrh</id>-->
<!-- <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>-->
<!-- </repository>-->
<!-- </distributionManagement>-->


<modules>
<module>easyByte-core</module>
<module>easyByte-example</module>
</modules>


<scm>
<url>https://github.com/gongxuanzhang/EasyByte</url>
</scm>

<developers>
<developer>
<id>gongxuanzhang</id>
<name>XuanZhang Gong</name>
<email>[email protected]</email>
</developer>
</developers>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -52,10 +91,50 @@
</dependencyManagement>



<build>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.sonatype.plugins</groupId>-->
<!-- <artifactId>nexus-staging-maven-plugin</artifactId>-->
<!-- <version>1.6.7</version>-->
<!-- <extensions>true</extensions>-->
<!-- <configuration>-->
<!-- <serverId>ossrh</serverId>-->
<!-- <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>-->
<!-- <autoReleaseAfterClose>true</autoReleaseAfterClose>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
<!-- <version>1.5</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>sign-artifacts</id>-->
<!-- <phase>verify</phase>-->
<!-- <goals>-->
<!-- <goal>sign</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down

0 comments on commit d969a6c

Please sign in to comment.