github.com/git-amp/amp-sdk-go@v0.7.5/amp/builtin-attrs.go (about)

     1  package amp
     2  
     3  func RegisterConstSymbols(reg SessionRegistry) {
     4  	consts := []struct {
     5  		ID   ConstSymbol
     6  		name string
     7  	}{
     8  		{ConstSymbol_Err, "Err"},
     9  		{ConstSymbol_RegisterDefs, "RegisterDefs"},
    10  		{ConstSymbol_HandleURI, "HandleURI"},
    11  		{ConstSymbol_PinRequest, "PinRequest"},
    12  		{ConstSymbol_Login, "Login"},
    13  		{ConstSymbol_LoginChallenge, "LoginChallenge"},
    14  		{ConstSymbol_LoginResponse, "LoginResponse"},
    15  	}
    16  
    17  	defs := RegisterDefs{
    18  		Symbols: make([]*Symbol, len(consts)),
    19  	}
    20  
    21  	for i, sym := range consts {
    22  		defs.Symbols[i] = &Symbol{
    23  			ID:   uint32(sym.ID),
    24  			Name: []byte(sym.name),
    25  		}
    26  	}
    27  
    28  	if err := reg.RegisterDefs(&defs); err != nil {
    29  		panic(err)
    30  	}
    31  }
    32  
    33  func RegisterBuiltInTypes(reg Registry) error {
    34  
    35  	prototypes := []ElemVal{
    36  		&Err{},
    37  		&RegisterDefs{},
    38  		&HandleURI{},
    39  		&Login{},
    40  		&LoginChallenge{},
    41  		&LoginResponse{},
    42  
    43  		&PinRequest{},
    44  		&CellHeader{},
    45  		&AssetTag{},
    46  		&AuthToken{},
    47  		&Position{},
    48  		//&TRS{},
    49  	}
    50  	for _, val := range prototypes {
    51  		reg.RegisterElemType(val)
    52  	}
    53  	return nil
    54  }
    55  
    56  func MarshalPbValueToBuf(src PbValue, dst *[]byte) error {
    57  	sz := src.Size()
    58  	if cap(*dst) < sz {
    59  		*dst = make([]byte, sz)
    60  	} else {
    61  		*dst = (*dst)[:sz]
    62  	}
    63  	_, err := src.MarshalToSizedBuffer(*dst)
    64  	return err
    65  }
    66  
    67  func ErrorToValue(v error) ElemVal {
    68  	if v == nil {
    69  		return nil
    70  	}
    71  	arcErr, _ := v.(*Err)
    72  	if arcErr == nil {
    73  		wrapped := ErrCode_UnnamedErr.Wrap(v)
    74  		arcErr = wrapped.(*Err)
    75  	}
    76  	return arcErr
    77  }
    78  
    79  func (v *AssetTag) MarshalToBuf(dst *[]byte) error {
    80  	return MarshalPbValueToBuf(v, dst)
    81  }
    82  
    83  func (v *AssetTag) TypeName() string {
    84  	return "AssetTag"
    85  }
    86  
    87  func (v *AssetTag) New() ElemVal {
    88  	return &AssetTag{}
    89  }
    90  
    91  func (v *Err) MarshalToBuf(dst *[]byte) error {
    92  	return MarshalPbValueToBuf(v, dst)
    93  }
    94  
    95  func (v *Err) TypeName() string {
    96  	return "Err"
    97  }
    98  
    99  func (v *Err) New() ElemVal {
   100  	return &Err{}
   101  }
   102  
   103  func (v *HandleURI) MarshalToBuf(dst *[]byte) error {
   104  	return MarshalPbValueToBuf(v, dst)
   105  }
   106  
   107  func (v *HandleURI) TypeName() string {
   108  	return "HandleURI"
   109  }
   110  
   111  func (v *HandleURI) New() ElemVal {
   112  	return &HandleURI{}
   113  }
   114  
   115  func (v *Login) MarshalToBuf(dst *[]byte) error {
   116  	return MarshalPbValueToBuf(v, dst)
   117  }
   118  
   119  func (v *Login) TypeName() string {
   120  	return "Login"
   121  }
   122  
   123  func (v *Login) New() ElemVal {
   124  	return &Login{}
   125  }
   126  
   127  func (v *LoginChallenge) MarshalToBuf(dst *[]byte) error {
   128  	return MarshalPbValueToBuf(v, dst)
   129  }
   130  
   131  func (v *LoginChallenge) TypeName() string {
   132  	return "LoginChallenge"
   133  }
   134  
   135  func (v *LoginChallenge) New() ElemVal {
   136  	return &LoginChallenge{}
   137  }
   138  
   139  func (v *LoginResponse) MarshalToBuf(dst *[]byte) error {
   140  	return MarshalPbValueToBuf(v, dst)
   141  }
   142  
   143  func (v *LoginResponse) TypeName() string {
   144  	return "LoginResponse"
   145  }
   146  
   147  func (v *LoginResponse) New() ElemVal {
   148  	return &LoginResponse{}
   149  }
   150  
   151  func (v *CellHeader) MarshalToBuf(dst *[]byte) error {
   152  	return MarshalPbValueToBuf(v, dst)
   153  }
   154  
   155  func (v *CellHeader) TypeName() string {
   156  	return "CellHeader"
   157  }
   158  
   159  func (v *CellHeader) New() ElemVal {
   160  	return &CellHeader{}
   161  }
   162  
   163  func (v *RegisterDefs) MarshalToBuf(dst *[]byte) error {
   164  	return MarshalPbValueToBuf(v, dst)
   165  }
   166  
   167  func (v *RegisterDefs) TypeName() string {
   168  	return "RegisterDefs"
   169  }
   170  
   171  func (v *RegisterDefs) New() ElemVal {
   172  	return &RegisterDefs{}
   173  }
   174  
   175  func (v *Position) MarshalToBuf(dst *[]byte) error {
   176  	return MarshalPbValueToBuf(v, dst)
   177  }
   178  
   179  func (v *Position) TypeName() string {
   180  	return "Position"
   181  }
   182  
   183  func (v *Position) New() ElemVal {
   184  	return &Position{}
   185  }
   186  
   187  func (v *AuthToken) MarshalToBuf(dst *[]byte) error {
   188  	return MarshalPbValueToBuf(v, dst)
   189  }
   190  
   191  func (v *AuthToken) TypeName() string {
   192  	return "AuthToken"
   193  }
   194  
   195  func (v *AuthToken) New() ElemVal {
   196  	return &AuthToken{}
   197  }
   198  
   199  func (v *PinRequest) MarshalToBuf(dst *[]byte) error {
   200  	return MarshalPbValueToBuf(v, dst)
   201  }
   202  
   203  func (v *PinRequest) TypeName() string {
   204  	return "PinRequest"
   205  }
   206  
   207  func (v *PinRequest) New() ElemVal {
   208  	return &PinRequest{}
   209  }
   210  
   211  func (v *PinRequest) CellID() CellID {
   212  	return CellIDFromU64(v.PinCellIDx0, v.PinCellIDx1)
   213  }