| 1 | /* |
| 2 | Licensed to the Apache Software Foundation (ASF) under one |
| 3 | oor more contributor license agreements. See the NOTICE file |
| 4 | distributed with this work for additional information |
| 5 | regarding copyright ownership. The ASF licenses this file |
| 6 | to you under the Apache License, Version 2.0 (the |
| 7 | "License"); you may not use this file except in compliance |
| 8 | with the License. You may obtain a copy of the License at |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | Unless required by applicable law or agreed to in writing, |
| 13 | software distributed under the License is distributed on an |
| 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | KIND, either express or implied. See the License for the |
| 16 | specific language governing permissions and limitations |
| 17 | under the License. |
| 18 | */ |
| 19 | |
| 20 | package amqpscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/ |
| 21 | |
| 22 | // #include <proton/codec.h> |
| 23 | import "C" |
| 24 | |
| 25 | import ( |
| 26 | "bytesscip-go gomod github.com/golang/go/src go1.11 bytes/" |
| 27 | "fmtscip-go gomod github.com/golang/go/src go1.11 fmt/" |
| 28 | "ioscip-go gomod github.com/golang/go/src go1.11 io/" |
| 29 | "reflectscip-go gomod github.com/golang/go/src go1.11 reflect/" |
| 30 | "timescip-go gomod github.com/golang/go/src go1.11 time/" |
| 31 | "unsafescip-go gomod github.com/golang/go/src go1.11 unsafe/" |
| 32 | ) |
| 33 | |
| 34 | const minDecodescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/minDecode. = 1024 |
| 35 | |
| 36 | // Error returned if AMQP data cannot be unmarshaled as the desired Go type. |
| 37 | type UnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError# struct { |
| 38 | // The name of the AMQP type. |
| 39 | AMQPTypescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#AMQPType. string |
| 40 | // The Go type. |
| 41 | GoTypescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#GoType. reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.Typescip-go gomod github.com/golang/go/src go1.11 reflect/Type# |
| 42 | |
| 43 | sscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#s. string |
| 44 | } |
| 45 | |
| 46 | func (e UnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#) Errorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#Error().() string { return e.sscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#s. } |
| 47 | |
| 48 | // Error returned if there are not enough bytes to decode a complete AMQP value. |
| 49 | var EndOfDatascip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/EndOfData. = &UnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#{sscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#s.: "Not enough data for AMQP value"} |
| 50 | |
| 51 | var badDatascip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/badData. = &UnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#{sscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#s.: "Unexpected error in data"} |
| 52 | |
| 53 | func newUnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/newUnmarshalError().(pnType C.pn_type_t, v interface{}) *UnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError# { |
| 54 | e := &UnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#{ |
| 55 | AMQPTypescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#AMQPType.: C.pn_type_t(pnType).String(), |
| 56 | GoTypescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#GoType.: reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.11 reflect/TypeOf().(v), |
| 57 | } |
| 58 | if e.GoTypescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#GoType. == nil || e.GoTypescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#GoType..Kindscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Kind().() != reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.11 reflect/Ptr. { |
| 59 | e.sscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#s. = fmtscip-go gomod github.com/golang/go/src go1.11 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.11 fmt/Sprintf().("cannot unmarshal to Go type %v, not a pointer", e.GoTypescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#GoType.) |
| 60 | } else { |
| 61 | e.sscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#s. = fmtscip-go gomod github.com/golang/go/src go1.11 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.11 fmt/Sprintf().("cannot unmarshal AMQP %v to Go %v", e.AMQPTypescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#AMQPType., e.GoTypescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#GoType..Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Elem().()) |
| 62 | } |
| 63 | return e |
| 64 | } |
| 65 | |
| 66 | func doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data *C.pn_data_t, v interface{}) { |
| 67 | e := newUnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/newUnmarshalError().(C.pn_data_type(data), v) |
| 68 | panic(e) |
| 69 | } |
| 70 | |
| 71 | func doPanicMsgscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanicMsg().(data *C.pn_data_t, v interface{}, msg string) { |
| 72 | e := newUnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/newUnmarshalError().(C.pn_data_type(data), v) |
| 73 | e.sscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#s. = e.sscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#s. + ": " + msg |
| 74 | panic(e) |
| 75 | } |
| 76 | |
| 77 | func panicIfBadDatascip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicIfBadData().(data *C.pn_data_t, v interface{}) { |
| 78 | if C.pn_data_errno(data) != 0 { |
| 79 | doPanicMsgscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanicMsg().(data, v, PnErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/PnError().(C.pn_data_error(data)).Error()) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | func panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(ok bool, data *C.pn_data_t, v interface{}) { |
| 84 | if !ok { |
| 85 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | func checkOpscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/checkOp().(ok bool, v interface{}) { |
| 90 | if !ok { |
| 91 | panic(&badDatascip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/badData.) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // |
| 96 | // Decoding from a pn_data_t |
| 97 | // |
| 98 | // NOTE: we use panic() to signal a decoding error, simplifies decoding logic. |
| 99 | // We recover() at the highest possible level - i.e. in the exported Unmarshal or Decode. |
| 100 | // |
| 101 | |
| 102 | // Decoder decodes AMQP values from an io.Reader. |
| 103 | // |
| 104 | type Decoderscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder# struct { |
| 105 | readerscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#reader. ioscip-go gomod github.com/golang/go/src go1.11 io/.Readerscip-go gomod github.com/golang/go/src go1.11 io/Reader# |
| 106 | bufferscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#buffer. bytesscip-go gomod github.com/golang/go/src go1.11 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.11 bytes/Buffer# |
| 107 | } |
| 108 | |
| 109 | // NewDecoder returns a new decoder that reads from r. |
| 110 | // |
| 111 | // The decoder has it's own buffer and may read more data than required for the |
| 112 | // AMQP values requested. Use Buffered to see if there is data left in the |
| 113 | // buffer. |
| 114 | // |
| 115 | func NewDecoderscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/NewDecoder().(r ioscip-go gomod github.com/golang/go/src go1.11 io/.Readerscip-go gomod github.com/golang/go/src go1.11 io/Reader#) *Decoderscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder# { |
| 116 | return &Decoderscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#{r, bytesscip-go gomod github.com/golang/go/src go1.11 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.11 bytes/Buffer#{}} |
| 117 | } |
| 118 | |
| 119 | // Buffered returns a reader of the data remaining in the Decoder's buffer. The |
| 120 | // reader is valid until the next call to Decode. |
| 121 | // |
| 122 | func (d *Decoderscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#) Bufferedscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#Buffered().() ioscip-go gomod github.com/golang/go/src go1.11 io/.Readerscip-go gomod github.com/golang/go/src go1.11 io/Reader# { |
| 123 | return bytesscip-go gomod github.com/golang/go/src go1.11 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.11 bytes/NewReader().(d.bufferscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#buffer..Bytesscip-go gomod github.com/golang/go/src go1.11 bytes/Buffer#Bytes().()) |
| 124 | } |
| 125 | |
| 126 | // Decode reads the next AMQP value from the Reader and stores it in the value pointed to by v. |
| 127 | // |
| 128 | // See the documentation for Unmarshal for details about the conversion of AMQP into a Go value. |
| 129 | // |
| 130 | func (d *Decoderscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#) Decodescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#Decode().(v interface{}) (err error) { |
| 131 | data := C.pn_data(0) |
| 132 | defer C.pn_data_free(data) |
| 133 | var n int |
| 134 | for n, err = decodescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/decode().(data, d.bufferscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#buffer..Bytesscip-go gomod github.com/golang/go/src go1.11 bytes/Buffer#Bytes().()); err == EndOfDatascip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/EndOfData.; { |
| 135 | err = d.morescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#more().() |
| 136 | if err == nil { |
| 137 | n, err = decodescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/decode().(data, d.bufferscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#buffer..Bytesscip-go gomod github.com/golang/go/src go1.11 bytes/Buffer#Bytes().()) |
| 138 | } |
| 139 | } |
| 140 | if err == nil { |
| 141 | if err = recoverUnmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/recoverUnmarshal().(v, data); err == nil { |
| 142 | d.bufferscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#buffer..Nextscip-go gomod github.com/golang/go/src go1.11 bytes/Buffer#Next().(n) |
| 143 | } |
| 144 | } |
| 145 | return |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | |
| 150 | Unmarshal decodes AMQP-encoded bytes and stores the result in the Go value |
| 151 | pointed to by v. Legal conversions from the source AMQP type to the target Go |
| 152 | type as follows: |
| 153 | |
| 154 | +----------------------------+-------------------------------------------------+ |
| 155 | |Target Go type | Allowed AMQP types |
| 156 | +============================+==================================================+ |
| 157 | |bool |bool | |
| 158 | +----------------------------+--------------------------------------------------+ |
| 159 | |int, int8, int16, int32, |Equivalent or smaller signed integer type: | |
| 160 | |int64 |byte, short, int, long or char | |
| 161 | +----------------------------+--------------------------------------------------+ |
| 162 | |uint, uint8, uint16, uint32,|Equivalent or smaller unsigned integer type: | |
| 163 | |uint64 |ubyte, ushort, uint, ulong | |
| 164 | +----------------------------+--------------------------------------------------+ |
| 165 | |float32, float64 |Equivalent or smaller float or double | |
| 166 | +----------------------------+--------------------------------------------------+ |
| 167 | |string, []byte |string, symbol or binary | |
| 168 | +----------------------------+--------------------------------------------------+ |
| 169 | |Symbol |symbol | |
| 170 | +----------------------------+--------------------------------------------------+ |
| 171 | |Char |char | |
| 172 | +----------------------------+--------------------------------------------------+ |
| 173 | |Described |AMQP described type [1] | |
| 174 | +----------------------------+--------------------------------------------------+ |
| 175 | |Time |timestamp | |
| 176 | +----------------------------+--------------------------------------------------+ |
| 177 | |UUID |uuid | |
| 178 | +----------------------------+--------------------------------------------------+ |
| 179 | |map[interface{}]interface{} |Any AMQP map | |
| 180 | +----------------------------+--------------------------------------------------+ |
| 181 | |map[K]T |map, provided all keys and values can unmarshal | |
| 182 | | |to types K,T | |
| 183 | +----------------------------+--------------------------------------------------+ |
| 184 | |[]interface{} |AMQP list or array | |
| 185 | +----------------------------+--------------------------------------------------+ |
| 186 | |[]T |list or array if elements can unmarshal as T | |
| 187 | +----------------------------+------------------n-------------------------------+ |
| 188 | |interface{} |any AMQP type[2] | |
| 189 | +----------------------------+--------------------------------------------------+ |
| 190 | |
| 191 | [1] An AMQP described value can also unmarshal to a plain value, discarding the |
| 192 | descriptor. Unmarshalling into the special amqp.Described type preserves the |
| 193 | descriptor. |
| 194 | |
| 195 | [2] Any AMQP value can be unmarshalled to an interface{}. The Go type is |
| 196 | determined by the AMQP type as follows: |
| 197 | |
| 198 | +----------------------------+--------------------------------------------------+ |
| 199 | |Source AMQP Type |Go Type in target interface{} | |
| 200 | +============================+==================================================+ |
| 201 | |bool |bool | |
| 202 | +----------------------------+--------------------------------------------------+ |
| 203 | |byte,short,int,long |int8,int16,int32,int64 | |
| 204 | +----------------------------+--------------------------------------------------+ |
| 205 | |ubyte,ushort,uint,ulong |uint8,uint16,uint32,uint64 | |
| 206 | +----------------------------+--------------------------------------------------+ |
| 207 | |float, double |float32, float64 | |
| 208 | +----------------------------+--------------------------------------------------+ |
| 209 | |string |string | |
| 210 | +----------------------------+--------------------------------------------------+ |
| 211 | |symbol |Symbol | |
| 212 | +----------------------------+--------------------------------------------------+ |
| 213 | |char |Char | |
| 214 | +----------------------------+--------------------------------------------------+ |
| 215 | |binary |Binary | |
| 216 | +----------------------------+--------------------------------------------------+ |
| 217 | |null |nil | |
| 218 | +----------------------------+--------------------------------------------------+ |
| 219 | |described type |Described | |
| 220 | +----------------------------+--------------------------------------------------+ |
| 221 | |timestamp |time.Time | |
| 222 | +----------------------------+--------------------------------------------------+ |
| 223 | |uuid |UUID | |
| 224 | +----------------------------+--------------------------------------------------+ |
| 225 | |map |Map or AnyMap[4] | |
| 226 | +----------------------------+--------------------------------------------------+ |
| 227 | |list |List | |
| 228 | +----------------------------+--------------------------------------------------+ |
| 229 | |array |[]T for simple types, T is chosen as above [3] | |
| 230 | +----------------------------+--------------------------------------------------+ |
| 231 | |
| 232 | [3] An AMQP array of simple types unmarshalls as a slice of the corresponding Go type. |
| 233 | An AMQP array containing complex types (lists, maps or nested arrays) unmarshals |
| 234 | to the generic array type amqp.Array |
| 235 | |
| 236 | [4] An AMQP map unmarshals as the generic `type Map map[interface{}]interface{}` |
| 237 | unless it contains key values that are illegal as Go map types, in which case |
| 238 | it unmarshals as type AnyMap. |
| 239 | |
| 240 | The following Go types cannot be unmarshaled: uintptr, function, interface, |
| 241 | channel, array (use slice), struct |
| 242 | |
| 243 | AMQP types not yet supported: decimal32/64/128 |
| 244 | */ |
| 245 | func Unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Unmarshal().(bytes []byte, v interface{}) (n int, err error) { |
| 246 | data := C.pn_data(0) |
| 247 | defer C.pn_data_free(data) |
| 248 | n, err = decodescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/decode().(data, bytes) |
| 249 | if err == nil { |
| 250 | err = recoverUnmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/recoverUnmarshal().(v, data) |
| 251 | } |
| 252 | return |
| 253 | } |
| 254 | |
| 255 | // Internal |
| 256 | func UnmarshalUnsafescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalUnsafe().(pnData unsafescip-go gomod github.com/golang/go/src go1.11 unsafe/.Pointer, v interface{}) (err error) { |
| 257 | return recoverUnmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/recoverUnmarshal().(v, (*C.pn_data_t)(pnData)) |
| 258 | } |
| 259 | |
| 260 | // more reads more data when we can't parse a complete AMQP type |
| 261 | func (d *Decoderscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#) morescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#more().() error { |
| 262 | var readSize int64 = minDecodescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/minDecode. |
| 263 | if int64(d.bufferscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#buffer..Lenscip-go gomod github.com/golang/go/src go1.11 bytes/Buffer#Len().()) > readSize { // Grow by doubling |
| 264 | readSize = int64(d.bufferscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#buffer..Lenscip-go gomod github.com/golang/go/src go1.11 bytes/Buffer#Len().()) |
| 265 | } |
| 266 | var n int64 |
| 267 | n, err := d.bufferscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#buffer..ReadFromscip-go gomod github.com/golang/go/src go1.11 bytes/Buffer#ReadFrom().(ioscip-go gomod github.com/golang/go/src go1.11 io/.LimitReaderscip-go gomod github.com/golang/go/src go1.11 io/LimitReader().(d.readerscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Decoder#reader., readSize)) |
| 268 | if n == 0 && err == nil { // ReadFrom won't report io.EOF, just returns 0 |
| 269 | err = ioscip-go gomod github.com/golang/go/src go1.11 io/.EOFscip-go gomod github.com/golang/go/src go1.11 io/EOF. |
| 270 | } |
| 271 | return err |
| 272 | } |
| 273 | |
| 274 | // Call unmarshal(), convert panic to error value |
| 275 | func recoverUnmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/recoverUnmarshal().(v interface{}, data *C.pn_data_t) (err error) { |
| 276 | defer func() { |
| 277 | if r := recover(); r != nil { |
| 278 | if uerr, ok := r.(*UnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#); ok { |
| 279 | err = uerr |
| 280 | } else { |
| 281 | panic(r) |
| 282 | } |
| 283 | } |
| 284 | }() |
| 285 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(v, data) |
| 286 | return nil |
| 287 | } |
| 288 | |
| 289 | // Unmarshal from data into value pointed at by v. Returns v. |
| 290 | // NOTE: If you update this you also need to update getInterface() |
| 291 | func unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(v interface{}, data *C.pn_data_t) { |
| 292 | rt := reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.11 reflect/TypeOf().(v) |
| 293 | rv := reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.11 reflect/ValueOf().(v) |
| 294 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(v != nil && rt.Kindscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.11 reflect/Ptr. && !rv.IsNilscip-go gomod github.com/golang/go/src go1.11 reflect/Value#IsNil().(), data, v) |
| 295 | |
| 296 | // Check for PN_DESCRIBED first, as described types can unmarshal into any of the Go types. |
| 297 | // An interface{} target is handled in the switch below, even for described types. |
| 298 | if _, isInterface := v.(*interface{}); !isInterface && bool(C.pn_data_is_described(data)) { |
| 299 | getDescribedscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getDescribed().(data, v) |
| 300 | return |
| 301 | } |
| 302 | |
| 303 | // Unmarshal based on the target type |
| 304 | pnType := C.pn_data_type(data) |
| 305 | switch v := v.(type) { |
| 306 | |
| 307 | case *bool: |
| 308 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_BOOL, data, v) |
| 309 | *v = bool(C.pn_data_get_bool(data)) |
| 310 | |
| 311 | case *int8: |
| 312 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_BYTE, data, v) |
| 313 | *v = int8(C.pn_data_get_byte(data)) |
| 314 | |
| 315 | case *uint8: |
| 316 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_UBYTE, data, v) |
| 317 | *v = uint8(C.pn_data_get_ubyte(data)) |
| 318 | |
| 319 | case *int16: |
| 320 | switch C.pn_data_type(data) { |
| 321 | case C.PN_BYTE: |
| 322 | *v = int16(C.pn_data_get_byte(data)) |
| 323 | case C.PN_SHORT: |
| 324 | *v = int16(C.pn_data_get_short(data)) |
| 325 | default: |
| 326 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 327 | } |
| 328 | |
| 329 | case *uint16: |
| 330 | switch pnType { |
| 331 | case C.PN_UBYTE: |
| 332 | *v = uint16(C.pn_data_get_ubyte(data)) |
| 333 | case C.PN_USHORT: |
| 334 | *v = uint16(C.pn_data_get_ushort(data)) |
| 335 | default: |
| 336 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 337 | } |
| 338 | |
| 339 | case *int32: |
| 340 | switch pnType { |
| 341 | case C.PN_CHAR: |
| 342 | *v = int32(C.pn_data_get_char(data)) |
| 343 | case C.PN_BYTE: |
| 344 | *v = int32(C.pn_data_get_byte(data)) |
| 345 | case C.PN_SHORT: |
| 346 | *v = int32(C.pn_data_get_short(data)) |
| 347 | case C.PN_INT: |
| 348 | *v = int32(C.pn_data_get_int(data)) |
| 349 | default: |
| 350 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 351 | } |
| 352 | |
| 353 | case *uint32: |
| 354 | switch pnType { |
| 355 | case C.PN_CHAR: |
| 356 | *v = uint32(C.pn_data_get_char(data)) |
| 357 | case C.PN_UBYTE: |
| 358 | *v = uint32(C.pn_data_get_ubyte(data)) |
| 359 | case C.PN_USHORT: |
| 360 | *v = uint32(C.pn_data_get_ushort(data)) |
| 361 | case C.PN_UINT: |
| 362 | *v = uint32(C.pn_data_get_uint(data)) |
| 363 | default: |
| 364 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 365 | } |
| 366 | |
| 367 | case *int64: |
| 368 | switch pnType { |
| 369 | case C.PN_CHAR: |
| 370 | *v = int64(C.pn_data_get_char(data)) |
| 371 | case C.PN_BYTE: |
| 372 | *v = int64(C.pn_data_get_byte(data)) |
| 373 | case C.PN_SHORT: |
| 374 | *v = int64(C.pn_data_get_short(data)) |
| 375 | case C.PN_INT: |
| 376 | *v = int64(C.pn_data_get_int(data)) |
| 377 | case C.PN_LONG: |
| 378 | *v = int64(C.pn_data_get_long(data)) |
| 379 | default: |
| 380 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 381 | } |
| 382 | |
| 383 | case *uint64: |
| 384 | switch pnType { |
| 385 | case C.PN_CHAR: |
| 386 | *v = uint64(C.pn_data_get_char(data)) |
| 387 | case C.PN_UBYTE: |
| 388 | *v = uint64(C.pn_data_get_ubyte(data)) |
| 389 | case C.PN_USHORT: |
| 390 | *v = uint64(C.pn_data_get_ushort(data)) |
| 391 | case C.PN_ULONG: |
| 392 | *v = uint64(C.pn_data_get_ulong(data)) |
| 393 | default: |
| 394 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 395 | } |
| 396 | |
| 397 | case *int: |
| 398 | switch pnType { |
| 399 | case C.PN_CHAR: |
| 400 | *v = int(C.pn_data_get_char(data)) |
| 401 | case C.PN_BYTE: |
| 402 | *v = int(C.pn_data_get_byte(data)) |
| 403 | case C.PN_SHORT: |
| 404 | *v = int(C.pn_data_get_short(data)) |
| 405 | case C.PN_INT: |
| 406 | *v = int(C.pn_data_get_int(data)) |
| 407 | case C.PN_LONG: |
| 408 | if intIs64scip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/intIs64. { |
| 409 | *v = int(C.pn_data_get_long(data)) |
| 410 | } else { |
| 411 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 412 | } |
| 413 | default: |
| 414 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 415 | } |
| 416 | |
| 417 | case *uint: |
| 418 | switch pnType { |
| 419 | case C.PN_CHAR: |
| 420 | *v = uint(C.pn_data_get_char(data)) |
| 421 | case C.PN_UBYTE: |
| 422 | *v = uint(C.pn_data_get_ubyte(data)) |
| 423 | case C.PN_USHORT: |
| 424 | *v = uint(C.pn_data_get_ushort(data)) |
| 425 | case C.PN_UINT: |
| 426 | *v = uint(C.pn_data_get_uint(data)) |
| 427 | case C.PN_ULONG: |
| 428 | if intIs64scip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/intIs64. { |
| 429 | *v = uint(C.pn_data_get_ulong(data)) |
| 430 | } else { |
| 431 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 432 | } |
| 433 | default: |
| 434 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 435 | } |
| 436 | |
| 437 | case *float32: |
| 438 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_FLOAT, data, v) |
| 439 | *v = float32(C.pn_data_get_float(data)) |
| 440 | |
| 441 | case *float64: |
| 442 | switch pnType { |
| 443 | case C.PN_FLOAT: |
| 444 | *v = float64(C.pn_data_get_float(data)) |
| 445 | case C.PN_DOUBLE: |
| 446 | *v = float64(C.pn_data_get_double(data)) |
| 447 | default: |
| 448 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 449 | } |
| 450 | |
| 451 | case *string: |
| 452 | switch pnType { |
| 453 | case C.PN_STRING: |
| 454 | *v = goStringscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goString().(C.pn_data_get_string(data)) |
| 455 | case C.PN_SYMBOL: |
| 456 | *v = goStringscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goString().(C.pn_data_get_symbol(data)) |
| 457 | case C.PN_BINARY: |
| 458 | *v = goStringscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goString().(C.pn_data_get_binary(data)) |
| 459 | default: |
| 460 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 461 | } |
| 462 | |
| 463 | case *[]byte: |
| 464 | switch pnType { |
| 465 | case C.PN_STRING: |
| 466 | *v = goBytesscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goBytes().(C.pn_data_get_string(data)) |
| 467 | case C.PN_SYMBOL: |
| 468 | *v = goBytesscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goBytes().(C.pn_data_get_symbol(data)) |
| 469 | case C.PN_BINARY: |
| 470 | *v = goBytesscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goBytes().(C.pn_data_get_binary(data)) |
| 471 | default: |
| 472 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 473 | } |
| 474 | return |
| 475 | |
| 476 | case *Charscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Char#: |
| 477 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_CHAR, data, v) |
| 478 | *v = Charscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Char#(C.pn_data_get_char(data)) |
| 479 | |
| 480 | case *Binaryscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Binary#: |
| 481 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_BINARY, data, v) |
| 482 | *v = Binaryscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Binary#(goBytesscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goBytes().(C.pn_data_get_binary(data))) |
| 483 | |
| 484 | case *Symbolscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Symbol#: |
| 485 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_SYMBOL, data, v) |
| 486 | *v = Symbolscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Symbol#(goBytesscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goBytes().(C.pn_data_get_symbol(data))) |
| 487 | |
| 488 | case *timescip-go gomod github.com/golang/go/src go1.11 time/.Timescip-go gomod github.com/golang/go/src go1.11 time/Time#: |
| 489 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_TIMESTAMP, data, v) |
| 490 | *v = goTimescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goTime().(C.pn_data_get_timestamp(data)) |
| 491 | |
| 492 | case *UUIDscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UUID#: |
| 493 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_UUID, data, v) |
| 494 | pn := C.pn_data_get_uuid(data) |
| 495 | copy((*v)[:], C.GoBytes(unsafescip-go gomod github.com/golang/go/src go1.11 unsafe/.Pointer(&pn.bytes), 16)) |
| 496 | |
| 497 | case *AnnotationKeyscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/AnnotationKey#: |
| 498 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(pnType == C.PN_ULONG || pnType == C.PN_SYMBOL || pnType == C.PN_STRING, data, v) |
| 499 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(&v.valuescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/AnnotationKey#value., data) |
| 500 | |
| 501 | case *AnyMapscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/AnyMap#: |
| 502 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(C.pn_data_type(data) == C.PN_MAP, data, v) |
| 503 | n := int(C.pn_data_get_map(data)) / 2 |
| 504 | if cap(*v) < n { |
| 505 | *v = make(AnyMapscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/AnyMap#, n) |
| 506 | } |
| 507 | *v = (*v)[:n] |
| 508 | data.enter(*v) |
| 509 | defer data.exit(*v) |
| 510 | for i := 0; i < n; i++ { |
| 511 | data.next(*v) |
| 512 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(&(*v)[i].Keyscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/KeyValue#Key., data) |
| 513 | data.next(*v) |
| 514 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(&(*v)[i].Valuescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/KeyValue#Value., data) |
| 515 | } |
| 516 | |
| 517 | case *interface{}: |
| 518 | getInterfacescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getInterface().(data, v) |
| 519 | |
| 520 | default: // This is not one of the fixed well-known types, reflect for map and slice types |
| 521 | |
| 522 | switch rt.Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Elem().().Kindscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Kind().() { |
| 523 | case reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.Mapscip-go gomod github.com/golang/go/src go1.11 reflect/Map.: |
| 524 | getMapscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getMap().(data, v) |
| 525 | case reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.Slicescip-go gomod github.com/golang/go/src go1.11 reflect/Slice.: |
| 526 | getSequencescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getSequence().(data, v) |
| 527 | default: |
| 528 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, v) |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | // Unmarshalling into an interface{} the type is determined by the AMQP source type, |
| 534 | // since the interface{} target can hold any Go type. |
| 535 | func getInterfacescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getInterface().(data *C.pn_data_t, vp *interface{}) { |
| 536 | pnType := C.pn_data_type(data) |
| 537 | switch pnType { |
| 538 | case C.PN_BOOL: |
| 539 | *vp = bool(C.pn_data_get_bool(data)) |
| 540 | case C.PN_UBYTE: |
| 541 | *vp = uint8(C.pn_data_get_ubyte(data)) |
| 542 | case C.PN_BYTE: |
| 543 | *vp = int8(C.pn_data_get_byte(data)) |
| 544 | case C.PN_USHORT: |
| 545 | *vp = uint16(C.pn_data_get_ushort(data)) |
| 546 | case C.PN_SHORT: |
| 547 | *vp = int16(C.pn_data_get_short(data)) |
| 548 | case C.PN_UINT: |
| 549 | *vp = uint32(C.pn_data_get_uint(data)) |
| 550 | case C.PN_INT: |
| 551 | *vp = int32(C.pn_data_get_int(data)) |
| 552 | case C.PN_CHAR: |
| 553 | *vp = Charscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Char#(C.pn_data_get_char(data)) |
| 554 | case C.PN_ULONG: |
| 555 | *vp = uint64(C.pn_data_get_ulong(data)) |
| 556 | case C.PN_LONG: |
| 557 | *vp = int64(C.pn_data_get_long(data)) |
| 558 | case C.PN_FLOAT: |
| 559 | *vp = float32(C.pn_data_get_float(data)) |
| 560 | case C.PN_DOUBLE: |
| 561 | *vp = float64(C.pn_data_get_double(data)) |
| 562 | case C.PN_BINARY: |
| 563 | *vp = Binaryscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Binary#(goBytesscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goBytes().(C.pn_data_get_binary(data))) |
| 564 | case C.PN_STRING: |
| 565 | *vp = goStringscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goString().(C.pn_data_get_string(data)) |
| 566 | case C.PN_SYMBOL: |
| 567 | *vp = Symbolscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Symbol#(goStringscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goString().(C.pn_data_get_symbol(data))) |
| 568 | case C.PN_TIMESTAMP: |
| 569 | *vp = goTimescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/goTime().(C.pn_data_get_timestamp(data)) |
| 570 | case C.PN_UUID: |
| 571 | var u UUIDscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UUID# |
| 572 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(&u, data) |
| 573 | *vp = u |
| 574 | case C.PN_MAP: |
| 575 | // We will try to unmarshal as a Map first, if that fails try AnyMap |
| 576 | m := make(Mapscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Map#, int(C.pn_data_get_map(data))/2) |
| 577 | if err := recoverUnmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/recoverUnmarshal().(&m, data); err == nil { |
| 578 | *vp = m |
| 579 | } else { |
| 580 | am := make(AnyMapscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/AnyMap#, int(C.pn_data_get_map(data))/2) |
| 581 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(&am, data) |
| 582 | *vp = am |
| 583 | } |
| 584 | case C.PN_LIST: |
| 585 | l := Listscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/List#{} |
| 586 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(&l, data) |
| 587 | *vp = l |
| 588 | case C.PN_ARRAY: |
| 589 | sp := getArrayStorescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getArrayStore().(data) // interface{} containing T* for suitable T |
| 590 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(sp, data) |
| 591 | *vp = reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.11 reflect/ValueOf().(sp).Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Elem().().Interfacescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Interface().() |
| 592 | case C.PN_DESCRIBED: |
| 593 | d := Describedscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Described#{} |
| 594 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(&d, data) |
| 595 | *vp = d |
| 596 | case C.PN_NULL: |
| 597 | *vp = nil |
| 598 | case C.PN_INVALID: |
| 599 | // Allow decoding from an empty data object to an interface, treat it like NULL. |
| 600 | // This happens when optional values or properties are omitted from a message. |
| 601 | *vp = nil |
| 602 | default: // Don't know how to handle this |
| 603 | panic(newUnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/newUnmarshalError().(pnType, vp)) |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | // Return an interface{} containing a pointer to an appropriate slice or Array |
| 608 | func getArrayStorescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getArrayStore().(data *C.pn_data_t) interface{} { |
| 609 | // TODO aconway 2017-11-10: described arrays. |
| 610 | switch C.pn_data_get_array_type(data) { |
| 611 | case C.PN_BOOL: |
| 612 | return new([]bool) |
| 613 | case C.PN_UBYTE: |
| 614 | return new([]uint8) |
| 615 | case C.PN_BYTE: |
| 616 | return new([]int8) |
| 617 | case C.PN_USHORT: |
| 618 | return new([]uint16) |
| 619 | case C.PN_SHORT: |
| 620 | return new([]int16) |
| 621 | case C.PN_UINT: |
| 622 | return new([]uint32) |
| 623 | case C.PN_INT: |
| 624 | return new([]int32) |
| 625 | case C.PN_CHAR: |
| 626 | return new([]Charscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Char#) |
| 627 | case C.PN_ULONG: |
| 628 | return new([]uint64) |
| 629 | case C.PN_LONG: |
| 630 | return new([]int64) |
| 631 | case C.PN_FLOAT: |
| 632 | return new([]float32) |
| 633 | case C.PN_DOUBLE: |
| 634 | return new([]float64) |
| 635 | case C.PN_BINARY: |
| 636 | return new([]Binaryscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Binary#) |
| 637 | case C.PN_STRING: |
| 638 | return new([]string) |
| 639 | case C.PN_SYMBOL: |
| 640 | return new([]Symbolscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Symbol#) |
| 641 | case C.PN_TIMESTAMP: |
| 642 | return new([]timescip-go gomod github.com/golang/go/src go1.11 time/.Timescip-go gomod github.com/golang/go/src go1.11 time/Time#) |
| 643 | case C.PN_UUID: |
| 644 | return new([]UUIDscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UUID#) |
| 645 | } |
| 646 | return new(Arrayscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Array#) // Not a simple type, use generic Array |
| 647 | } |
| 648 | |
| 649 | var typeOfInterfacescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/typeOfInterface. = reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.11 reflect/TypeOf().(interface{}(nil)) |
| 650 | |
| 651 | // get into map pointed at by v |
| 652 | func getMapscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getMap().(data *C.pn_data_t, v interface{}) { |
| 653 | panicUnlessscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/panicUnless().(C.pn_data_type(data) == C.PN_MAP, data, v) |
| 654 | n := int(C.pn_data_get_map(data)) / 2 |
| 655 | mapValue := reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.11 reflect/ValueOf().(v).Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Elem().() |
| 656 | mapValue.Setscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.MakeMapscip-go gomod github.com/golang/go/src go1.11 reflect/MakeMap().(mapValue.Typescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Type().())) // Clear the map |
| 657 | data.enter(v) |
| 658 | defer data.exit(v) |
| 659 | // Allocate re-usable key/val values |
| 660 | keyType := mapValue.Typescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Type().().Keyscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Key().() |
| 661 | keyPtr := reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.Newscip-go gomod github.com/golang/go/src go1.11 reflect/New().(keyType) |
| 662 | valPtr := reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.Newscip-go gomod github.com/golang/go/src go1.11 reflect/New().(mapValue.Typescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Type().().Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Elem().()) |
| 663 | for i := 0; i < n; i++ { |
| 664 | data.next(v) |
| 665 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(keyPtr.Interfacescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Interface().(), data) |
| 666 | if keyType.Kindscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.Interfacescip-go gomod github.com/golang/go/src go1.11 reflect/Interface. && !keyPtr.Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Elem().().Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Elem().().Typescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Type().().Comparablescip-go gomod github.com/golang/go/src go1.11 reflect/Type#Comparable().() { |
| 667 | doPanicMsgscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanicMsg().(data, v, fmtscip-go gomod github.com/golang/go/src go1.11 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.11 fmt/Sprintf().("key %#v is not comparable", keyPtr.Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Elem().().Interfacescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Interface().())) |
| 668 | } |
| 669 | data.next(v) |
| 670 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(valPtr.Interfacescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Interface().(), data) |
| 671 | mapValue.SetMapIndexscip-go gomod github.com/golang/go/src go1.11 reflect/Value#SetMapIndex().(keyPtr.Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Elem().(), valPtr.Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Elem().()) |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | func getSequencescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getSequence().(data *C.pn_data_t, vp interface{}) { |
| 676 | var count int |
| 677 | pnType := C.pn_data_type(data) |
| 678 | switch pnType { |
| 679 | case C.PN_LIST: |
| 680 | count = int(C.pn_data_get_list(data)) |
| 681 | case C.PN_ARRAY: |
| 682 | count = int(C.pn_data_get_array(data)) |
| 683 | default: |
| 684 | doPanicscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/doPanic().(data, vp) |
| 685 | } |
| 686 | listValue := reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.MakeSlicescip-go gomod github.com/golang/go/src go1.11 reflect/MakeSlice().(reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.TypeOfscip-go gomod github.com/golang/go/src go1.11 reflect/TypeOf().(vp).Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Elem().(), count, count) |
| 687 | data.enter(vp) |
| 688 | defer data.exit(vp) |
| 689 | for i := 0; i < count; i++ { |
| 690 | data.next(vp) |
| 691 | val := reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.Newscip-go gomod github.com/golang/go/src go1.11 reflect/New().(listValue.Typescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Type().().Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Type#Elem().()) |
| 692 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(val.Interfacescip-go gomod github.com/golang/go/src go1.11 reflect/Value#Interface().(), data) |
| 693 | listValue.Indexscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Index().(i).Setscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Set().(val.Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Elem().()) |
| 694 | } |
| 695 | reflectscip-go gomod github.com/golang/go/src go1.11 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.11 reflect/ValueOf().(vp).Elemscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Elem().().Setscip-go gomod github.com/golang/go/src go1.11 reflect/Value#Set().(listValue) |
| 696 | } |
| 697 | |
| 698 | func getDescribedscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/getDescribed().(data *C.pn_data_t, vp interface{}) { |
| 699 | d, isDescribed := vp.(*Describedscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Described#) |
| 700 | data.enter(vp) |
| 701 | defer data.exit(vp) |
| 702 | data.next(vp) |
| 703 | if isDescribed { |
| 704 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(&d.Descriptorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Described#Descriptor., data) |
| 705 | data.next(vp) |
| 706 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(&d.Valuescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/Described#Value., data) |
| 707 | } else { |
| 708 | data.next(vp) // Skip descriptor |
| 709 | unmarshalscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/unmarshal().(vp, data) // Unmarshal plain value |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | // decode from bytes. |
| 714 | // Return bytes decoded or 0 if we could not decode a complete object. |
| 715 | // |
| 716 | func decodescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/decode().(data *C.pn_data_t, bytes []byte) (int, error) { |
| 717 | n := C.pn_data_decode(data, cPtrscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/cPtr().(bytes), cLenscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/cLen().(bytes)) |
| 718 | if n == C.PN_UNDERFLOW { |
| 719 | C.pn_error_clear(C.pn_data_error(data)) |
| 720 | return 0, EndOfDatascip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/EndOfData. |
| 721 | } else if n <= 0 { |
| 722 | return 0, &UnmarshalErrorscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#{sscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/UnmarshalError#s.: fmtscip-go gomod github.com/golang/go/src go1.11 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.11 fmt/Sprintf().("unmarshal %v", PnErrorCodescip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/PnErrorCode#(n))} |
| 723 | } |
| 724 | return int(n), nil |
| 725 | } |
| 726 | |
| 727 | // Checked versions of pn_data functions |
| 728 | |
| 729 | func (data *C.pn_data_t) enterscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/enter().(v interface{}) { checkOpscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/checkOp().(bool(C.pn_data_enter(data)), v) } |
| 730 | func (data *C.pn_data_t) exitscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/exit().(v interface{}) { checkOpscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/checkOp().(bool(C.pn_data_exit(data)), v) } |
| 731 | func (data *C.pn_data_t) nextscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/next().(v interface{}) { checkOpscip-go gomod github.com/apache/qpid-proton . `github.com/apache/qpid-proton/go/pkg/amqp`/checkOp().(bool(C.pn_data_next(data)), v) } |