File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -291,6 +291,18 @@ exports.newOp = (optOpcode) => {
291291 */
292292const copyOp = ( op1 , op2 = new Op ( ) ) => Object . assign ( op2 , op1 ) ;
293293
294+ /**
295+ * Converts an iterable of operation objects to wire format.
296+ *
297+ * @param {Iterable<Op> } ops - Iterable of operations to serialize.
298+ * @returns {string } A string containing the encoded op data (example: '|5=2p=v*4*5+1').
299+ */
300+ const serializeOps = ( ops ) => {
301+ let res = '' ;
302+ for ( const op of ops ) res += op . toString ( ) ;
303+ return res ;
304+ } ;
305+
294306/**
295307 * Serializes a sequence of Ops.
296308 */
@@ -300,19 +312,19 @@ class OpAssembler {
300312 }
301313
302314 clear ( ) {
303- this . _serialized = '' ;
315+ this . _ops = [ ] ;
304316 }
305317
306318 /**
307319 * @param {Op } op - Operation to add. Ownership remains with the caller.
308320 */
309321 append ( op ) {
310322 assert ( op instanceof Op , 'argument must be an instance of Op' ) ;
311- this . _serialized += op . toString ( ) ;
323+ this . _ops . push ( copyOp ( op ) ) ;
312324 }
313325
314326 toString ( ) {
315- return this . _serialized ;
327+ return serializeOps ( this . _ops ) ;
316328 }
317329}
318330
You can’t perform that action at this time.
0 commit comments