import protobuf.type.scalar

namespace protobuf.type;
 
class signedInt{ 

	ctor(...) {
		this = ..protobuf.type.scalar(...)
		this.wired_type = ..protobuf.message.WIRED_VARINT;
	}
	 
	deSerialize = function () {
		call( ..protobuf.type.scalar,this );

		var saved = this.value;
		this.value = ..math.floor( this.value / 2 );
		
		if ( saved % 2 == 1)
			this.value = - this.value ; 
	}

 
	serialize = function ( rec = -1 ) { 
		var str = '';

		if ( rec > -1) {
			str ++= this._codecBase128.set_value( rec << 3 | this.wired_type );
		}

		var value = this._codecBase128.set_value( this.value );
		str ++= value;

		return  str;
	}
}
