You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/11/10 01:50:02 UTC
qpid-proton git commit: PROTON-1430: [go] Support for AMQP UUID type
Repository: qpid-proton
Updated Branches:
refs/heads/master 4edafb1a4 -> 99a1ad156
PROTON-1430: [go] Support for AMQP UUID type
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/99a1ad15
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/99a1ad15
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/99a1ad15
Branch: refs/heads/master
Commit: 99a1ad156647d53f86e574acedeef7c344554c68
Parents: 4edafb1
Author: Alan Conway <ac...@redhat.com>
Authored: Thu Nov 9 20:49:43 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Thu Nov 9 20:49:43 2017 -0500
----------------------------------------------------------------------
.../go/src/qpid.apache.org/amqp/marshal.go | 6 +++++-
.../bindings/go/src/qpid.apache.org/amqp/types.go | 7 +++++++
.../go/src/qpid.apache.org/amqp/types_test.go | 2 ++
.../go/src/qpid.apache.org/amqp/unmarshal.go | 17 ++++++++++++++++-
4 files changed, 30 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/99a1ad15/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal.go
index bbff055..a91e8d6 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal.go
@@ -102,10 +102,12 @@ Go types are encoded as follows
+-------------------------------------+--------------------------------------------+
|time.Time |timestamp |
+-------------------------------------+--------------------------------------------+
+ |UUID |uuid |
+ +-------------------------------------+--------------------------------------------+
The following Go types cannot be marshaled: uintptr, function, channel, array (use slice), struct, complex64/128.
-AMQP types not yet supported: decimal32/64/128, char, uuid, array.
+AMQP types not yet supported: decimal32/64/128, char, array.
*/
func Marshal(v interface{}, buffer []byte) (outbuf []byte, err error) {
defer recoverMarshal(&err)
@@ -220,6 +222,8 @@ func marshal(v interface{}, data *C.pn_data_t) {
marshal(v.Get(), data)
case time.Time:
C.pn_data_put_timestamp(data, C.pn_timestamp_t(v.UnixNano()/1000))
+ case UUID:
+ C.pn_data_put_uuid(data, *(*C.pn_uuid_t)(unsafe.Pointer(&v[0])))
default:
switch reflect.TypeOf(v).Kind() {
case reflect.Map:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/99a1ad15/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go
index 9d41de6..245486f 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/types.go
@@ -219,3 +219,10 @@ type Described struct {
Descriptor interface{}
Value interface{}
}
+
+// UUID is an AMQP 128-bit Universally Unique Identifier, as defined by RFC-4122 section 4.1.2
+type UUID [16]byte
+
+func (u UUID) String() string {
+ return fmt.Sprintf("UUID(%x-%x-%x-%x-%x)", u[0:4], u[4:6], u[6:8], u[8:10], u[10:])
+}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/99a1ad15/proton-c/bindings/go/src/qpid.apache.org/amqp/types_test.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/types_test.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/types_test.go
index 0b95e06..46f5278 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/types_test.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/types_test.go
@@ -69,6 +69,7 @@ var rtValues = []interface{}{
List{"V", int32(1)},
Described{"D", "V"},
timeValue,
+ UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
}
// Go values that unmarshal as an equivalent value but a different type
@@ -95,6 +96,7 @@ var vstrings = []string{
"[V 1]",
"{D V}",
fmt.Sprintf("%v", timeValue),
+ "UUID(01020304-0506-0708-090a-0b0c0d0e0f10)",
// for oddValues
"-99", "99",
"[98 121 116 101]", /*"byte"*/
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/99a1ad15/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go
index d4220cd..9dc84c0 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/unmarshal.go
@@ -202,10 +202,12 @@ Any AMQP type can unmarshal to an interface{}, the Go type used to unmarshal is
+--------------------------------------------------------------------------+
|timestamp |time.Time |
+--------------------------------------------------------------------------+
+ |uuid |UUID |
+ +--------------------------------------------------------------------------+
The following Go types cannot be unmarshaled: uintptr, function, interface, channel, array (use slice), struct
-AMQP types not yet supported: decimal32/64/128, char (round trip), uuid, maps with key values that are not legal Go map keys.
+AMQP types not yet supported: decimal32/64/128, char (round trip), maps with key values that are not legal Go map keys.
*/
func Unmarshal(bytes []byte, v interface{}) (n int, err error) {
defer recoverUnmarshal(&err)
@@ -468,6 +470,15 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
panic(newUnmarshalError(pnType, v))
}
+ case *UUID:
+ switch pnType {
+ case C.PN_UUID:
+ pn := C.pn_data_get_uuid(data)
+ copy((*v)[:], C.GoBytes(unsafe.Pointer(&pn.bytes), 16))
+ default:
+ panic(newUnmarshalError(pnType, v))
+ }
+
case *interface{}:
getInterface(data, v)
@@ -552,6 +563,10 @@ func getInterface(data *C.pn_data_t, v *interface{}) {
*v = d
case C.PN_TIMESTAMP:
*v = time.Unix(0, int64(C.pn_data_get_timestamp(data))*1000)
+ case C.PN_UUID:
+ var u UUID
+ unmarshal(&u, data)
+ *v = u
case C.PN_NULL:
*v = nil
case C.PN_INVALID:
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org