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