github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/cluster/codecs/CatchupPosition.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 CatchupPosition struct {
    13  	LeadershipTermId int64
    14  	LogPosition      int64
    15  	FollowerMemberId int32
    16  	CatchupEndpoint  []uint8
    17  }
    18  
    19  func (c *CatchupPosition) 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.LeadershipTermId); err != nil {
    26  		return err
    27  	}
    28  	if err := _m.WriteInt64(_w, c.LogPosition); err != nil {
    29  		return err
    30  	}
    31  	if err := _m.WriteInt32(_w, c.FollowerMemberId); err != nil {
    32  		return err
    33  	}
    34  	if err := _m.WriteUint32(_w, uint32(len(c.CatchupEndpoint))); err != nil {
    35  		return err
    36  	}
    37  	if err := _m.WriteBytes(_w, c.CatchupEndpoint); err != nil {
    38  		return err
    39  	}
    40  	return nil
    41  }
    42  
    43  func (c *CatchupPosition) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16, blockLength uint16, doRangeCheck bool) error {
    44  	if !c.LeadershipTermIdInActingVersion(actingVersion) {
    45  		c.LeadershipTermId = c.LeadershipTermIdNullValue()
    46  	} else {
    47  		if err := _m.ReadInt64(_r, &c.LeadershipTermId); err != nil {
    48  			return err
    49  		}
    50  	}
    51  	if !c.LogPositionInActingVersion(actingVersion) {
    52  		c.LogPosition = c.LogPositionNullValue()
    53  	} else {
    54  		if err := _m.ReadInt64(_r, &c.LogPosition); err != nil {
    55  			return err
    56  		}
    57  	}
    58  	if !c.FollowerMemberIdInActingVersion(actingVersion) {
    59  		c.FollowerMemberId = c.FollowerMemberIdNullValue()
    60  	} else {
    61  		if err := _m.ReadInt32(_r, &c.FollowerMemberId); err != nil {
    62  			return err
    63  		}
    64  	}
    65  	if actingVersion > c.SbeSchemaVersion() && blockLength > c.SbeBlockLength() {
    66  		io.CopyN(ioutil.Discard, _r, int64(blockLength-c.SbeBlockLength()))
    67  	}
    68  
    69  	if c.CatchupEndpointInActingVersion(actingVersion) {
    70  		var CatchupEndpointLength uint32
    71  		if err := _m.ReadUint32(_r, &CatchupEndpointLength); err != nil {
    72  			return err
    73  		}
    74  		if cap(c.CatchupEndpoint) < int(CatchupEndpointLength) {
    75  			c.CatchupEndpoint = make([]uint8, CatchupEndpointLength)
    76  		}
    77  		c.CatchupEndpoint = c.CatchupEndpoint[:CatchupEndpointLength]
    78  		if err := _m.ReadBytes(_r, c.CatchupEndpoint); err != nil {
    79  			return err
    80  		}
    81  	}
    82  	if doRangeCheck {
    83  		if err := c.RangeCheck(actingVersion, c.SbeSchemaVersion()); err != nil {
    84  			return err
    85  		}
    86  	}
    87  	return nil
    88  }
    89  
    90  func (c *CatchupPosition) RangeCheck(actingVersion uint16, schemaVersion uint16) error {
    91  	if c.LeadershipTermIdInActingVersion(actingVersion) {
    92  		if c.LeadershipTermId < c.LeadershipTermIdMinValue() || c.LeadershipTermId > c.LeadershipTermIdMaxValue() {
    93  			return fmt.Errorf("Range check failed on c.LeadershipTermId (%v < %v > %v)", c.LeadershipTermIdMinValue(), c.LeadershipTermId, c.LeadershipTermIdMaxValue())
    94  		}
    95  	}
    96  	if c.LogPositionInActingVersion(actingVersion) {
    97  		if c.LogPosition < c.LogPositionMinValue() || c.LogPosition > c.LogPositionMaxValue() {
    98  			return fmt.Errorf("Range check failed on c.LogPosition (%v < %v > %v)", c.LogPositionMinValue(), c.LogPosition, c.LogPositionMaxValue())
    99  		}
   100  	}
   101  	if c.FollowerMemberIdInActingVersion(actingVersion) {
   102  		if c.FollowerMemberId < c.FollowerMemberIdMinValue() || c.FollowerMemberId > c.FollowerMemberIdMaxValue() {
   103  			return fmt.Errorf("Range check failed on c.FollowerMemberId (%v < %v > %v)", c.FollowerMemberIdMinValue(), c.FollowerMemberId, c.FollowerMemberIdMaxValue())
   104  		}
   105  	}
   106  	for idx, ch := range c.CatchupEndpoint {
   107  		if ch > 127 {
   108  			return fmt.Errorf("c.CatchupEndpoint[%d]=%d failed ASCII validation", idx, ch)
   109  		}
   110  	}
   111  	return nil
   112  }
   113  
   114  func CatchupPositionInit(c *CatchupPosition) {
   115  	return
   116  }
   117  
   118  func (*CatchupPosition) SbeBlockLength() (blockLength uint16) {
   119  	return 20
   120  }
   121  
   122  func (*CatchupPosition) SbeTemplateId() (templateId uint16) {
   123  	return 56
   124  }
   125  
   126  func (*CatchupPosition) SbeSchemaId() (schemaId uint16) {
   127  	return 111
   128  }
   129  
   130  func (*CatchupPosition) SbeSchemaVersion() (schemaVersion uint16) {
   131  	return 8
   132  }
   133  
   134  func (*CatchupPosition) SbeSemanticType() (semanticType []byte) {
   135  	return []byte("")
   136  }
   137  
   138  func (*CatchupPosition) LeadershipTermIdId() uint16 {
   139  	return 1
   140  }
   141  
   142  func (*CatchupPosition) LeadershipTermIdSinceVersion() uint16 {
   143  	return 0
   144  }
   145  
   146  func (c *CatchupPosition) LeadershipTermIdInActingVersion(actingVersion uint16) bool {
   147  	return actingVersion >= c.LeadershipTermIdSinceVersion()
   148  }
   149  
   150  func (*CatchupPosition) LeadershipTermIdDeprecated() uint16 {
   151  	return 0
   152  }
   153  
   154  func (*CatchupPosition) LeadershipTermIdMetaAttribute(meta int) string {
   155  	switch meta {
   156  	case 1:
   157  		return ""
   158  	case 2:
   159  		return ""
   160  	case 3:
   161  		return ""
   162  	case 4:
   163  		return "required"
   164  	}
   165  	return ""
   166  }
   167  
   168  func (*CatchupPosition) LeadershipTermIdMinValue() int64 {
   169  	return math.MinInt64 + 1
   170  }
   171  
   172  func (*CatchupPosition) LeadershipTermIdMaxValue() int64 {
   173  	return math.MaxInt64
   174  }
   175  
   176  func (*CatchupPosition) LeadershipTermIdNullValue() int64 {
   177  	return math.MinInt64
   178  }
   179  
   180  func (*CatchupPosition) LogPositionId() uint16 {
   181  	return 2
   182  }
   183  
   184  func (*CatchupPosition) LogPositionSinceVersion() uint16 {
   185  	return 0
   186  }
   187  
   188  func (c *CatchupPosition) LogPositionInActingVersion(actingVersion uint16) bool {
   189  	return actingVersion >= c.LogPositionSinceVersion()
   190  }
   191  
   192  func (*CatchupPosition) LogPositionDeprecated() uint16 {
   193  	return 0
   194  }
   195  
   196  func (*CatchupPosition) LogPositionMetaAttribute(meta int) string {
   197  	switch meta {
   198  	case 1:
   199  		return ""
   200  	case 2:
   201  		return ""
   202  	case 3:
   203  		return ""
   204  	case 4:
   205  		return "required"
   206  	}
   207  	return ""
   208  }
   209  
   210  func (*CatchupPosition) LogPositionMinValue() int64 {
   211  	return math.MinInt64 + 1
   212  }
   213  
   214  func (*CatchupPosition) LogPositionMaxValue() int64 {
   215  	return math.MaxInt64
   216  }
   217  
   218  func (*CatchupPosition) LogPositionNullValue() int64 {
   219  	return math.MinInt64
   220  }
   221  
   222  func (*CatchupPosition) FollowerMemberIdId() uint16 {
   223  	return 3
   224  }
   225  
   226  func (*CatchupPosition) FollowerMemberIdSinceVersion() uint16 {
   227  	return 0
   228  }
   229  
   230  func (c *CatchupPosition) FollowerMemberIdInActingVersion(actingVersion uint16) bool {
   231  	return actingVersion >= c.FollowerMemberIdSinceVersion()
   232  }
   233  
   234  func (*CatchupPosition) FollowerMemberIdDeprecated() uint16 {
   235  	return 0
   236  }
   237  
   238  func (*CatchupPosition) FollowerMemberIdMetaAttribute(meta int) string {
   239  	switch meta {
   240  	case 1:
   241  		return ""
   242  	case 2:
   243  		return ""
   244  	case 3:
   245  		return ""
   246  	case 4:
   247  		return "required"
   248  	}
   249  	return ""
   250  }
   251  
   252  func (*CatchupPosition) FollowerMemberIdMinValue() int32 {
   253  	return math.MinInt32 + 1
   254  }
   255  
   256  func (*CatchupPosition) FollowerMemberIdMaxValue() int32 {
   257  	return math.MaxInt32
   258  }
   259  
   260  func (*CatchupPosition) FollowerMemberIdNullValue() int32 {
   261  	return math.MinInt32
   262  }
   263  
   264  func (*CatchupPosition) CatchupEndpointMetaAttribute(meta int) string {
   265  	switch meta {
   266  	case 1:
   267  		return ""
   268  	case 2:
   269  		return ""
   270  	case 3:
   271  		return ""
   272  	case 4:
   273  		return "required"
   274  	}
   275  	return ""
   276  }
   277  
   278  func (*CatchupPosition) CatchupEndpointSinceVersion() uint16 {
   279  	return 0
   280  }
   281  
   282  func (c *CatchupPosition) CatchupEndpointInActingVersion(actingVersion uint16) bool {
   283  	return actingVersion >= c.CatchupEndpointSinceVersion()
   284  }
   285  
   286  func (*CatchupPosition) CatchupEndpointDeprecated() uint16 {
   287  	return 0
   288  }
   289  
   290  func (CatchupPosition) CatchupEndpointCharacterEncoding() string {
   291  	return "US-ASCII"
   292  }
   293  
   294  func (CatchupPosition) CatchupEndpointHeaderLength() uint64 {
   295  	return 4
   296  }