github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/compress/raw/com-decom.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package raw
     4  
     5  import (
     6  	"io"
     7  
     8  	compress ".."
     9  	"../../protocol"
    10  )
    11  
    12  type comDecom struct {
    13  	data    []byte
    14  	reader  protocol.Reader
    15  	readLen int
    16  }
    17  
    18  /*
    19  ********** protocol.Codec interface **********
    20   */
    21  
    22  func (r *comDecom) MediaType() protocol.MediaType       { return nil }
    23  func (r *comDecom) CompressType() protocol.CompressType { return &RAW }
    24  func (r *comDecom) Len() (ln int)                       { return len(r.data) }
    25  
    26  func (r *comDecom) Decode(reader protocol.Reader) (err protocol.Error) {
    27  	if r.data == nil && r.readLen > 0 {
    28  		r.data = make([]byte, r.readLen)
    29  		io.ReadFull(reader, r.data)
    30  	}
    31  	return
    32  }
    33  func (r *comDecom) Encode(writer protocol.Writer) (err protocol.Error) {
    34  	var _, goErr = r.WriteTo(writer)
    35  	if goErr != nil {
    36  		// err =
    37  	}
    38  	return
    39  }
    40  func (r *comDecom) Marshal() (data []byte)       { return r.data }
    41  func (r *comDecom) MarshalTo(data []byte) []byte { return append(data, r.data...) }
    42  func (r *comDecom) Unmarshal(data []byte) (err protocol.Error) {
    43  	err = compress.ErrSourceNotChangeable
    44  	return
    45  }
    46  func (r *comDecom) UnmarshalFrom(data []byte) (remaining []byte, err protocol.Error) {
    47  	err = compress.ErrSourceNotChangeable
    48  	return
    49  }
    50  
    51  /*
    52  ********** io package interfaces **********
    53   */
    54  
    55  func (r *comDecom) ReadFrom(reader io.Reader) (n int64, err error) {
    56  	err = compress.ErrSourceNotChangeable
    57  	return
    58  }
    59  func (r *comDecom) WriteTo(w io.Writer) (totalWrite int64, err error) {
    60  	var writeLen int
    61  	writeLen, err = w.Write(r.data)
    62  	totalWrite = int64(writeLen)
    63  	return
    64  }