github.com/datastax/go-cassandra-native-protocol@v0.0.0-20220706104457-5e8aad05cf90/client/compression.go (about)

     1  // Copyright 2021 DataStax
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package client
    16  
    17  import (
    18  	"github.com/datastax/go-cassandra-native-protocol/compression/lz4"
    19  	"github.com/datastax/go-cassandra-native-protocol/compression/snappy"
    20  	"github.com/datastax/go-cassandra-native-protocol/frame"
    21  	"github.com/datastax/go-cassandra-native-protocol/primitive"
    22  	"github.com/datastax/go-cassandra-native-protocol/segment"
    23  )
    24  
    25  func NewBodyCompressor(c primitive.Compression) frame.BodyCompressor {
    26  	switch c {
    27  	case primitive.CompressionNone:
    28  		return nil
    29  	case primitive.CompressionLz4:
    30  		return &lz4.Compressor{}
    31  	case primitive.CompressionSnappy:
    32  		return &snappy.Compressor{}
    33  	default:
    34  		return nil
    35  	}
    36  }
    37  
    38  func NewPayloadCompressor(c primitive.Compression) segment.PayloadCompressor {
    39  	switch c {
    40  	case primitive.CompressionNone:
    41  		return nil
    42  	case primitive.CompressionLz4:
    43  		return &lz4.Compressor{}
    44  	case primitive.CompressionSnappy:
    45  		// Snappy not supported for payload compression
    46  		return nil
    47  	default:
    48  		return nil
    49  	}
    50  }