github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/cluster/codecs/TerminationPosition.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 TerminationPosition struct {
    13  	LeadershipTermId int64
    14  	LogPosition      int64
    15  }
    16  
    17  func (t *TerminationPosition) Encode(_m *SbeGoMarshaller, _w io.Writer, doRangeCheck bool) error {
    18  	if doRangeCheck {
    19  		if err := t.RangeCheck(t.SbeSchemaVersion(), t.SbeSchemaVersion()); err != nil {
    20  			return err
    21  		}
    22  	}
    23  	if err := _m.WriteInt64(_w, t.LeadershipTermId); err != nil {
    24  		return err
    25  	}
    26  	if err := _m.WriteInt64(_w, t.LogPosition); err != nil {
    27  		return err
    28  	}
    29  	return nil
    30  }
    31  
    32  func (t *TerminationPosition) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16, blockLength uint16, doRangeCheck bool) error {
    33  	if !t.LeadershipTermIdInActingVersion(actingVersion) {
    34  		t.LeadershipTermId = t.LeadershipTermIdNullValue()
    35  	} else {
    36  		if err := _m.ReadInt64(_r, &t.LeadershipTermId); err != nil {
    37  			return err
    38  		}
    39  	}
    40  	if !t.LogPositionInActingVersion(actingVersion) {
    41  		t.LogPosition = t.LogPositionNullValue()
    42  	} else {
    43  		if err := _m.ReadInt64(_r, &t.LogPosition); err != nil {
    44  			return err
    45  		}
    46  	}
    47  	if actingVersion > t.SbeSchemaVersion() && blockLength > t.SbeBlockLength() {
    48  		io.CopyN(ioutil.Discard, _r, int64(blockLength-t.SbeBlockLength()))
    49  	}
    50  	if doRangeCheck {
    51  		if err := t.RangeCheck(actingVersion, t.SbeSchemaVersion()); err != nil {
    52  			return err
    53  		}
    54  	}
    55  	return nil
    56  }
    57  
    58  func (t *TerminationPosition) RangeCheck(actingVersion uint16, schemaVersion uint16) error {
    59  	if t.LeadershipTermIdInActingVersion(actingVersion) {
    60  		if t.LeadershipTermId < t.LeadershipTermIdMinValue() || t.LeadershipTermId > t.LeadershipTermIdMaxValue() {
    61  			return fmt.Errorf("Range check failed on t.LeadershipTermId (%v < %v > %v)", t.LeadershipTermIdMinValue(), t.LeadershipTermId, t.LeadershipTermIdMaxValue())
    62  		}
    63  	}
    64  	if t.LogPositionInActingVersion(actingVersion) {
    65  		if t.LogPosition < t.LogPositionMinValue() || t.LogPosition > t.LogPositionMaxValue() {
    66  			return fmt.Errorf("Range check failed on t.LogPosition (%v < %v > %v)", t.LogPositionMinValue(), t.LogPosition, t.LogPositionMaxValue())
    67  		}
    68  	}
    69  	return nil
    70  }
    71  
    72  func TerminationPositionInit(t *TerminationPosition) {
    73  	return
    74  }
    75  
    76  func (*TerminationPosition) SbeBlockLength() (blockLength uint16) {
    77  	return 16
    78  }
    79  
    80  func (*TerminationPosition) SbeTemplateId() (templateId uint16) {
    81  	return 75
    82  }
    83  
    84  func (*TerminationPosition) SbeSchemaId() (schemaId uint16) {
    85  	return 111
    86  }
    87  
    88  func (*TerminationPosition) SbeSchemaVersion() (schemaVersion uint16) {
    89  	return 8
    90  }
    91  
    92  func (*TerminationPosition) SbeSemanticType() (semanticType []byte) {
    93  	return []byte("")
    94  }
    95  
    96  func (*TerminationPosition) LeadershipTermIdId() uint16 {
    97  	return 1
    98  }
    99  
   100  func (*TerminationPosition) LeadershipTermIdSinceVersion() uint16 {
   101  	return 0
   102  }
   103  
   104  func (t *TerminationPosition) LeadershipTermIdInActingVersion(actingVersion uint16) bool {
   105  	return actingVersion >= t.LeadershipTermIdSinceVersion()
   106  }
   107  
   108  func (*TerminationPosition) LeadershipTermIdDeprecated() uint16 {
   109  	return 0
   110  }
   111  
   112  func (*TerminationPosition) LeadershipTermIdMetaAttribute(meta int) string {
   113  	switch meta {
   114  	case 1:
   115  		return ""
   116  	case 2:
   117  		return ""
   118  	case 3:
   119  		return ""
   120  	case 4:
   121  		return "required"
   122  	}
   123  	return ""
   124  }
   125  
   126  func (*TerminationPosition) LeadershipTermIdMinValue() int64 {
   127  	return math.MinInt64 + 1
   128  }
   129  
   130  func (*TerminationPosition) LeadershipTermIdMaxValue() int64 {
   131  	return math.MaxInt64
   132  }
   133  
   134  func (*TerminationPosition) LeadershipTermIdNullValue() int64 {
   135  	return math.MinInt64
   136  }
   137  
   138  func (*TerminationPosition) LogPositionId() uint16 {
   139  	return 2
   140  }
   141  
   142  func (*TerminationPosition) LogPositionSinceVersion() uint16 {
   143  	return 0
   144  }
   145  
   146  func (t *TerminationPosition) LogPositionInActingVersion(actingVersion uint16) bool {
   147  	return actingVersion >= t.LogPositionSinceVersion()
   148  }
   149  
   150  func (*TerminationPosition) LogPositionDeprecated() uint16 {
   151  	return 0
   152  }
   153  
   154  func (*TerminationPosition) LogPositionMetaAttribute(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 (*TerminationPosition) LogPositionMinValue() int64 {
   169  	return math.MinInt64 + 1
   170  }
   171  
   172  func (*TerminationPosition) LogPositionMaxValue() int64 {
   173  	return math.MaxInt64
   174  }
   175  
   176  func (*TerminationPosition) LogPositionNullValue() int64 {
   177  	return math.MinInt64
   178  }