github.com/wfusion/gofusion@v1.1.14/internal/util/payload/types.go (about)

     1  package pd
     2  
     3  import (
     4  	"context"
     5  	"reflect"
     6  
     7  	"github.com/wfusion/gofusion/common/utils"
     8  	"github.com/wfusion/gofusion/common/utils/compress"
     9  	"github.com/wfusion/gofusion/common/utils/serialize"
    10  )
    11  
    12  var (
    13  	// sealMagicNumber FF FF FF FB: magic number
    14  	sealMagicNumber uint32 = 0xFFFFFFFB
    15  	// sealTypeNumber 01 00 00 00: version, serialize type, compress type, raw flag, encrypted info length
    16  	sealTypeNumber   = [8]byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
    17  	sealPrefixLength = 4 + len(sealTypeNumber)
    18  )
    19  
    20  type option struct {
    21  	ctx           context.Context
    22  	serializeType serialize.Algorithm
    23  	compressType  compress.Algorithm
    24  	dataType      reflect.Type
    25  	version       byte
    26  }
    27  
    28  func Context(ctx context.Context) utils.OptionFunc[option] {
    29  	return func(o *option) {
    30  		o.ctx = ctx
    31  	}
    32  }
    33  
    34  func Serialize(serializeType serialize.Algorithm) utils.OptionFunc[option] {
    35  	return func(o *option) {
    36  		o.serializeType = serializeType
    37  	}
    38  }
    39  
    40  func Compress(compressType compress.Algorithm) utils.OptionFunc[option] {
    41  	return func(o *option) {
    42  		o.compressType = compressType
    43  	}
    44  }
    45  
    46  func Type(typ reflect.Type) utils.OptionFunc[option] {
    47  	return func(o *option) {
    48  		o.dataType = typ
    49  	}
    50  }
    51  
    52  func Version(ver uint8) utils.OptionFunc[option] {
    53  	return func(o *option) {
    54  		o.version = ver
    55  	}
    56  }