Skip to content

Commit

Permalink
fix javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
youwenbusi committed Sep 26, 2022
1 parent 6481a19 commit a97b5aa
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 115 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.5-rc.9-SNAPSHOT
1.8.6-rc.1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import com.webank.weid.util.DataToolUtils;
import com.webank.weid.util.Multibase.Multibase;
import com.webank.weid.util.Multicodec.AmbiguousCodecEncodingException;
import com.webank.weid.util.Multicodec.DecodedData;
import com.webank.weid.util.Multicodec.MulticodecEncoder;
import lombok.Data;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/webank/weid/rpc/WeIdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
import com.webank.weid.protocol.base.*;
import com.webank.weid.protocol.request.AuthenticationArgs;
import com.webank.weid.protocol.request.CreateWeIdArgs;
import com.webank.weid.protocol.request.PublicKeyArgs;
import com.webank.weid.protocol.request.ServiceArgs;
import com.webank.weid.protocol.response.CreateWeIdDataResult;
import com.webank.weid.protocol.response.ResponseData;
import com.webank.weid.protocol.response.WeIdListResult;
import com.webank.weid.util.Multicodec.AmbiguousCodecEncodingException;



/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import com.webank.weid.protocol.base.*;
import com.webank.weid.util.Multibase.Multibase;
import com.webank.weid.util.Multicodec.AmbiguousCodecEncodingException;
import com.webank.weid.util.Multicodec.Multicodec;
import com.webank.weid.util.Multicodec.MulticodecEncoder;
import org.apache.commons.lang3.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ResponseData<Boolean> createWeId(
String weAddress,
String publicKey,
String privateKey
) throws NoSuchAlgorithmException;
);

