Skip to content

Commit

Permalink
Change CBORX to CborX for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Apr 20, 2020
1 parent cce9bd7 commit ba65bdf
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
7 changes: 0 additions & 7 deletions modules/core/src/main/java/org/dhallj/cbor/CBORException.java

This file was deleted.

7 changes: 7 additions & 0 deletions modules/core/src/main/java/org/dhallj/cbor/CborException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.dhallj.cbor;

public class CborException extends RuntimeException {
CborException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public R onTag() {
}

private R notExpected(String msg) {
throw new CBORException(String.format("%s not expected - expected null", msg));
throw new CborException(String.format("%s not expected - expected null", msg));
}
}
46 changes: 23 additions & 23 deletions modules/core/src/main/java/org/dhallj/cbor/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public final <R> R nextSymbol(Visitor<R> visitor) {
case MAP:
return visitor.onMap(readMapStart(b));
case SEMANTIC_TAG:
throw new CBORException("We should have skipped semantic tags");
throw new CborException("We should have skipped semantic tags");
case PRIMITIVE:
return readPrimitive(b, visitor);
default:
throw new CBORException(String.format("Invalid CBOR major type %d", b));
throw new CborException(String.format("Invalid CBOR major type %d", b));
}
}

Expand All @@ -52,7 +52,7 @@ public final BigInteger readPositiveBigNum() {
skip55799();
BigInteger result = readBigNum();
if (result.compareTo(BigInteger.ZERO) < 0) {
throw new CBORException(String.format("%s is not a positive big num", result));
throw new CborException(String.format("%s is not a positive big num", result));
} else {
return result;
}
Expand All @@ -78,10 +78,10 @@ public final BigInteger readBigNum() {
} else if (tag == 3) {
return BigInteger.valueOf(-1).subtract(result);
} else {
throw new CBORException(String.format("%d is not a valid tag for a bignum", tag));
throw new CborException(String.format("%d is not a valid tag for a bignum", tag));
}
default:
throw new CBORException(String.format("%d not a valid major type for an Unsigned Integer"));
throw new CborException(String.format("%d not a valid major type for an Unsigned Integer"));
}
}

Expand All @@ -94,7 +94,7 @@ public final String readNullableTextString() {
case PRIMITIVE:
return readPrimitive(next, NullVisitor.instanceForString);
default:
throw new CBORException("Next symbol is neither a text string or null");
throw new CborException("Next symbol is neither a text string or null");
}
}

Expand All @@ -107,7 +107,7 @@ public final byte[] readNullableByteString() {
case PRIMITIVE:
return readPrimitive(next, NullVisitor.instanceForByteArray);
default:
throw new CBORException("Next symbol is neither a byte string or null");
throw new CborException("Next symbol is neither a byte string or null");
}
}

Expand Down Expand Up @@ -137,12 +137,12 @@ public final BigInteger readArrayStart() {
AdditionalInfo info = AdditionalInfo.fromByte(next);
BigInteger length = readBigInteger(info, next);
if (length.compareTo(BigInteger.ZERO) < 0) {
throw new CBORException("Indefinite array not needed for Dhall");
throw new CborException("Indefinite array not needed for Dhall");
} else {
return length;
}
default:
throw new CBORException("Next symbol is not an array");
throw new CborException("Next symbol is not an array");
}
}

