github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/types/bytes.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 ( 20 "fmt" 21 22 "github.com/stafiprotocol/go-substrate-rpc-client/pkg/scale" 23 ) 24 25 // Bytes represents byte slices. Bytes has a variable length, it is encoded with a scale prefix 26 type Bytes []byte 27 28 // NewBytes creates a new Bytes type 29 func NewBytes(b []byte) Bytes { 30 return Bytes(b) 31 } 32 33 // BytesBare represents byte slices that will be encoded bare, i. e. without a compact length prefix. This makes it 34 // impossible to decode the bytes, but is used as the payload for signing. 35 type BytesBare []byte 36 37 // Encode implements encoding for BytesBare, which just unwraps the bytes of BytesBare without adding a compact 38 // length prefix 39 func (b BytesBare) Encode(encoder scale.Encoder) error { 40 return encoder.Write(b) 41 } 42 43 // Decode does nothing and always returns an error. BytesBare is only used for encoding, not for decoding 44 func (b *BytesBare) Decode(decoder scale.Decoder) error { 45 return fmt.Errorf("decoding of BytesBare is not supported") 46 } 47 48 // Bytes8 represents an 8 byte array 49 type Bytes8 [8]byte 50 51 // NewBytes8 creates a new Bytes8 type 52 func NewBytes8(b [8]byte) Bytes8 { 53 return Bytes8(b) 54 } 55 56 // Bytes16 represents an 16 byte array 57 type Bytes16 [16]byte 58 59 // NewBytes16 creates a new Bytes16 type 60 func NewBytes16(b [16]byte) Bytes16 { 61 return Bytes16(b) 62 } 63 64 // Bytes32 represents an 32 byte array 65 type Bytes32 [32]byte 66 67 // NewBytes32 creates a new Bytes32 type 68 func NewBytes32(b [32]byte) Bytes32 { 69 return Bytes32(b) 70 } 71 72 // Bytes64 represents an 64 byte array 73 type Bytes64 [64]byte 74 75 // NewBytes64 creates a new Bytes64 type 76 func NewBytes64(b [64]byte) Bytes64 { 77 return Bytes64(b) 78 } 79 80 // Bytes128 represents an 128 byte array 81 type Bytes128 [128]byte 82 83 // NewBytes128 creates a new Bytes128 type 84 func NewBytes128(b [128]byte) Bytes128 { 85 return Bytes128(b) 86 } 87 88 // Bytes256 represents an 256 byte array 89 type Bytes256 [256]byte 90 91 // NewBytes256 creates a new Bytes256 type 92 func NewBytes256(b [256]byte) Bytes256 { 93 return Bytes256(b) 94 } 95 96 // Bytes512 represents an 512 byte array 97 type Bytes512 [512]byte 98 99 // NewBytes512 creates a new Bytes512 type 100 func NewBytes512(b [512]byte) Bytes512 { 101 return Bytes512(b) 102 } 103 104 // Bytes1024 represents an 1024 byte array 105 type Bytes1024 [1024]byte 106 107 // NewBytes1024 creates a new Bytes1024 type 108 func NewBytes1024(b [1024]byte) Bytes1024 { 109 return Bytes1024(b) 110 } 111 112 // Bytes2048 represents an 2048 byte array 113 type Bytes2048 [2048]byte 114 115 // NewBytes2048 creates a new Bytes2048 type 116 func NewBytes2048(b [2048]byte) Bytes2048 { 117 return Bytes2048(b) 118 }