/**
* call weid contract to deactivate a weid.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
import java.io.IOException;

/**
* <p>Multicodec is part of the Multiformats collection of protocols.</p>
* <br/>
* <p>Multiformats is a collection of protocols which aim to future-proof systems, today. They do this mainly by allowing
* data to be self-describable.</p>
* <p>See: <a href="https://github.com/multiformats/multiformats">https://github.com/multiformats/multiformats</a></p>
* <p>The Multicodec is an agreed way for encoding bytes with a prefix that specifies the type of encoding.
* Multicodec is part of the Multiformats collection of protocols.
*
* Multiformats is a collection of protocols which aim to future-proof systems, today. They do this mainly by allowing
* data to be self-describable.
* See: https://github.com/multiformats/multiformats
* The Multicodec is an agreed way for encoding bytes with a prefix that specifies the type of encoding.
* The format is therefore a portable and self describing way of expressing an encoding of bytes that does not assume
* a specific context. </p>
* <p>See: <a href="https://github.com/multiformats/multicodec">https://github.com/multiformats/multicodec</a></p>
* <p>For example, the multicodec specification is used in the specifications for Decentralised Identifiers (DIDs) in
* a specific context.
* See: https://github.com/multiformats/multicodec
* For example, the multicodec specification is used in the specifications for Decentralised Identifiers (DIDs) in
* regard to the DID Method 'key' specification.
* Therefore, any work on `did:key` implementations needs to also solve for the use of multicodecs.</p>
* <p>See: <a href="https://w3c-ccg.github.io/did-method-key">https://w3c-ccg.github.io/did-method-key</a></p>
* <br/>
* Therefore, any work on `did:key` implementations needs to also solve for the use of multicodecs.
* See: https://w3c-ccg.github.io/did-method-key
*
*/
public class MulticodecEncoder {
Expand Down Expand Up @@ -57,31 +56,21 @@ public static byte[] encode(Multicodec multicodec, byte[] data) {
}

/**
* Decodes a multicodec encoded byte array.<br/>
* <br/>
* <b>Assumption: The decoding only supports single byte codec codes. </b></br>
* Some codec codes are multibyte values and these cannot be distinguished from single byte codec codes </br>
* Decodes a multicodec encoded byte array.
* Assumption: The decoding only supports single byte codec codes.
* Some codec codes are multibyte values and these cannot be distinguished from single byte codec codes
* when the data follows.
* <br/>
* <br/>
* Consider this encoding of sample data 'A1E9D3D8EC'<br/>
*<pre>
* Consider this encoding of sample data 'A1E9D3D8EC'
* 1. cidv1 encoding starts with 0x10.
* - therefore sample encoding hex data is: 01A1E9D3D8EC
* 2. udp encoding starts with 0x0111
* - therefore sample encoding hex data is: 0111A1E9D3D8EC
*</pre>
*
* Looking 2 it is impossible to determine if its<br/>
* <ol>
* <li> cidv1 encoding with data '11A1E9D3D8EC', or </li>
* <li> or if it is udp encoding with data 'A1E9D3D8EC'.</li>
* </ol>
*
* <p>
* Looking 2 it is impossible to determine if its
* cidv1 encoding with data '11A1E9D3D8EC',
* or if it is udp encoding with data 'A1E9D3D8EC'.
* This suggests an issue in the multi codec specification for codec prefixes greater than 1 byte.
* They cannot be 1:1 unambiguously mapped between each other.
* <br/>
* @param multicodecEncodedData The multicodec encoded data
* @return The DecodedData object
*/
Expand Down
67 changes: 13 additions & 54 deletions src/main/java/com/webank/weid/util/Multicodec/VarInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
* limitations under the License.
* --------------------------------------------------------------------------------
*
* <p>Encodes signed and unsigned values using a common variable-length
* Encodes signed and unsigned values using a common variable-length
* scheme, found for example in
* <a href="http://code.google.com/apis/protocolbuffers/docs/encoding.html">
* Google's Protocol Buffers</a>. It uses fewer bytes to encode smaller values,
* but will use slightly more bytes to encode large values.</p>
* <p/>
* <p>Signed values are further encoded using so-called zig-zag encoding
* in order to make them "compatible" with variable-length encoding.</p>
* http://code.google.com/apis/protocolbuffers/docs/encoding.html
* Google's Protocol Buffers. It uses fewer bytes to encode smaller values,
* but will use slightly more bytes to encode large values.
* Signed values are further encoded using so-called zig-zag encoding
* in order to make them "compatible" with variable-length encoding.
*/

@SuppressWarnings("GrazieInspection")
Expand All @@ -37,10 +36,10 @@ private VarInt() {}

/**
* Encodes a value using the variable-length encoding from
* <a href="http://code.google.com/apis/protocolbuffers/docs/encoding.html">
* Google Protocol Buffers</a>. It uses zig-zag encoding to efficiently
* http://code.google.com/apis/protocolbuffers/docs/encoding.html
* Google Protocol Buffers. It uses zig-zag encoding to efficiently
* encode signed values. If values are known to be non negative,
* {@link #writeUnsignedVarLong(long, DataOutput)} should be used.
* writeUnsignedVarLong should be used.
*
* @param value value to encode
* @param out to write bytes to
Expand All @@ -53,13 +52,13 @@ public static void writeSignedVarLong(long value, DataOutput out) throws IOExcep

/**
* Encodes a value using the variable-length encoding from
* <a href="http://code.google.com/apis/protocolbuffers/docs/encoding.html">
* Google Protocol Buffers</a>. Zig-zag is not used, so input must not be negative.
* If values can be negative, use {@link #writeSignedVarLong(long, DataOutput)}
* http://code.google.com/apis/protocolbuffers/docs/encoding.html
* Google Protocol Buffers. Zig-zag is not used, so input must not be negative.
* If values can be negative, use writeSignedVarLong
* instead. This method treats negative input as like a large unsigned value.
*
* @param value value to encode
* @param out to write bytes to
* @param out to write bytes to
* @throws IOException if {@link DataOutput} throws {@link IOException}
*/
public static void writeUnsignedVarLong(long value, DataOutput out) throws IOException {
Expand All @@ -70,17 +69,11 @@ public static void writeUnsignedVarLong(long value, DataOutput out) throws IOExc
out.writeByte((int) value & 0x7F);
}

/**
* @see #writeSignedVarLong(long, DataOutput)
*/
public static void writeSignedVarInt(int value, DataOutput out) throws IOException {
// Great trick from http://code.google.com/apis/protocolbuffers/docs/encoding.html#types
writeUnsignedVarInt((value << 1) ^ (value >> 31), out);
}

/**
* @see #writeUnsignedVarLong(long, DataOutput)
*/
public static void writeUnsignedVarInt(int value, DataOutput out) throws IOException {
while ((value & 0xFFFFFF80) != 0L) {
out.writeByte((value & 0x7F) | 0x80);
Expand All @@ -94,12 +87,6 @@ public static byte[] writeSignedVarInt(int value) {
return writeUnsignedVarInt((value << 1) ^ (value >> 31));
}

/**
* @see #writeUnsignedVarLong(long, DataOutput)
* <p/>
* This one does not use streams and is much faster.
* Makes a single object each time, and that object is a primitive array.
*/
public static byte[] writeUnsignedVarInt(int value) {
byte[] byteArrayList = new byte[10];
int i = 0;
Expand All @@ -115,14 +102,6 @@ public static byte[] writeUnsignedVarInt(int value) {
return out;
}

/**
* @param in to read bytes from
* @return decode value
* @throws IOException if {@link DataInput} throws {@link IOException}
* @throws IllegalArgumentException if variable-length value does not terminate
* after 9 bytes have been read
* @see #writeSignedVarLong(long, DataOutput)
*/
public static long readSignedVarLong(DataInput in) throws IOException {
long raw = readUnsignedVarLong(in);
// This undoes the trick in writeSignedVarLong()
Expand All @@ -133,14 +112,6 @@ public static long readSignedVarLong(DataInput in) throws IOException {
return temp ^ (raw & (1L << 63));
}

/**
* @param in to read bytes from
* @return decode value
* @throws IOException if {@link DataInput} throws {@link IOException}
* @throws IllegalArgumentException if variable-length value does not terminate
* after 9 bytes have been read
* @see #writeUnsignedVarLong(long, DataOutput)
*/
public static long readUnsignedVarLong(DataInput in) throws IOException {
long value = 0L;
int i = 0;
Expand All @@ -155,12 +126,6 @@ public static long readUnsignedVarLong(DataInput in) throws IOException {
return value | (b << i);
}

/**
* @throws IllegalArgumentException if variable-length value does not terminate
* after 5 bytes have been read
* @throws IOException if {@link DataInput} throws {@link IOException}
* @see #readSignedVarLong(DataInput)
*/
public static int readSignedVarInt(DataInput in) throws IOException {
int raw = readUnsignedVarInt(in);
// This undoes the trick in writeSignedVarInt()
Expand All @@ -171,12 +136,6 @@ public static int readSignedVarInt(DataInput in) throws IOException {
return temp ^ (raw & (1 << 31));
}

/**
* @throws IllegalArgumentException if variable-length value does not terminate
* after 5 bytes have been read
* @throws IOException if {@link DataInput} throws {@link IOException}
* @see #readUnsignedVarLong(DataInput)
*/
public static int readUnsignedVarInt(DataInput in) throws IOException {
int value = 0;
int i = 0;
Expand Down

0 comments on commit a97b5aa

Please sign in to comment.