github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/cluster/codecs/ConsensusModule.go (about)

     1  // Generated SBE (Simple Binary Encoding) message codec
     2  
     3  package codecs
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  	"io/ioutil"
     9  	"math"
    10  )
    11  
    12  type ConsensusModule struct {
    13  	NextSessionId          int64
    14  	NextServiceSessionId   int64
    15  	LogServiceSessionId    int64
    16  	PendingMessageCapacity int32
    17  }
    18  
    19  func (c *ConsensusModule) Encode(_m *SbeGoMarshaller, _w io.Writer, doRangeCheck bool) error {
    20  	if doRangeCheck {
    21  		if err := c.RangeCheck(c.SbeSchemaVersion(), c.SbeSchemaVersion()); err != nil {
    22  			return err
    23  		}
    24  	}
    25  	if err := _m.WriteInt64(_w, c.NextSessionId); err != nil {
    26  		return err
    27  	}
    28  	if err := _m.WriteInt64(_w, c.NextServiceSessionId); err != nil {
    29  		return err
    30  	}
    31  	if err := _m.WriteInt64(_w, c.LogServiceSessionId); err != nil {
    32  		return err
    33  	}
    34  	if err := _m.WriteInt32(_w, c.PendingMessageCapacity); err != nil {
    35  		return err
    36  	}
    37  	return nil
    38  }
    39  
    40  func (c *ConsensusModule) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16, blockLength uint16, doRangeCheck bool) error {
    41  	if !c.NextSessionIdInActingVersion(actingVersion) {
    42  		c.NextSessionId = c.NextSessionIdNullValue()
    43  	} else {
    44  		if err := _m.ReadInt64(_r, &c.NextSessionId); err != nil {
    45  			return err
    46  		}
    47  	}
    48  	if !c.NextServiceSessionIdInActingVersion(actingVersion) {
    49  		c.NextServiceSessionId = c.NextServiceSessionIdNullValue()
    50  	} else {
    51  		if err := _m.ReadInt64(_r, &c.NextServiceSessionId); err != nil {
    52  			return err
    53  		}
    54  	}
    55  	if !c.LogServiceSessionIdInActingVersion(actingVersion) {
    56  		c.LogServiceSessionId = c.LogServiceSessionIdNullValue()
    57  	} else {
    58  		if err := _m.ReadInt64(_r, &c.LogServiceSessionId); err != nil {
    59  			return err
    60  		}
    61  	}
    62  	if !c.PendingMessageCapacityInActingVersion(actingVersion) {
    63  		c.PendingMessageCapacity = c.PendingMessageCapacityNullValue()
    64  	} else {
    65  		if err := _m.ReadInt32(_r, &c.PendingMessageCapacity); err != nil {
    66  			return err
    67  		}
    68  	}
    69  	if actingVersion > c.SbeSchemaVersion() && blockLength > c.SbeBlockLength() {
    70  		io.CopyN(ioutil.Discard, _r, int64(blockLength-c.SbeBlockLength()))
    71  	}
    72  	if doRangeCheck {
    73  		if err := c.RangeCheck(actingVersion, c.SbeSchemaVersion()); err != nil {
    74  			return err
    75  		}
    76  	}
    77  	return nil
    78  }
    79  
    80  func (c *ConsensusModule) RangeCheck(actingVersion uint16, schemaVersion uint16) error {
    81  	if c.NextSessionIdInActingVersion(actingVersion) {
    82  		if c.NextSessionId < c.NextSessionIdMinValue() || c.NextSessionId > c.NextSessionIdMaxValue() {
    83  			return fmt.Errorf("Range check failed on c.NextSessionId (%v < %v > %v)", c.NextSessionIdMinValue(), c.NextSessionId, c.NextSessionIdMaxValue())
    84  		}
    85  	}
    86  	if c.NextServiceSessionIdInActingVersion(actingVersion) {
    87  		if c.NextServiceSessionId != c.NextServiceSessionIdNullValue() && (c.NextServiceSessionId < c.NextServiceSessionIdMinValue() || c.NextServiceSessionId > c.NextServiceSessionIdMaxValue()) {
    88  			return fmt.Errorf("Range check failed on c.NextServiceSessionId (%v < %v > %v)", c.NextServiceSessionIdMinValue(), c.NextServiceSessionId, c.NextServiceSessionIdMaxValue())
    89  		}
    90  	}
    91  	if c.LogServiceSessionIdInActingVersion(actingVersion) {
    92  		if c.LogServiceSessionId != c.LogServiceSessionIdNullValue() && (c.LogServiceSessionId < c.LogServiceSessionIdMinValue() || c.LogServiceSessionId > c.LogServiceSessionIdMaxValue()) {
    93  			return fmt.Errorf("Range check failed on c.LogServiceSessionId (%v < %v > %v)", c.LogServiceSessionIdMinValue(), c.LogServiceSessionId, c.LogServiceSessionIdMaxValue())
    94  		}
    95  	}
    96  	if c.PendingMessageCapacityInActingVersion(actingVersion) {
    97  		if c.PendingMessageCapacity != c.PendingMessageCapacityNullValue() && (c.PendingMessageCapacity < c.PendingMessageCapacityMinValue() || c.PendingMessageCapacity > c.PendingMessageCapacityMaxValue()) {
    98  			return fmt.Errorf("Range check failed on c.PendingMessageCapacity (%v < %v > %v)", c.PendingMessageCapacityMinValue(), c.PendingMessageCapacity, c.PendingMessageCapacityMaxValue())
    99  		}
   100  	}
   101  	return nil
   102  }
   103  
   104  func ConsensusModuleInit(c *ConsensusModule) {
   105  	c.NextServiceSessionId = math.MinInt64
   106  	c.LogServiceSessionId = math.MinInt64
   107  	c.PendingMessageCapacity = 0
   108  	return
   109  }
   110  
   111  func (*ConsensusModule) SbeBlockLength() (blockLength uint16) {
   112  	return 28
   113  }
   114  
   115  func (*ConsensusModule) SbeTemplateId() (templateId uint16) {
   116  	return 105
   117  }
   118  
   119  func (*ConsensusModule) SbeSchemaId() (schemaId uint16) {
   120  	return 111
   121  }
   122  
   123  func (*ConsensusModule) SbeSchemaVersion() (schemaVersion uint16) {
   124  	return 8
   125  }
   126  
   127  func (*ConsensusModule) SbeSemanticType() (semanticType []byte) {
   128  	return []byte("")
   129  }
   130  
   131  func (*ConsensusModule) NextSessionIdId() uint16 {
   132  	return 1
   133  }
   134  
   135  func (*ConsensusModule) NextSessionIdSinceVersion() uint16 {
   136  	return 0
   137  }
   138  
   139  func (c *ConsensusModule) NextSessionIdInActingVersion(actingVersion uint16) bool {
   140  	return actingVersion >= c.NextSessionIdSinceVersion()
   141  }
   142  
   143  func (*ConsensusModule) NextSessionIdDeprecated() uint16 {
   144  	return 0
   145  }
   146  
   147  func (*ConsensusModule) NextSessionIdMetaAttribute(meta int) string {
   148  	switch meta {
   149  	case 1:
   150  		return ""
   151  	case 2:
   152  		return ""
   153  	case 3:
   154  		return ""
   155  	case 4:
   156  		return "required"
   157  	}
   158  	return ""
   159  }
   160  
   161  func (*ConsensusModule) NextSessionIdMinValue() int64 {
   162  	return math.MinInt64 + 1
   163  }
   164  
   165  func (*ConsensusModule) NextSessionIdMaxValue() int64 {
   166  	return math.MaxInt64
   167  }
   168  
   169  func (*ConsensusModule) NextSessionIdNullValue() int64 {
   170  	return math.MinInt64
   171  }
   172  
   173  func (*ConsensusModule) NextServiceSessionIdId() uint16 {
   174  	return 2
   175  }
   176  
   177  func (*ConsensusModule) NextServiceSessionIdSinceVersion() uint16 {
   178  	return 3
   179  }
   180  
   181  func (c *ConsensusModule) NextServiceSessionIdInActingVersion(actingVersion uint16) bool {
   182  	return actingVersion >= c.NextServiceSessionIdSinceVersion()
   183  }
   184  
   185  func (*ConsensusModule) NextServiceSessionIdDeprecated() uint16 {
   186  	return 0
   187  }
   188  
   189  func (*ConsensusModule) NextServiceSessionIdMetaAttribute(meta int) string {
   190  	switch meta {
   191  	case 1:
   192  		return ""
   193  	case 2:
   194  		return ""
   195  	case 3:
   196  		return ""
   197  	case 4:
   198  		return "optional"
   199  	}
   200  	return ""
   201  }
   202  
   203  func (*ConsensusModule) NextServiceSessionIdMinValue() int64 {
   204  	return math.MinInt64 + 1
   205  }
   206  
   207  func (*ConsensusModule) NextServiceSessionIdMaxValue() int64 {
   208  	return math.MaxInt64
   209  }
   210  
   211  func (*ConsensusModule) NextServiceSessionIdNullValue() int64 {
   212  	return math.MinInt64
   213  }
   214  
   215  func (*ConsensusModule) LogServiceSessionIdId() uint16 {
   216  	return 3
   217  }
   218  
   219  func (*ConsensusModule) LogServiceSessionIdSinceVersion() uint16 {
   220  	return 3
   221  }
   222  
   223  func (c *ConsensusModule) LogServiceSessionIdInActingVersion(actingVersion uint16) bool {
   224  	return actingVersion >= c.LogServiceSessionIdSinceVersion()
   225  }
   226  
   227  func (*ConsensusModule) LogServiceSessionIdDeprecated() uint16 {
   228  	return 0
   229  }
   230  
   231  func (*ConsensusModule) LogServiceSessionIdMetaAttribute(meta int) string {
   232  	switch meta {
   233  	case 1:
   234  		return ""
   235  	case 2:
   236  		return ""
   237  	case 3:
   238  		return ""
   239  	case 4:
   240  		return "optional"
   241  	}
   242  	return ""
   243  }
   244  
   245  func (*ConsensusModule) LogServiceSessionIdMinValue() int64 {
   246  	return math.MinInt64 + 1
   247  }
   248  
   249  func (*ConsensusModule) LogServiceSessionIdMaxValue() int64 {
   250  	return math.MaxInt64
   251  }
   252  
   253  func (*ConsensusModule) LogServiceSessionIdNullValue() int64 {
   254  	return math.MinInt64
   255  }
   256  
   257  func (*ConsensusModule) PendingMessageCapacityId() uint16 {
   258  	return 4
   259  }
   260  
   261  func (*ConsensusModule) PendingMessageCapacitySinceVersion() uint16 {
   262  	return 3
   263  }
   264  
   265  func (c *ConsensusModule) PendingMessageCapacityInActingVersion(actingVersion uint16) bool {
   266  	return actingVersion >= c.PendingMessageCapacitySinceVersion()
   267  }
   268  
   269  func (*ConsensusModule) PendingMessageCapacityDeprecated() uint16 {
   270  	return 0
   271  }
   272  
   273  func (*ConsensusModule) PendingMessageCapacityMetaAttribute(meta int) string {
   274  	switch meta {
   275  	case 1:
   276  		return ""
   277  	case 2:
   278  		return ""
   279  	case 3:
   280  		return ""
   281  	case 4:
   282  		return "optional"
   283  	}
   284  	return ""
   285  }
   286  
   287  func (*ConsensusModule) PendingMessageCapacityMinValue() int32 {
   288  	return math.MinInt32 + 1
   289  }
   290  
   291  func (*ConsensusModule) PendingMessageCapacityMaxValue() int32 {
   292  	return math.MaxInt32
   293  }
   294  
   295  func (*ConsensusModule) PendingMessageCapacityNullValue() int32 {
   296  	return 0
   297  }