/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter UniSharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

const Utils = require("./../../../unisharp/Utils");

class ReadUtils {
    
    static readByte(s) {
        let b = s.readByte();
        if (b < 0) 
            throw new Error("Unexpected EOF");
        return b;
    }
    
    static readByteRef(s, read) {
        let b = ReadUtils.readByte(s);
        ++read.value;
        return b;
    }
    
    static readInt(s) {
        let res = 0;
        let i = s.read(ReadUtils.buf, 0, 4);
        if (i < 0) 
            return -1;
        if (i < 4) 
            return 0;
        for (i = 3; i >= 0; i--) {
            res = (res << 8) | (ReadUtils.buf[i]);
        }
        return res;
    }
    
    static readShort(s) {
        let res = 0;
        let i = s.read(ReadUtils.buf, 0, 2);
        if (i < 2) 
            return 0;
        for (i = 1; i >= 0; i--) {
            res = (((res) << 8) | (ReadUtils.buf[i]));
        }
        return res;
    }
    
    static readExact(s, count) {
        let data = new Uint8Array(count);
        let read = s.read(data, 0, count);
        if (read !== count) 
            throw new Error("Unexpected EOF");
        return data;
    }
    
    static readExactRef(s, count, read) {
        let data = ReadUtils.readExact(s, count);
        read.value += data.length;
        return data;
    }
    
    static skip(s, count) {
        s.seek(count, 1);
    }
    
    static static_constructor() {
        ReadUtils.byteSize = 1;
        ReadUtils.wordSize = 2;
        ReadUtils.dWordSize = 4;
        ReadUtils.buf = new Uint8Array(32);
    }
}


ReadUtils.static_constructor();

module.exports = ReadUtils