Skip to content
Snippets Groups Projects
Select Git revision
  • df01fea4be639a3e7a04506786f5813c06aacd8d
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

params.go

Blame
  • params.go 2.71 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                           //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file                                                               //
    ////////////////////////////////////////////////////////////////////////////////
    
    package message
    
    import (
    	"encoding/json"
    	"time"
    )
    
    // Params contains the parameters for the message package.
    type Params struct {
    	MessageReceptionBuffLen        uint
    	MessageReceptionWorkerPoolSize uint
    	MaxChecksInProcessMessage      uint
    	InProcessMessageWait           time.Duration
    	RealtimeOnly                   bool
    }
    
    // paramsDisk will be the marshal-able and umarshal-able object.
    type paramsDisk struct {
    	MessageReceptionBuffLen        uint
    	MessageReceptionWorkerPoolSize uint
    	MaxChecksInProcessMessage      uint
    	InProcessMessageWait           time.Duration
    	RealtimeOnly                   bool
    }
    
    // GetDefaultParams returns a Params object containing the
    // default parameters.
    func GetDefaultParams() Params {
    	return Params{
    		MessageReceptionBuffLen:        500,
    		MessageReceptionWorkerPoolSize: 4,
    		MaxChecksInProcessMessage:      10,
    		InProcessMessageWait:           15 * time.Minute,
    		RealtimeOnly:                   false,
    	}
    }
    
    // GetParameters returns the default Params, or override with given
    // parameters, if set.
    func GetParameters(params string) (Params, error) {
    	p := GetDefaultParams()
    	if len(params) > 0 {
    		err := json.Unmarshal([]byte(params), &p)
    		if err != nil {
    			return Params{}, err
    		}
    	}
    	return p, nil
    }
    
    // MarshalJSON adheres to the json.Marshaler interface.
    func (r Params) MarshalJSON() ([]byte, error) {
    	pDisk := paramsDisk{
    		MessageReceptionBuffLen:        r.MessageReceptionBuffLen,
    		MessageReceptionWorkerPoolSize: r.MessageReceptionWorkerPoolSize,
    		MaxChecksInProcessMessage:      r.MaxChecksInProcessMessage,
    		InProcessMessageWait:           r.InProcessMessageWait,
    		RealtimeOnly:                   r.RealtimeOnly,
    	}
    
    	return json.Marshal(&pDisk)
    
    }
    
    // UnmarshalJSON adheres to the json.Unmarshaler interface.
    func (r *Params) UnmarshalJSON(data []byte) error {
    	pDisk := paramsDisk{}
    	err := json.Unmarshal(data, &pDisk)
    	if err != nil {
    		return err
    	}
    
    	*r = Params{
    		MessageReceptionBuffLen:        pDisk.MessageReceptionBuffLen,
    		MessageReceptionWorkerPoolSize: pDisk.MessageReceptionWorkerPoolSize,
    		MaxChecksInProcessMessage:      pDisk.MaxChecksInProcessMessage,
    		InProcessMessageWait:           pDisk.InProcessMessageWait,
    		RealtimeOnly:                   pDisk.RealtimeOnly,
    	}
    
    	return nil
    }