github.com/annchain/OG@v0.0.9/common/math/bigint_gen.go (about) 1 // Copyright © 2019 Annchain Authors <EMAIL ADDRESS> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package math 15 16 // Code generated by github.com/tinylib/msgp DO NOT EDIT. 17 18 import ( 19 "github.com/tinylib/msgp/msgp" 20 "math/big" 21 ) 22 23 // DecodeMsg implements msgp.Decodable 24 func (z *BigInt) DecodeMsg(dc *msgp.Reader) (err error) { 25 var zb0001 uint32 26 zb0001, err = dc.ReadArrayHeader() 27 if err != nil { 28 return 29 } 30 if zb0001 != 1 { 31 err = msgp.ArrayError{Wanted: 1, Got: zb0001} 32 return 33 } 34 sign, err := dc.ReadBool() 35 if err != nil { 36 return 37 } 38 39 bytes, err := dc.ReadBytes([]byte{}) 40 if err != nil { 41 return 42 } 43 z.Value = big.NewInt(0).SetBytes(bytes) 44 if !sign { 45 z.Value = z.Value.Neg(z.Value) 46 } 47 return 48 } 49 50 // EncodeMsg implements msgp.Encodable 51 func (z *BigInt) EncodeMsg(en *msgp.Writer) (err error) { 52 // array header, size 1 53 err = en.Append(0x91) 54 if err != nil { 55 return 56 } 57 err = en.WriteBool(z.Value.Sign() > 0) 58 err = en.WriteBytes(z.Value.Bytes()) 59 if err != nil { 60 return 61 } 62 return 63 } 64 65 // MarshalMsg implements msgp.Marshaler 66 func (z *BigInt) MarshalMsg(b []byte) (o []byte, err error) { 67 o = msgp.Require(b, z.Msgsize()) 68 // array header, size 1 69 o = append(o, 0x91) 70 o = msgp.AppendBool(o, z.Sign() > 0) 71 o = msgp.AppendBytes(o, z.Value.Bytes()) 72 return 73 } 74 75 // UnmarshalMsg implements msgp.Unmarshaler 76 func (z *BigInt) UnmarshalMsg(bts []byte) (o []byte, err error) { 77 var zb0001 uint32 78 zb0001, bts, err = msgp.ReadArrayHeaderBytes(bts) 79 if err != nil { 80 return 81 } 82 if zb0001 != 1 { 83 err = msgp.ArrayError{Wanted: 1, Got: zb0001} 84 return 85 } 86 sign, bts, err := msgp.ReadBoolBytes(bts) 87 if err != nil { 88 return 89 } 90 bytes, bts, err := msgp.ReadBytesBytes(bts, []byte{}) 91 if err != nil { 92 return 93 } 94 z.Value = big.NewInt(0).SetBytes(bytes) 95 if !sign { 96 z.Value = z.Value.Neg(z.Value) 97 } 98 o = bts 99 return 100 } 101 102 // Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message 103 func (z *BigInt) Msgsize() (s int) { 104 s = 1 + msgp.BytesPrefixSize + 1 + len(z.Value.Bytes()) 105 return 106 }