github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/types/option_int.go (about)

     1  // Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls
     2  //
     3  // Copyright 2020 Stafi Protocol
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package types
    18  
    19  import "github.com/stafiprotocol/go-substrate-rpc-client/pkg/scale"
    20  
    21  // OptionI8 is a structure that can store a I8 or a missing value
    22  type OptionI8 struct {
    23  	option
    24  	value I8
    25  }
    26  
    27  // NewOptionI8 creates an OptionI8 with a value
    28  func NewOptionI8(value I8) OptionI8 {
    29  	return OptionI8{option{true}, value}
    30  }
    31  
    32  // NewOptionI8Empty creates an OptionI8 without a value
    33  func NewOptionI8Empty() OptionI8 {
    34  	return OptionI8{option: option{false}}
    35  }
    36  
    37  func (o OptionI8) Encode(encoder scale.Encoder) error {
    38  	return encoder.EncodeOption(o.hasValue, o.value)
    39  }
    40  
    41  func (o *OptionI8) Decode(decoder scale.Decoder) error {
    42  	return decoder.DecodeOption(&o.hasValue, &o.value)
    43  }
    44  
    45  // SetSome sets a value
    46  func (o *OptionI8) SetSome(value I8) {
    47  	o.hasValue = true
    48  	o.value = value
    49  }
    50  
    51  // SetNone removes a value and marks it as missing
    52  func (o *OptionI8) SetNone() {
    53  	o.hasValue = false
    54  	o.value = I8(0)
    55  }
    56  
    57  // Unwrap returns a flag that indicates whether a value is present and the stored value
    58  func (o OptionI8) Unwrap() (ok bool, value I8) {
    59  	return o.hasValue, o.value
    60  }
    61  
    62  // OptionI16 is a structure that can store a I16 or a missing value
    63  type OptionI16 struct {
    64  	option
    65  	value I16
    66  }
    67  
    68  // NewOptionI16 creates an OptionI16 with a value
    69  func NewOptionI16(value I16) OptionI16 {
    70  	return OptionI16{option{true}, value}
    71  }
    72  
    73  // NewOptionI16Empty creates an OptionI16 without a value
    74  func NewOptionI16Empty() OptionI16 {
    75  	return OptionI16{option: option{false}}
    76  }
    77  
    78  func (o OptionI16) Encode(encoder scale.Encoder) error {
    79  	return encoder.EncodeOption(o.hasValue, o.value)
    80  }
    81  
    82  func (o *OptionI16) Decode(decoder scale.Decoder) error {
    83  	return decoder.DecodeOption(&o.hasValue, &o.value)
    84  }
    85  
    86  // SetSome sets a value
    87  func (o *OptionI16) SetSome(value I16) {
    88  	o.hasValue = true
    89  	o.value = value
    90  }
    91  
    92  // SetNone removes a value and marks it as missing
    93  func (o *OptionI16) SetNone() {
    94  	o.hasValue = false
    95  	o.value = I16(0)
    96  }
    97  
    98  // Unwrap returns a flag that indicates whether a value is present and the stored value
    99  func (o OptionI16) Unwrap() (ok bool, value I16) {
   100  	return o.hasValue, o.value
   101  }
   102  
   103  // OptionI32 is a structure that can store a I32 or a missing value
   104  type OptionI32 struct {
   105  	option
   106  	value I32
   107  }
   108  
   109  // NewOptionI32 creates an OptionI32 with a value
   110  func NewOptionI32(value I32) OptionI32 {
   111  	return OptionI32{option{true}, value}
   112  }
   113  
   114  // NewOptionI32Empty creates an OptionI32 without a value
   115  func NewOptionI32Empty() OptionI32 {
   116  	return OptionI32{option: option{false}}
   117  }
   118  
   119  func (o OptionI32) Encode(encoder scale.Encoder) error {
   120  	return encoder.EncodeOption(o.hasValue, o.value)
   121  }
   122  
   123  func (o *OptionI32) Decode(decoder scale.Decoder) error {
   124  	return decoder.DecodeOption(&o.hasValue, &o.value)
   125  }
   126  
   127  // SetSome sets a value
   128  func (o *OptionI32) SetSome(value I32) {
   129  	o.hasValue = true
   130  	o.value = value
   131  }
   132  
   133  // SetNone removes a value and marks it as missing
   134  func (o *OptionI32) SetNone() {
   135  	o.hasValue = false
   136  	o.value = I32(0)
   137  }
   138  
   139  // Unwrap returns a flag that indicates whether a value is present and the stored value
   140  func (o OptionI32) Unwrap() (ok bool, value I32) {
   141  	return o.hasValue, o.value
   142  }
   143  
   144  // OptionI64 is a structure that can store a I64 or a missing value
   145  type OptionI64 struct {
   146  	option
   147  	value I64
   148  }
   149  
   150  // NewOptionI64 creates an OptionI64 with a value
   151  func NewOptionI64(value I64) OptionI64 {
   152  	return OptionI64{option{true}, value}
   153  }
   154  
   155  // NewOptionI64Empty creates an OptionI64 without a value
   156  func NewOptionI64Empty() OptionI64 {
   157  	return OptionI64{option: option{false}}
   158  }
   159  
   160  func (o OptionI64) Encode(encoder scale.Encoder) error {
   161  	return encoder.EncodeOption(o.hasValue, o.value)
   162  }
   163  
   164  func (o *OptionI64) Decode(decoder scale.Decoder) error {
   165  	return decoder.DecodeOption(&o.hasValue, &o.value)
   166  }
   167  
   168  // SetSome sets a value
   169  func (o *OptionI64) SetSome(value I64) {
   170  	o.hasValue = true
   171  	o.value = value
   172  }
   173  
   174  // SetNone removes a value and marks it as missing
   175  func (o *OptionI64) SetNone() {
   176  	o.hasValue = false
   177  	o.value = I64(0)
   178  }
   179  
   180  // Unwrap returns a flag that indicates whether a value is present and the stored value
   181  func (o OptionI64) Unwrap() (ok bool, value I64) {
   182  	return o.hasValue, o.value
   183  }