import "stdUtils.scrypt"; library _opcat_labs_scrypt_ts_opcat_4_0_0__rs__ByteStringWriter { bytes buf; constructor() { this.buf = b''; } function writeBytes(bytes buf) : bool { int n = len(buf); bytes header = b''; if(n < 76) { header = _opcat_labs_scrypt_ts_opcat_4_0_0__rs__StdUtils.toLEUnsigned(n, 1); } else if(n < 0x100) { header = b'4c' + _opcat_labs_scrypt_ts_opcat_4_0_0__rs__StdUtils.toLEUnsigned(n, 1); } else if(n < 0x10000) { header = b'4d' + _opcat_labs_scrypt_ts_opcat_4_0_0__rs__StdUtils.toLEUnsigned(n, 2); } else if(n < 0x100000000) { header = b'4e' + _opcat_labs_scrypt_ts_opcat_4_0_0__rs__StdUtils.toLEUnsigned(n, 4); } else { require(false); } this.buf += header + buf; return true; } function writeBool(bool x) : bool { this.buf += x ? b'01' : b'00'; return true; } function writeVarInt(int x) : bool { require(x >= 0); int size = 0; if(x < 0xfd) { size = 1; } else if(x < 0x10000) { this.buf += _opcat_labs_scrypt_ts_opcat_4_0_0__rs__StdUtils.VARINT_2BYTE; size = 2; } else if(x < 0x100000000) { size = 4; this.buf += _opcat_labs_scrypt_ts_opcat_4_0_0__rs__StdUtils.VARINT_4BYTE; } else { size = 8; this.buf += _opcat_labs_scrypt_ts_opcat_4_0_0__rs__StdUtils.VARINT_8BYTE; } this.buf += _opcat_labs_scrypt_ts_opcat_4_0_0__rs__StdUtils.toLEUnsigned(x, size); return true; } }