1 package keystore 2 3 // File automatically generated with ./types.sh 4 5 import ( 6 "io" 7 "sync" 8 9 "vimagination.zapto.org/byteio" 10 ) 11 12 type readerPool struct { 13 pool sync.Pool 14 } 15 16 func (rp *readerPool) Get(r io.Reader) *byteio.StickyLittleEndianReader { 17 lr := rp.pool.Get().(*byteio.StickyLittleEndianReader) 18 lr.Reader = r 19 return lr 20 } 21 22 func (rp *readerPool) Put(lr *byteio.StickyLittleEndianReader) (int64, error) { 23 c, err := lr.Count, lr.Err 24 *lr = byteio.StickyLittleEndianReader{} 25 rp.pool.Put(lr) 26 return c, err 27 } 28 29 type writerPool struct { 30 pool sync.Pool 31 } 32 33 func (wp *writerPool) Get(w io.Writer) *byteio.StickyLittleEndianWriter { 34 lw := wp.pool.Get().(*byteio.StickyLittleEndianWriter) 35 lw.Writer = w 36 return lw 37 } 38 39 func (wp *writerPool) Put(lw *byteio.StickyLittleEndianWriter) (int64, error) { 40 c, err := lw.Count, lw.Err 41 *lw = byteio.StickyLittleEndianWriter{} 42 wp.pool.Put(lw) 43 return c, err 44 } 45 46 var ( 47 aReaderPool = readerPool{ 48 pool: sync.Pool{ 49 New: func() interface{} { 50 return new(byteio.StickyLittleEndianReader) 51 }, 52 }, 53 } 54 aWriterPool = writerPool{ 55 pool: sync.Pool{ 56 New: func() interface{} { 57 return new(byteio.StickyLittleEndianWriter) 58 }, 59 }, 60 } 61 ) 62 63 // String is a string that implements io.ReaderFrom and io.WriterTo 64 type String string 65 66 // ReadFrom decodes the string from the Reader 67 func (t *String) ReadFrom(r io.Reader) (int64, error) { 68 lr := aReaderPool.Get(r) 69 *t = String(lr.ReadStringX()) 70 return aReaderPool.Put(lr) 71 } 72 73 // WriteTo encodes the string to the Writer 74 func (t String) WriteTo(w io.Writer) (int64, error) { 75 lw := aWriterPool.Get(w) 76 lw.WriteStringX(string(t)) 77 return aWriterPool.Put(lw) 78 } 79 80 // Uint8 is a uint8 that implements io.ReaderFrom and io.WriterTo 81 type Uint8 uint8 82 83 // ReadFrom decodes the uint8 from the Reader 84 func (t *Uint8) ReadFrom(r io.Reader) (int64, error) { 85 lr := aReaderPool.Get(r) 86 *t = Uint8(lr.ReadUint8()) 87 return aReaderPool.Put(lr) 88 } 89 90 // WriteTo encodes the uint8 to the Writer 91 func (t Uint8) WriteTo(w io.Writer) (int64, error) { 92 lw := aWriterPool.Get(w) 93 lw.WriteUint8(uint8(t)) 94 return aWriterPool.Put(lw) 95 } 96 97 // Uint16 is a uint16 that implements io.ReaderFrom and io.WriterTo 98 type Uint16 uint16 99 100 // ReadFrom decodes the uint16 from the Reader 101 func (t *Uint16) ReadFrom(r io.Reader) (int64, error) { 102 lr := aReaderPool.Get(r) 103 *t = Uint16(lr.ReadUint16()) 104 return aReaderPool.Put(lr) 105 } 106 107 // WriteTo encodes the uint16 to the Writer 108 func (t Uint16) WriteTo(w io.Writer) (int64, error) { 109 lw := aWriterPool.Get(w) 110 lw.WriteUint16(uint16(t)) 111 return aWriterPool.Put(lw) 112 } 113 114 // Uint32 is a uint32 that implements io.ReaderFrom and io.WriterTo 115 type Uint32 uint32 116 117 // ReadFrom decodes the uint32 from the Reader 118 func (t *Uint32) ReadFrom(r io.Reader) (int64, error) { 119 lr := aReaderPool.Get(r) 120 *t = Uint32(lr.ReadUint32()) 121 return aReaderPool.Put(lr) 122 } 123 124 // WriteTo encodes the uint32 to the Writer 125 func (t Uint32) WriteTo(w io.Writer) (int64, error) { 126 lw := aWriterPool.Get(w) 127 lw.WriteUint32(uint32(t)) 128 return aWriterPool.Put(lw) 129 } 130 131 // Uint64 is a uint64 that implements io.ReaderFrom and io.WriterTo 132 type Uint64 uint64 133 134 // ReadFrom decodes the uint64 from the Reader 135 func (t *Uint64) ReadFrom(r io.Reader) (int64, error) { 136 lr := aReaderPool.Get(r) 137 *t = Uint64(lr.ReadUint64()) 138 return aReaderPool.Put(lr) 139 } 140 141 // WriteTo encodes the uint64 to the Writer 142 func (t Uint64) WriteTo(w io.Writer) (int64, error) { 143 lw := aWriterPool.Get(w) 144 lw.WriteUint64(uint64(t)) 145 return aWriterPool.Put(lw) 146 } 147 148 // Uint is a uint that implements io.ReaderFrom and io.WriterTo 149 type Uint uint 150 151 // ReadFrom decodes the uint from the Reader 152 func (t *Uint) ReadFrom(r io.Reader) (int64, error) { 153 lr := aReaderPool.Get(r) 154 *t = Uint(lr.ReadUintX()) 155 return aReaderPool.Put(lr) 156 } 157 158 // WriteTo encodes the uint to the Writer 159 func (t Uint) WriteTo(w io.Writer) (int64, error) { 160 lw := aWriterPool.Get(w) 161 lw.WriteUintX(uint64(t)) 162 return aWriterPool.Put(lw) 163 } 164 165 // Int8 is a int8 that implements io.ReaderFrom and io.WriterTo 166 type Int8 int8 167 168 // ReadFrom decodes the int8 from the Reader 169 func (t *Int8) ReadFrom(r io.Reader) (int64, error) { 170 lr := aReaderPool.Get(r) 171 *t = Int8(lr.ReadInt8()) 172 return aReaderPool.Put(lr) 173 } 174 175 // WriteTo encodes the int8 to the Writer 176 func (t Int8) WriteTo(w io.Writer) (int64, error) { 177 lw := aWriterPool.Get(w) 178 lw.WriteInt8(int8(t)) 179 return aWriterPool.Put(lw) 180 } 181 182 // Int16 is a int16 that implements io.ReaderFrom and io.WriterTo 183 type Int16 int16 184 185 // ReadFrom decodes the int16 from the Reader 186 func (t *Int16) ReadFrom(r io.Reader) (int64, error) { 187 lr := aReaderPool.Get(r) 188 *t = Int16(lr.ReadInt16()) 189 return aReaderPool.Put(lr) 190 } 191 192 // WriteTo encodes the int16 to the Writer 193 func (t Int16) WriteTo(w io.Writer) (int64, error) { 194 lw := aWriterPool.Get(w) 195 lw.WriteInt16(int16(t)) 196 return aWriterPool.Put(lw) 197 } 198 199 // Int32 is a int32 that implements io.ReaderFrom and io.WriterTo 200 type Int32 int32 201 202 // ReadFrom decodes the int32 from the Reader 203 func (t *Int32) ReadFrom(r io.Reader) (int64, error) { 204 lr := aReaderPool.Get(r) 205 *t = Int32(lr.ReadInt32()) 206 return aReaderPool.Put(lr) 207 } 208 209 // WriteTo encodes the int32 to the Writer 210 func (t Int32) WriteTo(w io.Writer) (int64, error) { 211 lw := aWriterPool.Get(w) 212 lw.WriteInt32(int32(t)) 213 return aWriterPool.Put(lw) 214 } 215 216 // Int64 is a int64 that implements io.ReaderFrom and io.WriterTo 217 type Int64 int64 218 219 // ReadFrom decodes the int64 from the Reader 220 func (t *Int64) ReadFrom(r io.Reader) (int64, error) { 221 lr := aReaderPool.Get(r) 222 *t = Int64(lr.ReadInt64()) 223 return aReaderPool.Put(lr) 224 } 225 226 // WriteTo encodes the int64 to the Writer 227 func (t Int64) WriteTo(w io.Writer) (int64, error) { 228 lw := aWriterPool.Get(w) 229 lw.WriteInt64(int64(t)) 230 return aWriterPool.Put(lw) 231 } 232 233 // Int is a int that implements io.ReaderFrom and io.WriterTo 234 type Int int 235 236 // ReadFrom decodes the int from the Reader 237 func (t *Int) ReadFrom(r io.Reader) (int64, error) { 238 lr := aReaderPool.Get(r) 239 *t = Int(lr.ReadIntX()) 240 return aReaderPool.Put(lr) 241 } 242 243 // WriteTo encodes the int to the Writer 244 func (t Int) WriteTo(w io.Writer) (int64, error) { 245 lw := aWriterPool.Get(w) 246 lw.WriteIntX(int64(t)) 247 return aWriterPool.Put(lw) 248 } 249 250 // Float32 is a float32 that implements io.ReaderFrom and io.WriterTo 251 type Float32 float32 252 253 // ReadFrom decodes the float32 from the Reader 254 func (t *Float32) ReadFrom(r io.Reader) (int64, error) { 255 lr := aReaderPool.Get(r) 256 *t = Float32(lr.ReadFloat32()) 257 return aReaderPool.Put(lr) 258 } 259 260 // WriteTo encodes the float32 to the Writer 261 func (t Float32) WriteTo(w io.Writer) (int64, error) { 262 lw := aWriterPool.Get(w) 263 lw.WriteFloat32(float32(t)) 264 return aWriterPool.Put(lw) 265 } 266 267 // Float64 is a float64 that implements io.ReaderFrom and io.WriterTo 268 type Float64 float64 269 270 // ReadFrom decodes the float64 from the Reader 271 func (t *Float64) ReadFrom(r io.Reader) (int64, error) { 272 lr := aReaderPool.Get(r) 273 *t = Float64(lr.ReadFloat64()) 274 return aReaderPool.Put(lr) 275 } 276 277 // WriteTo encodes the float64 to the Writer 278 func (t Float64) WriteTo(w io.Writer) (int64, error) { 279 lw := aWriterPool.Get(w) 280 lw.WriteFloat64(float64(t)) 281 return aWriterPool.Put(lw) 282 }