2023-05-26 09:49:04 +00:00
|
|
|
package rw ;import (_c "bytes";_eb "encoding/binary";_f "errors";_b "fmt";_g "io";_a "io/ioutil";_ff "reflect";);func (_ebd *Reader )ReadPairProperty (p interface{})error {if _d :=_ebd .align (4);_d !=nil {return _d ;};_af :=_ff .ValueOf (p );for _af .Kind ()==_ff .Ptr {_af =_af .Elem ();};if !_af .IsValid (){return _b .Errorf ("\u0076a\u006cu\u0065\u0020\u0069\u0073\u0020n\u006f\u0074 \u0076\u0061\u006c\u0069\u0064");};if _gc :=_eb .Read (_ebd ,_eb .LittleEndian ,p );_gc !=nil {return _gc ;};return nil ;};type Reader struct{*_c .Reader };const _cee =64;func NewWriter ()*Writer {return &Writer {_aad :[]byte {}}};func PopRightUI32 (v uint32 )(bool ,uint32 ){return (v &uint32 (1))==1,v >>1};func (_df *Writer )Len ()int {return len (_df ._aad )-_df ._fdf };func (_bga *Writer )WriteTo (wTo _g .Writer )(_ebf int64 ,_ec error ){if _efc :=_bga .Len ();_efc > 0{_aac ,_dd :=wTo .Write (_bga ._aad [_bga ._fdf :]);if _aac > _efc {return 0,_f .New ("\u0072\u0077\u002e\u0057\u0072\u0069\u0074\u0065\u0072\u002e\u0057\u0072\u0069\u0074\u0065\u0054\u006f\u003a\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0057\u0072\u0069t\u0065\u0020c\u006f\u0075\u006e\u0074");};_bga ._fdf +=_aac ;_ebf =int64 (_aac );if _dd !=nil {return _ebf ,_dd ;};if _aac !=_efc {return _ebf ,_g .ErrShortWrite ;};};_bga .reset ();return _ebf ,nil ;};func (_be *Reader )curPos ()int {return int (_be .Size ())-_be .Len ()};func (_cad *Writer )Write (p []byte )(_de int ,_bd error ){_baa ,_cec :=_cad .tryGrowByReslice (len (p ));if !_cec {var _dg error ;_baa ,_dg =_cad .grow (len (p ));if _dg !=nil {return 0,_dg ;};};return copy (_cad ._aad [_baa :],p ),nil ;};type Writer struct{_aad []byte ;_fdf int ;};func (_bg *Writer )Skip (n int )error {if n ==0{return nil ;};_ ,_ffc :=_bg .Write (make ([]byte ,n ));return _ffc ;};func (_cf *Writer )WriteProperty (a interface{})error {if _bfd :=_cf .align (int (_ff .TypeOf (a ).Size ()));_bfd !=nil {return _bfd ;};return _cf .WritePropertyNoAlign (a );};func (_ef *Writer )Cap ()int {return cap (_ef ._aad )};func (_geb *Writer )curPos ()int {return int (_geb .Cap ())-_geb .Len ()};func (_ce *Writer )AlignLength (alignTo int )error {_bee :=_ce .Len ()%alignTo ;if _bee > 0{_ ,_gb :=_ce .Write (make ([]byte ,alignTo -_bee ));if _gb !=nil {return _gb ;};};return nil ;};func (_aa *Reader )ReadProperty (a interface{})error {_ga :=_ff .ValueOf (a );for _ga .Kind ()==_ff .Ptr {_ga =_ga .Elem ();};if !_ga .IsValid (){return _b .Errorf ("\u0076a\u006cu\u0065\u0020\u0069\u0073\u0020n\u006f\u0074 \u0076\u0061\u006c\u0069\u0064");};if _ag :=_aa .align (int (_ga .Type ().Size ()));_ag !=nil {return _ag ;};if _bc :=_eb .Read (_aa ,_eb .LittleEndian ,a );_bc !=nil {return _bc ;};return nil ;};func PushLeftUI64 (v uint64 ,flag bool )uint64 {v >>=1;if flag {v |=1<<63;};return v ;};func (_ca *Reader )skip (_fd int )error {_ ,_bf :=_g .CopyN (_a .Discard ,_ca ,int64 (_fd ));if _bf !=nil {return _bf ;};return nil ;};func (_cgg *Writer )tryGrowByReslice (_gg int )(int ,bool ){if _egb :=len (_cgg ._aad );_gg <=cap (_cgg ._aad )-_egb {_cgg ._aad =_cgg ._aad [:_egb +_gg ];return _egb ,true ;};return 0,false ;};const _cfd =int (^uint (0)>>1);func (_ffcd *Writer )align (_edg int )error {return _ffcd .Skip ((_edg -(_ffcd .Len ())%_edg )%_edg )};func (_db *Writer )reset (){_db ._aad =_db ._aad [:0];_db ._fdf =0};var _gbe =_f .New ("r\u0077.\u0057\u0072\u0069\u0074\u0065\u0072\u003a\u0020t\u006f\u006f\u0020\u006car\u0067\u0065");func PushLeftUI32 (v uint32 ,flag bool )uint32 {v >>=1;if flag {v |=1<<31;};return v ;};func _fb (_ea int )[]byte {defer func (){if recover ()!=nil {panic (_gbe );};}();return make ([]byte ,_ea );};func (_caa *Writer )WriteStringProperty (s string )error {_caa .align (4);_edb :=[]byte (s );if _fe :=_eb .Write (_caa ,_eb .LittleEndian ,&_edb );_fe !=nil {return _fe ;};return nil ;};func (_efce *Writer )FillWithByte (fillSize int ,b byte )error {for _cd :=0;_cd < fillSize ;_cd ++{if _cff :=_efce .WritePropertyNoAlign (b );_cff !=nil {return _cff ;};};return nil ;};func NewReader (b []byte )(*Reader ,error ){return &Reader {_c .NewReade
|