diff --git a/convex-benchmarks/src/main/java/convex/benchmarks/HashBenchmark.java b/convex-benchmarks/src/main/java/convex/benchmarks/HashBenchmark.java index 36bf22bd0..a6307e605 100644 --- a/convex-benchmarks/src/main/java/convex/benchmarks/HashBenchmark.java +++ b/convex-benchmarks/src/main/java/convex/benchmarks/HashBenchmark.java @@ -7,7 +7,7 @@ import convex.core.crypto.Hashing; import convex.core.data.AArrayBlob; import convex.core.data.Blob; -import convex.core.data.Format; +import convex.core.data.Cells; import convex.core.data.prim.CVMLong; /** @@ -21,7 +21,7 @@ public class HashBenchmark { @Benchmark public void longHash_SHA_256() { CVMLong l = CVMLong.create(17L); - AArrayBlob d = Format.encodedBlob(l); + AArrayBlob d = Cells.encode(l); Hashing.sha256(d.getInternalArray()); } diff --git a/convex-core/src/main/java/convex/core/Result.java b/convex-core/src/main/java/convex/core/Result.java index 8a5f9722d..48f1da3f4 100644 --- a/convex-core/src/main/java/convex/core/Result.java +++ b/convex-core/src/main/java/convex/core/Result.java @@ -18,7 +18,7 @@ import convex.core.data.AVector; import convex.core.data.Address; import convex.core.data.Blob; -import convex.core.data.Format; +import convex.core.data.Cells; import convex.core.data.Keyword; import convex.core.data.Keywords; import convex.core.data.Maps; @@ -302,7 +302,7 @@ public static Result read(Blob b, int pos) throws BadFormatException { int epos=pos; // include tag location since we are reading raw Vector (will ignore tag) AVector v=Vectors.read(b,epos); - epos+=Format.getEncodingLength(v); + epos+=Cells.getEncodingLength(v); // we can't check values yet because might be missing data diff --git a/convex-core/src/main/java/convex/core/cpos/Belief.java b/convex-core/src/main/java/convex/core/cpos/Belief.java index 730259de6..818a64bdc 100644 --- a/convex-core/src/main/java/convex/core/cpos/Belief.java +++ b/convex-core/src/main/java/convex/core/cpos/Belief.java @@ -161,7 +161,7 @@ public static Belief read(Blob b, int pos) throws BadFormatException { Index> orders = Format.read(b,epos); if (orders == null) throw new BadFormatException("Null orders in Belief"); - epos+=Format.getEncodingLength(orders); + epos+=Cells.getEncodingLength(orders); Belief result= new Belief(orders); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cpos/Block.java b/convex-core/src/main/java/convex/core/cpos/Block.java index 90f87a354..df42fdb64 100644 --- a/convex-core/src/main/java/convex/core/cpos/Block.java +++ b/convex-core/src/main/java/convex/core/cpos/Block.java @@ -158,7 +158,7 @@ public static Block read(Blob b, int pos) throws BadFormatException { epos+=8; AVector> transactions = Format.read(b,epos); - epos+=Format.getEncodingLength(transactions); + epos+=Cells.getEncodingLength(transactions); Block result=Block.create(timestamp, transactions); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cpos/BlockResult.java b/convex-core/src/main/java/convex/core/cpos/BlockResult.java index a45cffad6..f7f37599f 100644 --- a/convex-core/src/main/java/convex/core/cpos/BlockResult.java +++ b/convex-core/src/main/java/convex/core/cpos/BlockResult.java @@ -183,11 +183,11 @@ public static BlockResult read(Blob b, int pos) throws BadFormatException { State newState=Format.read(b,epos); if (newState==null) throw new BadFormatException("Null state"); - epos+=Format.getEncodingLength(newState); + epos+=Cells.getEncodingLength(newState); AVector newResults=Format.read(b,epos); if (newResults==null) throw new BadFormatException("Null results"); - epos+=Format.getEncodingLength(newResults); + epos+=Cells.getEncodingLength(newResults); BlockResult result=create(newState,newResults); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/PeerStatus.java b/convex-core/src/main/java/convex/core/cvm/PeerStatus.java index a50e0439a..b283d96c7 100644 --- a/convex-core/src/main/java/convex/core/cvm/PeerStatus.java +++ b/convex-core/src/main/java/convex/core/cvm/PeerStatus.java @@ -210,13 +210,13 @@ public int encodeRaw(byte[] bs, int pos) { public static PeerStatus read(Blob b, int pos) throws BadFormatException{ int epos=pos+1; // skip tag Address owner = Format.read(b,epos); - epos+=Format.getEncodingLength(owner); + epos+=Cells.getEncodingLength(owner); long stake = Format.readVLQLong(b,epos); epos+=Format.getVLQLongLength(stake); Index stakes = Format.read(b,epos); - epos+=Format.getEncodingLength(stakes); + epos+=Cells.getEncodingLength(stakes); if (stakes==null) { stakes=EMPTY_STAKES; } else if (stakes.isEmpty()) { @@ -227,7 +227,7 @@ public static PeerStatus read(Blob b, int pos) throws BadFormatException{ epos+=Format.getVLQLongLength(delegatedStake); AHashMap metadata = Format.read(b,epos); - epos+=Format.getEncodingLength(metadata); + epos+=Cells.getEncodingLength(metadata); long timestamp=Format.readVLQLong(b,epos); epos+=Format.getVLQLongLength(timestamp); diff --git a/convex-core/src/main/java/convex/core/cvm/Receipt.java b/convex-core/src/main/java/convex/core/cvm/Receipt.java index cab71debc..4bfd072f6 100644 --- a/convex-core/src/main/java/convex/core/cvm/Receipt.java +++ b/convex-core/src/main/java/convex/core/cvm/Receipt.java @@ -137,13 +137,13 @@ public static Receipt read(byte tag,Blob b, int pos) throws BadFormatException { boolean hasLog=((tag&Tag.RECEIPT_LOG_MASK)!=0); ACell result = Format.read(b,epos); - epos+=Format.getEncodingLength(result); + epos+=Cells.getEncodingLength(result); AVector> log=null; if (hasLog) { log = Vectors.read(b, epos); if ((log==null)||(log.isEmpty())) throw new BadFormatException("Expected non-empty log"); - epos+=Format.getEncodingLength(log); + epos+=Cells.getEncodingLength(log); } Receipt receipt=new Receipt(isError,result,log); diff --git a/convex-core/src/main/java/convex/core/cvm/State.java b/convex-core/src/main/java/convex/core/cvm/State.java index 509143f16..0742b57bd 100644 --- a/convex-core/src/main/java/convex/core/cvm/State.java +++ b/convex-core/src/main/java/convex/core/cvm/State.java @@ -239,19 +239,19 @@ public static State read(Blob b, int pos) throws BadFormatException { int epos=pos+1; // skip tag AVector accounts = Format.read(b,epos); if (accounts==null) throw new BadFormatException("Null accounts!"); - epos+=Format.getEncodingLength(accounts); + epos+=Cells.getEncodingLength(accounts); Index peers = Format.read(b,epos); if (peers==null) throw new BadFormatException("Null peers!"); - epos+=Format.getEncodingLength(peers); + epos+=Cells.getEncodingLength(peers); AVector globals = Format.read(b,epos); if (globals==null) throw new BadFormatException("Null globals!"); - epos+=Format.getEncodingLength(globals); + epos+=Cells.getEncodingLength(globals); Index> schedule = Format.read(b,epos); if (schedule==null) throw new BadFormatException("Null schedule!"); - epos+=Format.getEncodingLength(schedule); + epos+=Cells.getEncodingLength(schedule); State result=create(accounts, peers, globals, schedule); result.attachEncoding(b.slice(pos,epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/ops/Cond.java b/convex-core/src/main/java/convex/core/cvm/ops/Cond.java index 4a6c4765b..eef79ed4a 100644 --- a/convex-core/src/main/java/convex/core/cvm/ops/Cond.java +++ b/convex-core/src/main/java/convex/core/cvm/ops/Cond.java @@ -8,6 +8,7 @@ import convex.core.data.ASequence; import convex.core.data.AVector; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.IRefFunction; import convex.core.data.Vectors; @@ -110,7 +111,7 @@ public static Cond read(Blob b, int pos) throws BadFormatEx int epos=pos+Ops.OP_DATA_OFFSET; // skip tag and opcode to get to data AVector> ops = Format.read(b,epos); - epos+=Format.getEncodingLength(ops); + epos+=Cells.getEncodingLength(ops); Cond result=create(ops); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/ops/Def.java b/convex-core/src/main/java/convex/core/cvm/ops/Def.java index dc00cd0ed..61cb1e26d 100644 --- a/convex-core/src/main/java/convex/core/cvm/ops/Def.java +++ b/convex-core/src/main/java/convex/core/cvm/ops/Def.java @@ -6,6 +6,7 @@ import convex.core.cvm.Ops; import convex.core.data.ACell; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.IRefFunction; import convex.core.data.Ref; @@ -156,7 +157,7 @@ public static Def read(Blob b, int pos) throws BadFormatExc int epos=pos+Ops.OP_DATA_OFFSET; // skip tag and opcode to get to data ACell symbol = Format.read(b,epos); - epos+=Format.getEncodingLength(symbol); + epos+=Cells.getEncodingLength(symbol); Ref> ref = Format.readRef(b,epos); if (!validKey(symbol)) throw new BadFormatException("Symbol not valid for Def op"); diff --git a/convex-core/src/main/java/convex/core/cvm/ops/Do.java b/convex-core/src/main/java/convex/core/cvm/ops/Do.java index 0dbff3b64..6fb503207 100644 --- a/convex-core/src/main/java/convex/core/cvm/ops/Do.java +++ b/convex-core/src/main/java/convex/core/cvm/ops/Do.java @@ -8,6 +8,7 @@ import convex.core.data.ASequence; import convex.core.data.AVector; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.Vectors; import convex.core.data.util.BlobBuilder; @@ -91,7 +92,7 @@ public static Do read(Blob b, int pos) throws BadFormatExce int epos=pos+Ops.OP_DATA_OFFSET; // skip tag and opcode to get to data AVector> ops = Format.read(b,epos); - epos+=Format.getEncodingLength(ops); + epos+=Cells.getEncodingLength(ops); Do result=create(ops); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/ops/Invoke.java b/convex-core/src/main/java/convex/core/cvm/ops/Invoke.java index b679f1b02..b2dbe9ea8 100644 --- a/convex-core/src/main/java/convex/core/cvm/ops/Invoke.java +++ b/convex-core/src/main/java/convex/core/cvm/ops/Invoke.java @@ -8,6 +8,7 @@ import convex.core.data.ASequence; import convex.core.data.AVector; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.Vectors; import convex.core.data.type.Types; @@ -131,7 +132,7 @@ public byte opCode() { public static Invoke read(Blob b, int pos) throws BadFormatException { int epos=pos+Ops.OP_DATA_OFFSET; // skip tag and opcode to get to data AVector> ops = Format.read(b,epos); - epos+=Format.getEncodingLength(ops); + epos+=Cells.getEncodingLength(ops); Invoke result=create(ops); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/ops/Let.java b/convex-core/src/main/java/convex/core/cvm/ops/Let.java index 20f04f234..7dee60173 100644 --- a/convex-core/src/main/java/convex/core/cvm/ops/Let.java +++ b/convex-core/src/main/java/convex/core/cvm/ops/Let.java @@ -9,6 +9,7 @@ import convex.core.data.ASequence; import convex.core.data.AVector; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.IRefFunction; import convex.core.data.Ref; @@ -183,9 +184,9 @@ public static Let read(Blob b, int pos, boolean isLoop) thr int epos=pos+Ops.OP_DATA_OFFSET; // skip tag and opcode to get to data AVector syms = Format.read(b,epos); - epos+=Format.getEncodingLength(syms); + epos+=Cells.getEncodingLength(syms); AVector> ops = Format.read(b,epos); - epos+=Format.getEncodingLength(ops); + epos+=Cells.getEncodingLength(ops); Let result= create(syms, ops.toVector(),isLoop); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/ops/Lookup.java b/convex-core/src/main/java/convex/core/cvm/ops/Lookup.java index f22197c62..d7664ba84 100644 --- a/convex-core/src/main/java/convex/core/cvm/ops/Lookup.java +++ b/convex-core/src/main/java/convex/core/cvm/ops/Lookup.java @@ -8,6 +8,7 @@ import convex.core.data.ACell; import convex.core.data.Address; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.IRefFunction; import convex.core.data.Ref; @@ -107,10 +108,10 @@ public static Lookup read(Blob b,int pos) throws BadFormatE Symbol sym = Format.read(b,epos); if (sym==null) throw new BadFormatException("Lookup symbol cannot be null"); - epos+=Format.getEncodingLength(sym); + epos+=Cells.getEncodingLength(sym); AOp
address = Format.read(b,epos); - epos+=Format.getEncodingLength(address); + epos+=Cells.getEncodingLength(address); Lookup result= create(address,sym); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/ops/Query.java b/convex-core/src/main/java/convex/core/cvm/ops/Query.java index 36380d442..89832aa7c 100644 --- a/convex-core/src/main/java/convex/core/cvm/ops/Query.java +++ b/convex-core/src/main/java/convex/core/cvm/ops/Query.java @@ -9,6 +9,7 @@ import convex.core.data.ASequence; import convex.core.data.AVector; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.Vectors; import convex.core.data.util.BlobBuilder; @@ -98,7 +99,7 @@ public static Query read(Blob b, int pos) throws BadFormatE int epos=pos+Ops.OP_DATA_OFFSET; // skip tag and opcode to get to data AVector> ops = Format.read(b,epos); - epos+=Format.getEncodingLength(ops); + epos+=Cells.getEncodingLength(ops); Query result= create(ops); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/ops/Set.java b/convex-core/src/main/java/convex/core/cvm/ops/Set.java index 153f45427..5fba61d52 100644 --- a/convex-core/src/main/java/convex/core/cvm/ops/Set.java +++ b/convex-core/src/main/java/convex/core/cvm/ops/Set.java @@ -8,6 +8,7 @@ import convex.core.data.ACell; import convex.core.data.AVector; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.IRefFunction; import convex.core.data.Ref; @@ -95,7 +96,7 @@ public static Set read(Blob b, int pos) throws BadFormatExc epos+=Format.getVLQLongLength(position); AOp op = Format.read(b,epos); - epos+=Format.getEncodingLength(op); + epos+=Cells.getEncodingLength(op); Set result= create(position, op); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/ops/Try.java b/convex-core/src/main/java/convex/core/cvm/ops/Try.java index dfa1913ba..d8e1d8ed3 100644 --- a/convex-core/src/main/java/convex/core/cvm/ops/Try.java +++ b/convex-core/src/main/java/convex/core/cvm/ops/Try.java @@ -9,6 +9,7 @@ import convex.core.data.ASequence; import convex.core.data.AVector; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.Vectors; import convex.core.data.util.BlobBuilder; @@ -103,7 +104,7 @@ public static Try read(Blob b, int pos) throws BadFormatExc int epos=pos+Ops.OP_DATA_OFFSET; // skip tag and opcode to get to data AVector> ops = Format.read(b,epos); - epos+=Format.getEncodingLength(ops); + epos+=Cells.getEncodingLength(ops); Try result=create(ops); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/transactions/Call.java b/convex-core/src/main/java/convex/core/cvm/transactions/Call.java index d9b03c79d..5881b320c 100644 --- a/convex-core/src/main/java/convex/core/cvm/transactions/Call.java +++ b/convex-core/src/main/java/convex/core/cvm/transactions/Call.java @@ -6,6 +6,7 @@ import convex.core.data.AVector; import convex.core.data.Address; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.IRefFunction; import convex.core.data.Keyword; @@ -87,7 +88,7 @@ public static Call read(Blob b, int pos) throws BadFormatException { epos+=Format.getVLQCountLength(sequence); Address target=Format.read(b, epos); - epos+=Format.getEncodingLength(target); + epos+=Cells.getEncodingLength(target); long offer=Format.readVLQCount(b,epos); epos+=Format.getVLQCountLength(offer); @@ -95,10 +96,10 @@ public static Call read(Blob b, int pos) throws BadFormatException { Symbol functionName=Format.read(b,epos); - epos+=Format.getEncodingLength(functionName); + epos+=Cells.getEncodingLength(functionName); AVector args = Format.read(b,epos); - epos+=Format.getEncodingLength(args); + epos+=Cells.getEncodingLength(args); Call result=create(origin,sequence, target, offer, functionName,args); result.attachEncoding(b.slice(pos,epos)); diff --git a/convex-core/src/main/java/convex/core/cvm/transactions/Invoke.java b/convex-core/src/main/java/convex/core/cvm/transactions/Invoke.java index 286ecdbbe..7913cb08c 100644 --- a/convex-core/src/main/java/convex/core/cvm/transactions/Invoke.java +++ b/convex-core/src/main/java/convex/core/cvm/transactions/Invoke.java @@ -97,7 +97,7 @@ public static Invoke read(Blob b, int pos) throws BadFormatException { epos+=Format.getVLQCountLength(sequence); ACell args=Format.read(b, epos); - epos+=Format.getEncodingLength(args); + epos+=Cells.getEncodingLength(args); Invoke result=create(address, sequence, args); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/main/java/convex/core/data/CAD3Encoder.java b/convex-core/src/main/java/convex/core/data/CAD3Encoder.java index d52be963a..e113ec62c 100644 --- a/convex-core/src/main/java/convex/core/data/CAD3Encoder.java +++ b/convex-core/src/main/java/convex/core/data/CAD3Encoder.java @@ -5,10 +5,10 @@ /** * Base Encoder for CAD3 data / stores */ -public abstract class CAD3Encoder extends AEncoder { +public class CAD3Encoder extends AEncoder { public Blob encode(ACell a) { - return Format.encodedBlob(a); + return Cells.encode(a); } public ACell decode(Blob encoding) throws BadFormatException { @@ -22,5 +22,7 @@ public ACell decode(Blob encoding) throws BadFormatException { * @throws BadFormatException If CAD3 encoding format is invalid */ @Override - public abstract ACell decodeMultiCell(Blob enc) throws BadFormatException; + public ACell decodeMultiCell(Blob enc) throws BadFormatException { + return Format.decodeMultiCell(enc); + } } diff --git a/convex-core/src/main/java/convex/core/data/CVMEncoder.java b/convex-core/src/main/java/convex/core/data/CVMEncoder.java index 76409bf53..b952c26c3 100644 --- a/convex-core/src/main/java/convex/core/data/CVMEncoder.java +++ b/convex-core/src/main/java/convex/core/data/CVMEncoder.java @@ -1,14 +1,9 @@ package convex.core.data; -import convex.core.exceptions.BadFormatException; - public class CVMEncoder extends CAD3Encoder { public static final CVMEncoder INSTANCE = new CVMEncoder(); - @Override - public ACell decodeMultiCell(Blob enc) throws BadFormatException { - return Format.decodeMultiCell(enc); - } + } diff --git a/convex-core/src/main/java/convex/core/data/Cells.java b/convex-core/src/main/java/convex/core/data/Cells.java index 110ec026d..2af8dde1c 100644 --- a/convex-core/src/main/java/convex/core/data/Cells.java +++ b/convex-core/src/main/java/convex/core/data/Cells.java @@ -127,7 +127,7 @@ public static boolean isCVM(ACell a) { } /** - * Checks if a Cell is completely encoded, i.e. has not external Refs + * Checks if a Cell is completely encoded, i.e. has no external Refs * @param a Cell to check * @return True if completely encoded, false otherwise */ @@ -345,4 +345,20 @@ public static boolean isEmbedded(ACell cell) { return cell.isEmbedded(); } + /** + * Gets the encoded Blob for an object in CAD3 format + * + * @param o The object to encode + * @return Encoded data as a blob + */ + public static Blob encode(ACell o) { + if (o==null) return Blob.NULL_ENCODING; + return o.getEncoding(); + } + + public static int getEncodingLength(ACell value) { + if (value==null) return 1; + return value.getEncodingLength(); + } + } diff --git a/convex-core/src/main/java/convex/core/data/Format.java b/convex-core/src/main/java/convex/core/data/Format.java index 7c763e984..cf5f56382 100644 --- a/convex-core/src/main/java/convex/core/data/Format.java +++ b/convex-core/src/main/java/convex/core/data/Format.java @@ -558,13 +558,15 @@ public static T read(Blob blob, int offset) throws BadFormatEx } /** - * Helper method to read a value encoded as a hex string + * Helper method to read a CVM value encoded as a hex string * @param Type of value to read * @param hexString A valid hex String * @return Value read * @throws BadFormatException If encoding is invalid */ public static T read(String hexString) throws BadFormatException { + Blob enc=Blob.fromHex(hexString); + if (enc==null) throw new BadFormatException("Invalid hex string"); return read(Blob.fromHex(hexString)); } @@ -714,17 +716,6 @@ private static T readTransaction(byte tag, Blob b, int pos) th return (T) dr; } - /** - * Gets the encoded Blob for an object in canonical message format - * - * @param o The object to encode - * @return Encoded data as a blob - */ - public static Blob encodedBlob(ACell o) { - if (o==null) return Blob.NULL_ENCODING; - return o.getEncoding(); - } - /** * Writes hex digits from digit position start, total length. * @@ -752,24 +743,6 @@ public static int writeHexDigits(byte[] bs, int pos, ABlob src, long start, lon return pos+nBytes; } - /** - * Gets a hex String representing an object's encoding - * @param cell Any cell - * @return Hex String - */ - public static String encodedString(ACell cell) { - return encodedBlob(cell).toHexString(); - } - - /** - * Gets a hex String representing an object's encoding. Used in testing only. - * @param o Any object, will be cast to appropriate CVM type - * @return Hex String - */ - public static String encodedString(Object o) { - return encodedString(RT.cvm(o)); - } - /** * Estimate the encoding size of a Cell value. Useful for pre-sizing buffers. * @param cell Cell to estimate encoding size for @@ -817,7 +790,6 @@ public static ACell[] decodeCells(Blob data) throws BadFormatException { @SuppressWarnings("unchecked") public static T decodeMultiCell(Blob data) throws BadFormatException { long ml=data.count(); - if (ml>Format.MAX_MESSAGE_LENGTH) throw new BadFormatException("Message too long: "+ml); if (ml<1) throw new BadFormatException("Attempt to decode from empty Blob"); // read first cell @@ -942,7 +914,7 @@ public static void decodeCells(HashMap acc, Blob data) throws BadFor * @return Blob encoding */ public static Blob encodeMultiCell(ACell a, boolean everything) { - Blob topCellEncoding=Format.encodedBlob(a); + Blob topCellEncoding=Cells.encode(a); if (a.getRefCount()==0) return topCellEncoding; // Add any non-embedded child cells to stack @@ -979,7 +951,7 @@ public static Blob encodeMultiCell(ACell a, boolean everything) { int ix=topCellEncoding.size(); for (Ref r: refs) { ACell c=r.getValue(); - Blob enc=Format.encodedBlob(c); + Blob enc=Cells.encode(c); int encLength=enc.size(); // Write count then Blob encoding @@ -1001,7 +973,7 @@ public static Blob encodeMultiCell(ACell a, boolean everything) { public static Blob encodeCells(java.util.List cells) { int ml=0; for (ACell a:cells) { - Blob enc=Format.encodedBlob(a); // can be null in some cases, e.g. in DATA responses signalling missing data + Blob enc=Cells.encode(a); // can be null in some cases, e.g. in DATA responses signalling missing data int elen=enc.size(); if (ml>0) ml+=Format.getVLQCountLength(elen); ml+=elen; @@ -1010,7 +982,7 @@ public static Blob encodeCells(java.util.List cells) { byte[] msg=new byte[ml]; int ix=0; for (ACell a:cells) { - Blob enc=Format.encodedBlob(a); // can be null in some cases, e.g. in DATA responses signalling missing data; + Blob enc=Cells.encode(a); // can be null in some cases, e.g. in DATA responses signalling missing data; int elen=enc.size(); if (ix>0) ix=Format.writeVLQCount(msg,ix,elen); ix=enc.getBytes(msg, ix); @@ -1055,11 +1027,6 @@ public static Blob encodeDelta(java.util.List cells) { return Blob.wrap(msg); } - public static int getEncodingLength(ACell value) { - if (value==null) return 1; - return value.getEncodingLength(); - } - /** * Reads a long value represented by the specified bytes in a Blob * @param blob Blob instance diff --git a/convex-core/src/main/java/convex/core/data/Ref.java b/convex-core/src/main/java/convex/core/data/Ref.java index 82949ad5f..c4e30211b 100644 --- a/convex-core/src/main/java/convex/core/data/Ref.java +++ b/convex-core/src/main/java/convex/core/data/Ref.java @@ -606,7 +606,7 @@ public final int encode(byte[] bs, int pos) { @Override protected Blob createEncoding() { if (isEmbedded()) { - return Format.encodedBlob(getValue()); + return Cells.encode(getValue()); } byte[] bs=new byte[Ref.INDIRECT_ENCODING_LENGTH]; diff --git a/convex-core/src/main/java/convex/core/data/Syntax.java b/convex-core/src/main/java/convex/core/data/Syntax.java index d199316db..c7f76b1c6 100644 --- a/convex-core/src/main/java/convex/core/data/Syntax.java +++ b/convex-core/src/main/java/convex/core/data/Syntax.java @@ -168,7 +168,7 @@ public static Syntax read(Blob b, int pos) throws BadFormatException { epos+=datum.getEncodingLength(); AHashMap props = Format.read(b,epos); - epos+=Format.getEncodingLength(props); + epos+=Cells.getEncodingLength(props); if (props == null) { props = Maps.empty(); // we encode empty props as null for efficiency diff --git a/convex-core/src/main/java/convex/core/lang/Core.java b/convex-core/src/main/java/convex/core/lang/Core.java index 257e588a5..03ff26f64 100644 --- a/convex-core/src/main/java/convex/core/lang/Core.java +++ b/convex-core/src/main/java/convex/core/lang/Core.java @@ -41,7 +41,6 @@ import convex.core.data.Address; import convex.core.data.Blob; import convex.core.data.Cells; -import convex.core.data.Format; import convex.core.data.Hash; import convex.core.data.Index; import convex.core.data.Keyword; @@ -1808,7 +1807,7 @@ public Context invoke(Context context, ACell[] args) { if (args.length != 1) return context.withArityError(exactArityMessage(1, args.length)); ACell a = args[0]; - Blob encoding=Format.encodedBlob(a); + Blob encoding=Cells.encode(a); long juice=Juice.buildBlobCost(encoding.count()); if (!context.checkJuice(juice)) return context.withJuiceError(); diff --git a/convex-core/src/main/java/convex/core/lang/impl/Fn.java b/convex-core/src/main/java/convex/core/lang/impl/Fn.java index 5be555f16..09d6ca714 100644 --- a/convex-core/src/main/java/convex/core/lang/impl/Fn.java +++ b/convex-core/src/main/java/convex/core/lang/impl/Fn.java @@ -5,6 +5,7 @@ import convex.core.data.ACell; import convex.core.data.AVector; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.IRefFunction; import convex.core.data.Ref; @@ -136,14 +137,14 @@ public static Fn read(Blob b, int pos) throws BadFormatExce AVector params = Format.read(b,epos); if (params==null) throw new BadFormatException("Null parameters to Fn"); - epos+=Format.getEncodingLength(params); + epos+=Cells.getEncodingLength(params); AOp body = Format.read(b,epos); if (body==null) throw new BadFormatException("Null body in Fn"); - epos+=Format.getEncodingLength(body); + epos+=Cells.getEncodingLength(body); AVector lexicalEnv = Format.read(b,epos); - epos+=Format.getEncodingLength(lexicalEnv); + epos+=Cells.getEncodingLength(lexicalEnv); Fn result = new Fn<>(params, body, lexicalEnv); diff --git a/convex-core/src/main/java/convex/core/lang/impl/MultiFn.java b/convex-core/src/main/java/convex/core/lang/impl/MultiFn.java index 78d57255f..babb2a3fd 100644 --- a/convex-core/src/main/java/convex/core/lang/impl/MultiFn.java +++ b/convex-core/src/main/java/convex/core/lang/impl/MultiFn.java @@ -5,6 +5,7 @@ import convex.core.data.ACell; import convex.core.data.AVector; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.IRefFunction; import convex.core.data.Ref; @@ -124,7 +125,7 @@ public static MultiFn read(Blob b, int pos) throws BadForma AVector> fns=Format.read(b,epos); if (fns==null) throw new BadFormatException("Null fns!"); - epos+=Format.getEncodingLength(fns); + epos+=Cells.getEncodingLength(fns); MultiFn result= new MultiFn(fns); result.attachEncoding(b.slice(pos, epos)); diff --git a/convex-core/src/test/java/convex/comms/GenTestFormat.java b/convex-core/src/test/java/convex/comms/GenTestFormat.java index 0f983e4d1..aa38fa33c 100644 --- a/convex-core/src/test/java/convex/comms/GenTestFormat.java +++ b/convex-core/src/test/java/convex/comms/GenTestFormat.java @@ -28,24 +28,24 @@ public class GenTestFormat { @Property public void messageRoundTrip(String str) throws BadFormatException { AString s=Strings.create(str); - Blob b = Format.encodedBlob(s); + Blob b = Cells.encode(s); AString s2 = Format.read(b); assertEquals(s, s2); - assertEquals(b, Format.encodedBlob(s2)); + assertEquals(b, Cells.encode(s2)); FuzzTestFormat.doMutationTest(b); } @Property public void primitiveRoundTrip(@From(PrimitiveGen.class) ACell prim) throws BadFormatException, IOException { - Blob b = Format.encodedBlob(prim); + Blob b = Cells.encode(prim); if (!Cells.isEmbedded(prim)) { // persist in case large Cells.persist(prim); } ACell o = Format.read(b); assertEquals(prim, o); - assertEquals(b, Format.encodedBlob(o)); + assertEquals(b, Cells.encode(o)); FuzzTestFormat.doMutationTest(b); } @@ -53,12 +53,12 @@ public void primitiveRoundTrip(@From(PrimitiveGen.class) ACell prim) throws BadF @Property public void dataRoundTrip(@From(ValueGen.class) ACell value) throws BadFormatException, IOException { Ref pref = Ref.get(Cells.persist(value)); // ensure persisted - Blob b = Format.encodedBlob(value); + Blob b = Cells.encode(value); ACell o = Format.read(b); assertEquals(RT.getType(value), RT.getType(o)); assertEquals(value, o); - assertEquals(b, Format.encodedBlob(o)); + assertEquals(b, Cells.encode(o)); assertEquals(pref.getValue(), o); FuzzTestFormat.doMutationTest(b); diff --git a/convex-core/src/test/java/convex/comms/VLCParamTest.java b/convex-core/src/test/java/convex/comms/VLCParamTest.java index ef1963e6b..8d4fcb536 100644 --- a/convex-core/src/test/java/convex/comms/VLCParamTest.java +++ b/convex-core/src/test/java/convex/comms/VLCParamTest.java @@ -11,6 +11,7 @@ import convex.core.data.ACell; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.FuzzTestFormat; import convex.core.data.prim.CVMLong; @@ -39,7 +40,7 @@ public static Collection dataExamples() { @Test public void testRoundTrip() throws BadFormatException { - Blob b = Format.encodedBlob(value); + Blob b = Cells.encode(value); ACell v2 = Format.read(b); assertEquals(value, v2); diff --git a/convex-core/src/test/java/convex/core/StateTest.java b/convex-core/src/test/java/convex/core/StateTest.java index 38efb3f48..54cb8e300 100644 --- a/convex-core/src/test/java/convex/core/StateTest.java +++ b/convex-core/src/test/java/convex/core/StateTest.java @@ -70,7 +70,7 @@ public void testRoundTrip() throws BadFormatException, IOException { // TODO: consider if cached ref in state should now have persisted status? // assertTrue(s.getRef().isPersisted()); - Blob b = Format.encodedBlob(s); + Blob b = Cells.encode(s); State s2 = Format.read(b); assertEquals(s, s2); diff --git a/convex-core/src/test/java/convex/core/data/BlobsTest.java b/convex-core/src/test/java/convex/core/data/BlobsTest.java index 521a74347..b24dcd05f 100644 --- a/convex-core/src/test/java/convex/core/data/BlobsTest.java +++ b/convex-core/src/test/java/convex/core/data/BlobsTest.java @@ -305,7 +305,7 @@ public void testEmptyBlob() throws BadFormatException { assertSame(e,e.append(e)); assertSame(e,new BlobBuilder().toBlob()); - assertSame(e,Format.read(Format.encodedBlob(e))); + assertSame(e,Format.read(Cells.encode(e))); assertSame(e,Format.read(e.getEncoding())); assertSame(e,e.getChunk(0)); @@ -592,7 +592,7 @@ public void testLongBlobBroken() throws BadFormatException, IOException { assertEquals(RT.getType(value), RT.getType(o)); assertEquals(value, o); - assertEquals(b, Format.encodedBlob(o)); + assertEquals(b, Cells.encode(o)); assertEquals(pref.getValue(), o); } diff --git a/convex-core/src/test/java/convex/core/data/EncodingSizeTest.java b/convex-core/src/test/java/convex/core/data/EncodingSizeTest.java index 017a69600..a0807f8e6 100644 --- a/convex-core/src/test/java/convex/core/data/EncodingSizeTest.java +++ b/convex-core/src/test/java/convex/core/data/EncodingSizeTest.java @@ -17,7 +17,7 @@ */ public class EncodingSizeTest { public static int size(ACell a) { - return Utils.checkedInt(Format.encodedBlob(a).count()); + return Utils.checkedInt(Cells.encode(a).count()); } @Test public void testLong() { diff --git a/convex-core/src/test/java/convex/core/data/EncodingTest.java b/convex-core/src/test/java/convex/core/data/EncodingTest.java index 5de021911..b174f938c 100644 --- a/convex-core/src/test/java/convex/core/data/EncodingTest.java +++ b/convex-core/src/test/java/convex/core/data/EncodingTest.java @@ -116,7 +116,7 @@ private void doVLQLongTest(long x) throws BadFormatException { @Test public void testEmbeddedRegression() throws BadFormatException { Keyword k=Keyword.create("foo"); - Blob b=Format.encodedBlob(k); + Blob b=Cells.encode(k); ACell o=Format.read(b); assertEquals(k,o); assertTrue(Cells.isEmbedded(k)); @@ -154,7 +154,7 @@ private void doVLQLongTest(long x) throws BadFormatException { @Test public void testStringRegression() throws BadFormatException { StringShort s=StringShort.create("��zI�&$\\ž1�����4�E4�a8�#?$wD(�#"); - Blob b=Format.encodedBlob(s); + Blob b=Cells.encode(s); StringShort s2=Format.read(b); assertEquals(s,s2); } @@ -164,7 +164,7 @@ private void doVLQLongTest(long x) throws BadFormatException { List l=List.reverse(me); assertEquals(me,l.reverse()); // ensure MapEntry gets converted to canonical vector - Blob b=Format.encodedBlob(l); + Blob b=Cells.encode(l); List l2=Format.read(b); assertEquals(l,l2); @@ -187,7 +187,7 @@ private void doVLQLongTest(long x) throws BadFormatException { @Test public void testReadBlobData() throws BadFormatException { Blob d=Blob.fromHex("cafebabe"); - Blob edData=Format.encodedBlob(d); + Blob edData=Cells.encode(d); AArrayBlob dd=Format.read(edData); assertEquals(d,dd); assertSame(edData,dd.getEncoding()); // should re-use encoded data object directly @@ -196,7 +196,7 @@ private void doVLQLongTest(long x) throws BadFormatException { @Test public void testBadMessageTooLong() throws BadFormatException { ACell o=Samples.FOO; - Blob data=Format.encodedBlob(o).append(Blob.fromHex("ff")).toFlatBlob(); + Blob data=Cells.encode(o).append(Blob.fromHex("ff")).toFlatBlob(); assertThrows(BadFormatException.class,()->Format.read(data)); } diff --git a/convex-core/src/test/java/convex/core/data/FormatTest.java b/convex-core/src/test/java/convex/core/data/FormatTest.java index 4714ac5e7..e30a60b6f 100644 --- a/convex-core/src/test/java/convex/core/data/FormatTest.java +++ b/convex-core/src/test/java/convex/core/data/FormatTest.java @@ -118,6 +118,12 @@ private void checkVLQLong(String hex, long a) { } } + @Test public void testRead() { + assertThrows(BadFormatException.class,()->Format.read("")); + assertThrows(BadFormatException.class,()->Format.read("0")); + assertThrows(BadFormatException.class,()->Format.read("FF")); + } + private void checkVLQCount(String hex, long a) { int blen=hex.length()/2; byte[] bs=new byte[blen]; diff --git a/convex-core/src/test/java/convex/core/data/FuzzTestFormat.java b/convex-core/src/test/java/convex/core/data/FuzzTestFormat.java index 97d4e4c5f..3ee8a22d5 100644 --- a/convex-core/src/test/java/convex/core/data/FuzzTestFormat.java +++ b/convex-core/src/test/java/convex/core/data/FuzzTestFormat.java @@ -55,7 +55,7 @@ public void fuzzExamples() { public static void doCellFuzzTests(ACell c) { for (int i = 0; i < 1000; i++) { - Blob b=Format.encodedBlob(c); + Blob b=Cells.encode(c); try { doFuzzTest(b); } catch (Exception e) { @@ -85,7 +85,7 @@ private static void doFuzzTest(Blob b) throws BadFormatException { // format! assertTrue(Cells.isCanonical(v),()->"Not canonical: "+Utils.getClassName(v)); - Blob b2 = Format.encodedBlob(v); + Blob b2 = Cells.encode(v); assertEquals(v, Format.read(b2), () -> "Expected to be able to regenerate value: " + v + " of type " + Utils.getClass(v)); diff --git a/convex-core/src/test/java/convex/core/data/GenTestAnyValue.java b/convex-core/src/test/java/convex/core/data/GenTestAnyValue.java index 758529796..6eaaabc43 100644 --- a/convex-core/src/test/java/convex/core/data/GenTestAnyValue.java +++ b/convex-core/src/test/java/convex/core/data/GenTestAnyValue.java @@ -57,7 +57,7 @@ public void testUpdateRefs(@From(ValueGen.class) ACell o) { @Property public void testFuzzing(@From(ValueGen.class) ACell o) throws InvalidDataException { - Blob b=Format.encodedBlob(o); + Blob b=Cells.encode(o); FuzzTestFormat.doMutationTest(b); if (o instanceof ACell) { @@ -77,12 +77,12 @@ public void validEmbedded(@From(ValueGen.class) ACell o) throws InvalidDataExcep if (Cells.isEmbedded(o)) { Cells.persist(o); // NOTE: may have child refs to persist - Blob data=Format.encodedBlob(o); + Blob data=Cells.encode(o); ACell o2=Format.read(data); // check round trip properties assertEquals(o,o2); - AArrayBlob data2=Format.encodedBlob(o2); + AArrayBlob data2=Cells.encode(o2); assertEquals(data,data2); assertTrue(Cells.isEmbedded(o2)); @@ -100,7 +100,7 @@ public void validEmbedded(@From(ValueGen.class) ACell o) throws InvalidDataExcep @Property (trials=20) public void dataRoundTrip(@From(ValueGen.class) ACell o) throws BadFormatException, IOException { - Blob data=Format.encodedBlob(o); + Blob data=Cells.encode(o); // introduce a small offset to ensure blobs working correctly data=Samples.ONE_ZERO_BYTE_DATA.append(data).slice(1).toFlatBlob(); @@ -121,7 +121,7 @@ public void dataRoundTrip(@From(ValueGen.class) ACell o) throws BadFormatExcepti assertEquals(hash,Hash.get(o2)); // re-encoding - AArrayBlob data2=Format.encodedBlob(o2); + AArrayBlob data2=Cells.encode(o2); assertEquals(data,data2); // simulate retrieval via hash diff --git a/convex-core/src/test/java/convex/core/data/ObjectsTest.java b/convex-core/src/test/java/convex/core/data/ObjectsTest.java index 29ccd8250..5c7611c28 100644 --- a/convex-core/src/test/java/convex/core/data/ObjectsTest.java +++ b/convex-core/src/test/java/convex/core/data/ObjectsTest.java @@ -228,7 +228,7 @@ private static void doCellEncodingTest(ACell a) { * @param a Any Cell, might not be CVM value */ private static void doAnyEncodingTests(ACell a) { - Blob encoding = Format.encodedBlob(a); + Blob encoding = Cells.encode(a); if (a==null) { assertSame(Blob.NULL_ENCODING,encoding); return; diff --git a/convex-core/src/test/java/convex/core/data/ParamTestValues.java b/convex-core/src/test/java/convex/core/data/ParamTestValues.java index 99f9c49d9..49bd14662 100644 --- a/convex-core/src/test/java/convex/core/data/ParamTestValues.java +++ b/convex-core/src/test/java/convex/core/data/ParamTestValues.java @@ -119,7 +119,7 @@ public void testType() { @Test public void testHexRoundTrip() throws InvalidDataException, ValidationException, IOException { Cells.persist(data); - String hex = Format.encodedBlob(data).toHexString(); + String hex = Cells.encode(data).toHexString(); Blob d2 = Blob.fromHex(hex); ACell rec = Format.read(d2); diff --git a/convex-core/src/test/java/convex/core/data/SetsTest.java b/convex-core/src/test/java/convex/core/data/SetsTest.java index 3582222bf..5074e6b0a 100644 --- a/convex-core/src/test/java/convex/core/data/SetsTest.java +++ b/convex-core/src/test/java/convex/core/data/SetsTest.java @@ -121,10 +121,10 @@ public void testMerging() { @Test public void regressionRead() throws BadFormatException { ASet v1=Sets.of(43); - Blob b1 = Format.encodedBlob(v1); + Blob b1 = Cells.encode(v1); ASet v2=Format.read(b1); - Blob b2 = Format.encodedBlob(v2); + Blob b2 = Cells.encode(v2); assertEquals(v1, v2); assertEquals(b1,b2); diff --git a/convex-core/src/test/java/convex/core/data/VLCEncodingTest.java b/convex-core/src/test/java/convex/core/data/VLCEncodingTest.java index 57b3175e8..14f85ad8c 100644 --- a/convex-core/src/test/java/convex/core/data/VLCEncodingTest.java +++ b/convex-core/src/test/java/convex/core/data/VLCEncodingTest.java @@ -134,14 +134,14 @@ public void testVLCSignExtend() { @Test public void testLongVLCRegression2() throws BadFormatException { CVMLong b = CVMLong.create(1496216L); - Blob blob = Format.encodedBlob(b); + Blob blob = Cells.encode(b); assertEquals(b, Format.read(blob)); } @Test public void testLongVLCRegression() throws BadFormatException { CVMLong b = RT.cvm(1234578); - Blob blob = Format.encodedBlob(b); + Blob blob = Cells.encode(b); assertEquals(b, Format.read(blob)); } } diff --git a/convex-core/src/test/java/convex/core/data/prim/BigIntegerTest.java b/convex-core/src/test/java/convex/core/data/prim/BigIntegerTest.java index 18065bc7d..18cbda92d 100644 --- a/convex-core/src/test/java/convex/core/data/prim/BigIntegerTest.java +++ b/convex-core/src/test/java/convex/core/data/prim/BigIntegerTest.java @@ -61,7 +61,7 @@ public class BigIntegerTest { assertEquals(BigInteger.ZERO,bi.getBigInteger()); assertFalse(bi.isCanonical()); - Blob enc=Format.encodedBlob(bi); + Blob enc=Cells.encode(bi); assertEquals(bi,Format.read(enc)); assertNotEquals(enc,Blobs.empty().getEncoding()); @@ -105,7 +105,7 @@ public class BigIntegerTest { CVMBigInteger cb=CVMBigInteger.wrap(b1); Blob bb=cb.getEncoding(); assertNotEquals(b,bb); - assertNotEquals(b,Format.encodedBlob(cb)); + assertNotEquals(b,Cells.encode(cb)); ObjectsTest.doAnyValueTests(cb); } diff --git a/convex-core/src/test/java/convex/core/lang/CoreTest.java b/convex-core/src/test/java/convex/core/lang/CoreTest.java index 85d428c33..c2f89a4c0 100644 --- a/convex-core/src/test/java/convex/core/lang/CoreTest.java +++ b/convex-core/src/test/java/convex/core/lang/CoreTest.java @@ -68,6 +68,7 @@ import convex.core.data.Address; import convex.core.data.Blob; import convex.core.data.Blobs; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.Hash; import convex.core.data.Index; @@ -3988,7 +3989,7 @@ public void testCoreDefSymbols() throws BadFormatException { ACell v=Core.ENVIRONMENT.get(sym); assertSame(def, v); - Blob b = Format.encodedBlob(def); + Blob b = Cells.encode(def); assertSame(def, Format.read(b)); AHashMap meta= Core.METADATA.get(sym); @@ -5229,19 +5230,19 @@ public void testSymbolFor() { public void testCoreFormatRoundTrip() throws BadFormatException { { // a core function ACell c = eval("count"); - Blob b = Format.encodedBlob(c); + Blob b = Cells.encode(c); assertSame(c, Format.read(b)); } { // a core macro ACell c = eval("*initial-expander*"); - Blob b = Format.encodedBlob(c); + Blob b = Cells.encode(c); assertSame(c, Format.read(b)); } { // a basic lambda expression ACell c = eval("(fn [x] x)"); - Blob b = Format.encodedBlob(c); + Blob b = Cells.encode(c); assertEquals(c, Format.read(b)); } } diff --git a/convex-core/src/test/java/convex/core/lang/ParamTestEvals.java b/convex-core/src/test/java/convex/core/lang/ParamTestEvals.java index a704c8c7c..b3074f415 100644 --- a/convex-core/src/test/java/convex/core/lang/ParamTestEvals.java +++ b/convex-core/src/test/java/convex/core/lang/ParamTestEvals.java @@ -106,11 +106,11 @@ public Context eval(String source) { @Test public void testOpRoundTrip() throws BadFormatException, IOException { AOp op = compile(source); - Blob b = Format.encodedBlob(op); + Blob b = Cells.encode(op); Cells.persist(op); // persist to allow re-creation AOp op2 = Format.read(b); - Blob b2 = Format.encodedBlob(op2); + Blob b2 = Cells.encode(op2); assertEquals(b, b2); ACell result = eval(op2).getResult(); diff --git a/convex-core/src/test/java/convex/core/lang/ParamTestJuice.java b/convex-core/src/test/java/convex/core/lang/ParamTestJuice.java index 0fc20ff95..237b09645 100644 --- a/convex-core/src/test/java/convex/core/lang/ParamTestJuice.java +++ b/convex-core/src/test/java/convex/core/lang/ParamTestJuice.java @@ -16,6 +16,7 @@ import convex.core.cvm.State; import convex.core.data.ACell; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.Keyword; import convex.core.data.Lists; @@ -103,9 +104,9 @@ public static Context eval(String source) { @Test public void testOpRoundTrip() throws BadFormatException { AOp op = compile(source); - Blob b = Format.encodedBlob(op); + Blob b = Cells.encode(op); AOp op2 = Format.read(b); - Blob b2 = Format.encodedBlob(op2); + Blob b2 = Cells.encode(op2); assertEquals(b, b2); } diff --git a/convex-core/src/test/java/convex/test/generators/AnyMapGen.java b/convex-core/src/test/java/convex/test/generators/AnyMapGen.java index 6db2ea6ed..166c67d33 100644 --- a/convex-core/src/test/java/convex/test/generators/AnyMapGen.java +++ b/convex-core/src/test/java/convex/test/generators/AnyMapGen.java @@ -8,8 +8,8 @@ import convex.core.data.AMap; import convex.core.data.AString; import convex.core.data.AVector; +import convex.core.data.Cells; import convex.core.data.Index; -import convex.core.data.Format; import convex.core.data.Maps; import convex.test.Samples; @@ -44,7 +44,7 @@ public AMap generate(SourceOfRandomness r, GenerationStatus status) { case 5: return Index.EMPTY; case 6: { - ABlob o1 = Format.encodedBlob(gen().make(PrimitiveGen.class).generate(r, status)); + ABlob o1 = Cells.encode(gen().make(PrimitiveGen.class).generate(r, status)); AString o2 = gen().make(StringGen.class).generate(r, status); return Index.create(o1, o2); } diff --git a/convex-core/src/test/java/convex/test/generators/BlobGen.java b/convex-core/src/test/java/convex/test/generators/BlobGen.java index 020bbe040..ec965edda 100644 --- a/convex-core/src/test/java/convex/test/generators/BlobGen.java +++ b/convex-core/src/test/java/convex/test/generators/BlobGen.java @@ -7,7 +7,7 @@ import convex.core.data.ABlob; import convex.core.data.Blob; import convex.core.data.Blobs; -import convex.core.data.Format; +import convex.core.data.Cells; import convex.core.data.impl.LongBlob; import convex.test.Samples; @@ -39,7 +39,7 @@ public ABlob generate(SourceOfRandomness r, GenerationStatus status) { case 5: return Samples.NON_EMBEDDED_BLOB; case 6: - return Format.encodedBlob(Gen.PRIMITIVE.generate(r, status)); + return Cells.encode(Gen.PRIMITIVE.generate(r, status)); case 7: { // use a slice from a big blob long length=Math.min(len, Samples.BIG_BLOB_LENGTH); diff --git a/convex-peer/src/main/java/convex/net/Connection.java b/convex-peer/src/main/java/convex/net/Connection.java index 340aeaa05..bcd32fa71 100644 --- a/convex-peer/src/main/java/convex/net/Connection.java +++ b/convex-peer/src/main/java/convex/net/Connection.java @@ -29,6 +29,7 @@ import convex.core.data.AVector; import convex.core.data.Address; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.Hash; import convex.core.data.IRefFunction; @@ -406,7 +407,7 @@ private boolean sendObject(MessageType type, ACell payload) throws IOException { Blob enc = Format.encodeMultiCell(payload,true); if (log.isTraceEnabled()) { log.trace("Sending message: " + type + " :: " + payload + " to " + getRemoteAddress() + " format: " - + Format.encodedBlob(payload).toHexString()); + + Cells.encode(payload).toHexString()); } boolean sent = sendBuffer(type, enc); return sent; diff --git a/convex-peer/src/main/java/convex/net/Message.java b/convex-peer/src/main/java/convex/net/Message.java index bea0bb423..5acadee1b 100644 --- a/convex-peer/src/main/java/convex/net/Message.java +++ b/convex-peer/src/main/java/convex/net/Message.java @@ -15,6 +15,7 @@ import convex.core.data.AVector; import convex.core.data.Address; import convex.core.data.Blob; +import convex.core.data.Cells; import convex.core.data.Format; import convex.core.data.Hash; import convex.core.data.Ref; @@ -168,7 +169,7 @@ public Blob getMessageData() { break; default: - messageData=Format.encodedBlob(payload); + messageData=Cells.encode(payload); } return messageData;