github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/compress/raw/raw.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package raw
     4  
     5  import (
     6  	compress ".."
     7  	"../../mediatype"
     8  	"../../protocol"
     9  )
    10  
    11  const (
    12  	RawContentEncoding = "raw"
    13  	RawExtension       = ""
    14  )
    15  
    16  var RAW = raw{
    17  	CompressType: compress.New(RawContentEncoding, mediatype.New("domain/raw.protocol.data-structure").SetFileExtension(RawExtension)),
    18  }
    19  
    20  type raw struct {
    21  	*compress.CompressType
    22  }
    23  
    24  func (r *raw) Compress(raw protocol.Codec, options protocol.CompressOptions) (compressed protocol.Codec, err protocol.Error) {
    25  	return raw, nil
    26  }
    27  func (r *raw) CompressBySlice(raw []byte, options protocol.CompressOptions) (compressed protocol.Codec, err protocol.Error) {
    28  	compressed = &comDecom{
    29  		data: raw,
    30  	}
    31  	return
    32  }
    33  func (r *raw) CompressByReader(raw protocol.Reader, options protocol.CompressOptions) (compressed protocol.Codec, err protocol.Error) {
    34  	// TODO:::
    35  	return
    36  }
    37  
    38  func (r *raw) Decompress(compressed protocol.Codec) (raw protocol.Codec, err protocol.Error) {
    39  	return compressed, nil
    40  }
    41  func (r *raw) DecompressFromSlice(compressed []byte) (raw protocol.Codec, err protocol.Error) {
    42  	raw = &comDecom{
    43  		data: compressed,
    44  	}
    45  	return
    46  }
    47  func (r *raw) DecompressFromReader(compressed protocol.Reader, compressedLen int) (raw protocol.Codec, err protocol.Error) {
    48  	var rawDecoder = comDecom{
    49  		reader:  compressed,
    50  		readLen: compressedLen,
    51  	}
    52  	rawDecoder.Decode(compressed)
    53  	raw = &rawDecoder
    54  	return
    55  }