Skip to content

Commit

Permalink
Adicionado doc ao codigo
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBalbucio committed May 27, 2024
1 parent f238799 commit e4160d7
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Deploy Javadoc

on:
push:
branches:
- master

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Deploy JavaDoc 🚀
uses: MathieuSoysal/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
javadoc-branch: javadoc
java-version: 8
target-folder: javadoc
project: maven
18 changes: 15 additions & 3 deletions src/main/java/balbucio/byson/BysonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

import balbucio.byson.utils.BysonCompressHelper;
import balbucio.byson.utils.BysonTypeHelper;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
* This class allows you to directly deserialize and serialize JSON.
*/
public class BysonParser {

/**
* Converts the binary to JSONObject again. The binary is already compressed.
* @param buffer json in binary format
* @return JSONObject
* @throws IOException If it is impossible to read the bytes or they are poorly aligned, this exception will appear.
*/
public static JSONObject deserialize(ByteBuffer buffer) throws IOException {
if (buffer != null) {
JSONObject json = new JSONObject();
Expand All @@ -33,6 +39,12 @@ public static JSONObject deserialize(ByteBuffer buffer) throws IOException {
return null;
}

/**
* Converts JSON to compressed binary using ByteBuffer to store.
* @param json JSONObject
* @return json in binary format
* @throws IOException If it is impossible to read the bytes or they are poorly aligned, this exception will appear.
*/
public static ByteBuffer serialize(JSONObject json) throws IOException {
if (json != null && !json.isEmpty()) {
List<byte[]> inputs = new ArrayList<>();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/balbucio/byson/utils/BysonCompressHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.util.zip.InflaterInputStream;
import java.util.zip.InflaterOutputStream;

/**
* Class with utilities for compression.
*/
public class BysonCompressHelper {

public static byte[] compress(byte[] bArray) {
Expand Down
35 changes: 34 additions & 1 deletion src/main/java/balbucio/byson/utils/BysonTypeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@
import java.util.List;
import java.util.Map;

/**
* Class with utilities to transform JSON types into binary.
*
* There is a lot of recursive code and some is needed for now.
*/
public class BysonTypeHelper {

/**
* Creates a ByteArray from a Key:Value
* @param s Key
* @param obj Value
* @return ByteArray in OutputStream
* @throws IOException If he can't write or convert.
*/
public static ByteArrayOutputStream keyValueToBinary(String s, Object obj) throws IOException {
ByteArrayOutputStream inputStream = null;

Expand Down Expand Up @@ -110,6 +122,14 @@ public static ByteArrayOutputStream keyValueToBinary(String s, Object obj) throw
return inputStream;
}

/**
* Transforms a list into a binary array.
*
* The binary generated for each type has fewer parameters.
* @param array List
* @return ByteArray
* @throws IOException If he can't write or convert.
*/
public static List<byte[]> listToBinary(Iterable array) throws IOException {
List<byte[]> inputs = new ArrayList<>();
for (Object obj : array) {
Expand Down Expand Up @@ -197,7 +217,12 @@ public static List<byte[]> listToBinary(Iterable array) throws IOException {
}
return inputs;
}

/**
* Transforms a map into a binary array.
* @param map Map
* @return ByteArray
* @throws IOException If he can't write or convert.
*/
public static List<byte[]> mapToBinary(Map<String, Object> map) throws IOException {
List<byte[]> inputs = new ArrayList<>();

Expand All @@ -212,6 +237,14 @@ public static List<byte[]> mapToBinary(Map<String, Object> map) throws IOExcepti
return inputs;
}

/**
* Transforms the binary into an object, using a parameter in Short format.
* @param type short type number
* @param obj where it should be set.
* @param data
* @return returns the object itself (obj parameter)
* @throws IOException If he can't write or convert.
*/
public static Object parseObject(short type, Object obj, DataInputStream data) throws IOException {
if (type == 0) { // Int
obj = data.readInt();
Expand Down

0 comments on commit e4160d7

Please sign in to comment.