Expand All @@ -160,7 +160,7 @@ public final <R> Map<String, R> readMap(Visitor<R> visitor) {
}
return entries;
default:
throw new CBORException(
throw new CborException(
String.format("Cannot read map - major type is %s", MajorType.fromByte(b)));
}
}
Expand All @@ -179,7 +179,7 @@ private final byte[] readByteString(byte b) {
AdditionalInfo info = AdditionalInfo.fromByte(b);
BigInteger length = readBigInteger(info, b);
if (length.compareTo(BigInteger.ZERO) < 0) {
throw new CBORException("Indefinite byte string not needed for Dhall");
throw new CborException("Indefinite byte string not needed for Dhall");
} else {
// We don't handle the case where the length is > Integer.MaxValue
return this.read(length.intValue());
Expand All @@ -191,7 +191,7 @@ private final String readTextString(byte b) {
BigInteger length = readBigInteger(info, b);
if (length.compareTo(BigInteger.ZERO) < 0) {
// Indefinite length - do we need this for Dhall?
throw new CBORException("Indefinite text string not needed for Dhall");
throw new CborException("Indefinite text string not needed for Dhall");
} else {
// We don't handle the case where the length is > Integer.MaxValue
return new String(this.read(length.intValue()), Charset.forName("UTF-8"));
Expand All @@ -202,7 +202,7 @@ private final <R> R readArrayStart(byte b, Visitor<R> visitor) {
AdditionalInfo info = AdditionalInfo.fromByte(b);
BigInteger length = readBigInteger(info, b);
if (length.compareTo(BigInteger.ZERO) < 0) {
throw new CBORException("Indefinite array not needed for Dhall");
throw new CborException("Indefinite array not needed for Dhall");
} else {
skip55799();
byte next = read();
Expand All @@ -212,7 +212,7 @@ private final <R> R readArrayStart(byte b, Visitor<R> visitor) {
case TEXT_STRING:
return visitor.onVariableArray(length, readTextString(next));
default:
throw new CBORException(
throw new CborException(
String.format(
"Invalid start to CBOR-encoded Dhall expression %s",
MajorType.fromByte(b).toString()));
Expand All @@ -224,7 +224,7 @@ private final BigInteger readMapStart(byte b) {
AdditionalInfo info = AdditionalInfo.fromByte(b);
BigInteger length = readBigInteger(info, b);
if (length.compareTo(BigInteger.ZERO) < 0) {
throw new CBORException("Indefinite array not needed for Dhall");
throw new CborException("Indefinite array not needed for Dhall");
} else {
return length;
}
Expand All @@ -233,17 +233,17 @@ private final BigInteger readMapStart(byte b) {
private final <R> R readPrimitive(byte b, Visitor<R> visitor) {
int value = b & 31;
if (0 <= value && value <= 19) {
throw new CBORException(String.format("Primitive %d is unassigned", value));
throw new CborException(String.format("Primitive %d is unassigned", value));
} else if (value == 20) {
return visitor.onFalse();
} else if (value == 21) {
return visitor.onTrue();
} else if (value == 22) {
return visitor.onNull();
} else if (value == 23) {
throw new CBORException(String.format("Primitive %d is unassigned", value));
throw new CborException(String.format("Primitive %d is unassigned", value));
} else if (value == 24) {
throw new CBORException("Simple value not needed for Dhall");
throw new CborException("Simple value not needed for Dhall");
} else if (value == 25) {
// https://github.com/c-rack/cbor-java/blob/master/src/main/java/co/nstant/in/cbor/decoder/HalfPrecisionFloatDecoder.java
int bits = 0;
Expand Down Expand Up @@ -283,11 +283,11 @@ private final <R> R readPrimitive(byte b, Visitor<R> visitor) {
}
return visitor.onDoubleFloat(Double.longBitsToDouble(result));
} else if (28 <= value && value <= 30) {
throw new CBORException(String.format("Primitive %d is unassigned", value));
throw new CborException(String.format("Primitive %d is unassigned", value));
} else if (value == 31) {
throw new CBORException("Break stop code not needed for Dhall");
throw new CborException("Break stop code not needed for Dhall");
} else {
throw new CBORException(String.format("Primitive %d is not valid", value));
throw new CborException(String.format("Primitive %d is not valid", value));
}
}

Expand All @@ -303,7 +303,7 @@ private final void skip55799() {
BigInteger tag = readBigInteger(info, read()); // Now advance pointer
int t = tag.intValue();
if (t != 55799) {
throw new CBORException(String.format("Unrecognized CBOR semantic tag %d", t));
throw new CborException(String.format("Unrecognized CBOR semantic tag %d", t));
} else {
skip55799(); // Please tell me no encoders do this
}
Expand All @@ -325,7 +325,7 @@ private final BigInteger readBigInteger(AdditionalInfo info, byte first) {
case EIGHT_BYTES:
return readBigInteger(8);
case RESERVED:
throw new CBORException("Additional info RESERVED should not require reading a uintXX");
throw new CborException("Additional info RESERVED should not require reading a uintXX");
case INDEFINITE:
return BigInteger.valueOf(-1);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
* <p>Note that e.g. a negative integer by itself is an error, but a single float by itself is
* allowed.
*/
final class CBORDecodingVisitor implements Visitor<Expr> {
final class CborDecodingVisitor implements Visitor<Expr> {

private final Reader reader;

CBORDecodingVisitor(Reader reader) {
CborDecodingVisitor(Reader reader) {
this.reader = reader;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Decode {
public static final Expr decode(byte[] bytes) {
Reader reader = new Reader.ByteArrayReader(bytes);
// TODO check: if identifier then must be builtin using Expr.Constants.isBuiltInConstant
Expr e = reader.nextSymbol(new CBORDecodingVisitor(reader));
Expr e = reader.nextSymbol(new CborDecodingVisitor(reader));
return e;
}
}

0 comments on commit ba65bdf

Please sign in to comment.