MCPcopy Create free account
hub / github.com/erpc/erpc / tryGetRemoteState

Method tryGetRemoteState

data/shared_state_variable.go:571–591  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

569}
570
571func (c *counterInt64) tryGetRemoteState(ctx context.Context) (CounterInt64State, bool) {
572 remoteVal, err := c.registry.connector.Get(ctx, ConnectorMainIndex, c.key, "value", nil)
573 if err != nil {
574 if common.HasErrorCode(err, common.ErrCodeRecordNotFound) {
575 c.registry.logger.Debug().Err(err).Str("key", c.key).Msg("remote counter value not found, will initialize it")
576 } else {
577 c.registry.logger.Warn().Err(err).Str("key", c.key).Msg("failed to get remote counter value")
578 }
579 return CounterInt64State{}, false
580 }
581 var st CounterInt64State
582 if err := common.SonicCfg.Unmarshal(remoteVal, &st); err != nil {
583 // No backward compatibility: treat parse errors as missing
584 c.registry.logger.Debug().Err(err).Str("key", c.key).Msg("failed to parse remote counter state (treating as missing)")
585 return CounterInt64State{}, false
586 }
587 if st.UpdatedAt <= 0 {
588 return CounterInt64State{}, false
589 }
590 return st, true
591}
592
593func (c *counterInt64) updateRemoteState(ctx context.Context, st CounterInt64State) {
594 if st.UpdatedBy == "" {

Callers 1

Calls 2

HasErrorCodeFunction · 0.92
GetMethod · 0.65

Tested by

no test coverage detected