Skip to content

Commit b7a6371

Browse files
committed
More refactoring for Protonet encodings
1 parent b4263b0 commit b7a6371

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+137
-135
lines changed

convex-benchmarks/src/main/java/convex/benchmarks/HashBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import convex.core.crypto.Hashing;
88
import convex.core.data.AArrayBlob;
99
import convex.core.data.Blob;
10-
import convex.core.data.Format;
10+
import convex.core.data.Cells;
1111
import convex.core.data.prim.CVMLong;
1212

1313
/**
@@ -21,7 +21,7 @@ public class HashBenchmark {
2121
@Benchmark
2222
public void longHash_SHA_256() {
2323
CVMLong l = CVMLong.create(17L);
24-
AArrayBlob d = Format.encodedBlob(l);
24+
AArrayBlob d = Cells.encode(l);
2525
Hashing.sha256(d.getInternalArray());
2626
}
2727

convex-core/src/main/java/convex/core/Result.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import convex.core.data.AVector;
1919
import convex.core.data.Address;
2020
import convex.core.data.Blob;
21-
import convex.core.data.Format;
21+
import convex.core.data.Cells;
2222
import convex.core.data.Keyword;
2323
import convex.core.data.Keywords;
2424
import convex.core.data.Maps;
@@ -302,7 +302,7 @@ public static Result read(Blob b, int pos) throws BadFormatException {
302302
int epos=pos;
303303
// include tag location since we are reading raw Vector (will ignore tag)
304304
AVector<ACell> v=Vectors.read(b,epos);
305-
epos+=Format.getEncodingLength(v);
305+
epos+=Cells.getEncodingLength(v);
306306

307307
// we can't check values yet because might be missing data
308308

convex-core/src/main/java/convex/core/cpos/Belief.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static Belief read(Blob b, int pos) throws BadFormatException {
161161

162162
Index<AccountKey, SignedData<Order>> orders = Format.read(b,epos);
163163
if (orders == null) throw new BadFormatException("Null orders in Belief");
164-
epos+=Format.getEncodingLength(orders);
164+
epos+=Cells.getEncodingLength(orders);
165165

166166
Belief result= new Belief(orders);
167167
result.attachEncoding(b.slice(pos, epos));

convex-core/src/main/java/convex/core/cpos/Block.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static Block read(Blob b, int pos) throws BadFormatException {
158158
epos+=8;
159159

160160
AVector<SignedData<ATransaction>> transactions = Format.read(b,epos);
161-
epos+=Format.getEncodingLength(transactions);
161+
epos+=Cells.getEncodingLength(transactions);
162162

163163
Block result=Block.create(timestamp, transactions);
164164
result.attachEncoding(b.slice(pos, epos));

convex-core/src/main/java/convex/core/cpos/BlockResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ public static BlockResult read(Blob b, int pos) throws BadFormatException {
183183

184184
State newState=Format.read(b,epos);
185185
if (newState==null) throw new BadFormatException("Null state");
186-
epos+=Format.getEncodingLength(newState);
186+
epos+=Cells.getEncodingLength(newState);
187187

188188
AVector<Result> newResults=Format.read(b,epos);
189189
if (newResults==null) throw new BadFormatException("Null results");
190-
epos+=Format.getEncodingLength(newResults);
190+
epos+=Cells.getEncodingLength(newResults);
191191

192192
BlockResult result=create(newState,newResults);
193193
result.attachEncoding(b.slice(pos, epos));

convex-core/src/main/java/convex/core/cvm/PeerStatus.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ public int encodeRaw(byte[] bs, int pos) {
210210
public static PeerStatus read(Blob b, int pos) throws BadFormatException{
211211
int epos=pos+1; // skip tag
212212
Address owner = Format.read(b,epos);
213-
epos+=Format.getEncodingLength(owner);
213+
epos+=Cells.getEncodingLength(owner);
214214

215215
long stake = Format.readVLQLong(b,epos);
216216
epos+=Format.getVLQLongLength(stake);
217217

218218
Index<Address, CVMLong> stakes = Format.read(b,epos);
219-
epos+=Format.getEncodingLength(stakes);
219+
epos+=Cells.getEncodingLength(stakes);
220220
if (stakes==null) {
221221
stakes=EMPTY_STAKES;
222222
} else if (stakes.isEmpty()) {
@@ -227,7 +227,7 @@ public static PeerStatus read(Blob b, int pos) throws BadFormatException{
227227
epos+=Format.getVLQLongLength(delegatedStake);
228228

229229
AHashMap<ACell,ACell> metadata = Format.read(b,epos);
230-
epos+=Format.getEncodingLength(metadata);
230+
epos+=Cells.getEncodingLength(metadata);
231231

232232
long timestamp=Format.readVLQLong(b,epos);
233233
epos+=Format.getVLQLongLength(timestamp);

convex-core/src/main/java/convex/core/cvm/Receipt.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ public static Receipt read(byte tag,Blob b, int pos) throws BadFormatException {
137137
boolean hasLog=((tag&Tag.RECEIPT_LOG_MASK)!=0);
138138

139139
ACell result = Format.read(b,epos);
140-
epos+=Format.getEncodingLength(result);
140+
epos+=Cells.getEncodingLength(result);
141141

142142
AVector<AVector<ACell>> log=null;
143143
if (hasLog) {
144144
log = Vectors.read(b, epos);
145145
if ((log==null)||(log.isEmpty())) throw new BadFormatException("Expected non-empty log");
146-
epos+=Format.getEncodingLength(log);
146+
epos+=Cells.getEncodingLength(log);
147147
}
148148

149149
Receipt receipt=new Receipt(isError,result,log);

convex-core/src/main/java/convex/core/cvm/State.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,19 @@ public static State read(Blob b, int pos) throws BadFormatException {
239239
int epos=pos+1; // skip tag
240240
AVector<AccountStatus> accounts = Format.read(b,epos);
241241
if (accounts==null) throw new BadFormatException("Null accounts!");
242-
epos+=Format.getEncodingLength(accounts);
242+
epos+=Cells.getEncodingLength(accounts);
243243

244244
Index<AccountKey, PeerStatus> peers = Format.read(b,epos);
245245
if (peers==null) throw new BadFormatException("Null peers!");
246-
epos+=Format.getEncodingLength(peers);
246+
epos+=Cells.getEncodingLength(peers);
247247

248248
AVector<ACell> globals = Format.read(b,epos);
249249
if (globals==null) throw new BadFormatException("Null globals!");
250-
epos+=Format.getEncodingLength(globals);
250+
epos+=Cells.getEncodingLength(globals);
251251

252252
Index<ABlob, AVector<ACell>> schedule = Format.read(b,epos);
253253
if (schedule==null) throw new BadFormatException("Null schedule!");
254-
epos+=Format.getEncodingLength(schedule);
254+
epos+=Cells.getEncodingLength(schedule);
255255

256256
State result=create(accounts, peers, globals, schedule);
257257
result.attachEncoding(b.slice(pos,epos));

convex-core/src/main/java/convex/core/cvm/ops/Cond.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import convex.core.data.ASequence;
99
import convex.core.data.AVector;
1010
import convex.core.data.Blob;
11+
import convex.core.data.Cells;
1112
import convex.core.data.Format;
1213
import convex.core.data.IRefFunction;
1314
import convex.core.data.Vectors;
@@ -110,7 +111,7 @@ public static <T extends ACell> Cond<T> read(Blob b, int pos) throws BadFormatEx
110111
int epos=pos+Ops.OP_DATA_OFFSET; // skip tag and opcode to get to data
111112

112113
AVector<AOp<ACell>> ops = Format.read(b,epos);
113-
epos+=Format.getEncodingLength(ops);
114+
epos+=Cells.getEncodingLength(ops);
114115

115116
Cond<T> result=create(ops);
116117
result.attachEncoding(b.slice(pos, epos));

convex-core/src/main/java/convex/core/cvm/ops/Def.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import convex.core.cvm.Ops;
77
import convex.core.data.ACell;
88
import convex.core.data.Blob;
9+
import convex.core.data.Cells;
910
import convex.core.data.Format;
1011
import convex.core.data.IRefFunction;
1112
import convex.core.data.Ref;
@@ -156,7 +157,7 @@ public static <T extends ACell> Def<T> read(Blob b, int pos) throws BadFormatExc
156157
int epos=pos+Ops.OP_DATA_OFFSET; // skip tag and opcode to get to data
157158

158159
ACell symbol = Format.read(b,epos);
159-
epos+=Format.getEncodingLength(symbol);
160+
epos+=Cells.getEncodingLength(symbol);
160161

161162
Ref<AOp<T>> ref = Format.readRef(b,epos);
162163
if (!validKey(symbol)) throw new BadFormatException("Symbol not valid for Def op");

0 commit comments

Comments
 (0)