-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use native byte order as default
1. use native byte order as default; 2. add AbstractProtocol class.
- Loading branch information
Showing
4 changed files
with
50 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.indunet.fastproto; | ||
|
||
/** | ||
* Abstract protocol. | ||
* | ||
* @author Deng Ran | ||
* @since 3.11.0 | ||
*/ | ||
public abstract class AbstractProtocol { | ||
public static final int NON_FIXED_LENGTH = -1; | ||
|
||
protected int length = NON_FIXED_LENGTH; | ||
protected BitOrder bitOrder = BitOrder.LSB_0; | ||
protected ByteOrder byteOrder = ByteOrder.nativeOrder(); | ||
|
||
public byte[] toByteArray() { | ||
if (length == NON_FIXED_LENGTH) { | ||
return FastProto.encode(this); | ||
} else { | ||
return FastProto.encode(this, length); | ||
} | ||
} | ||
|
||
public String toHexString() { | ||
StringBuilder hexString = new StringBuilder(); | ||
|
||
for (byte b : toByteArray()) { | ||
hexString.append(String.format("%02x", b)); | ||
} | ||
|
||
return hexString.toString(); | ||
} | ||
|
||
public void printHexString() { | ||
System.out.println(toHexString()); | ||
} | ||
} |
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