github.com/cloudwego/kitex@v0.9.0/pkg/remote/compression.go (about)

     1  /*
     2   * Copyright 2021 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package remote
    18  
    19  import (
    20  	"github.com/cloudwego/kitex/pkg/rpcinfo"
    21  )
    22  
    23  // CompressType tells compression type for a message.
    24  type CompressType int32
    25  
    26  // Compression types.
    27  // Not support now, compression will be supported at later version
    28  const (
    29  	NoCompress CompressType = iota
    30  	GZip
    31  )
    32  
    33  func SetRecvCompressor(ri rpcinfo.RPCInfo, compressorName string) {
    34  	if ri == nil || compressorName == "" {
    35  		return
    36  	}
    37  	if v, ok := ri.Invocation().(rpcinfo.InvocationSetter); ok {
    38  		v.SetExtra("recv-compressor", compressorName)
    39  	}
    40  }
    41  
    42  func SetSendCompressor(ri rpcinfo.RPCInfo, compressorName string) {
    43  	if ri == nil || compressorName == "" {
    44  		return
    45  	}
    46  	if v, ok := ri.Invocation().(rpcinfo.InvocationSetter); ok {
    47  		v.SetExtra("send-compressor", compressorName)
    48  	}
    49  }
    50  
    51  func GetSendCompressor(ri rpcinfo.RPCInfo) string {
    52  	if ri == nil {
    53  		return ""
    54  	}
    55  	v := ri.Invocation().Extra("send-compressor")
    56  	if name, ok := v.(string); ok {
    57  		return name
    58  	}
    59  	return ""
    60  }
    61  
    62  func GetRecvCompressor(ri rpcinfo.RPCInfo) string {
    63  	if ri == nil {
    64  		return ""
    65  	}
    66  	v := ri.Invocation().Extra("recv-compressor")
    67  	if name, ok := v.(string); ok {
    68  		return name
    69  	}
    70  	return ""
    71  }