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/09 21:09:17 UTC
qpid-proton git commit: PROTON-1429: [go] Support for timestamp
Repository: qpid-proton
Updated Branches:
refs/heads/master 4856b6e18 -> 4edafb1a4
PROTON-1429: [go] Support for timestamp
Add support for marshaling/unmarshaling go time.Time values as AMQP timestamps.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4edafb1a
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4edafb1a
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4edafb1a
Branch: refs/heads/master
Commit: 4edafb1a473e3a0d9aa3b9498a3f5bba257aba0a
Parents: 4856b6e
Author: Alan Conway <ac...@redhat.com>
Authored: Thu Nov 9 16:08:35 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Thu Nov 9 16:08:35 2017 -0500
----------------------------------------------------------------------
.../go/src/qpid.apache.org/amqp/marshal.go | 13 ++++++------
.../go/src/qpid.apache.org/amqp/types_test.go | 13 ++++++++----
.../go/src/qpid.apache.org/amqp/unmarshal.go | 21 +++++++++++++++-----
3 files changed, 32 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4edafb1a/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 ca5e380..bbff055 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
@@ -26,6 +26,7 @@ import (
"fmt"
"io"
"reflect"
+ "time"
"unsafe"
)
@@ -99,14 +100,12 @@ Go types are encoded as follows
+-------------------------------------+--------------------------------------------+
|Described |described type |
+-------------------------------------+--------------------------------------------+
+ |time.Time |timestamp |
+ +-------------------------------------+--------------------------------------------+
-The following Go types cannot be marshaled: uintptr, function, channel, array (use slice), struct
-
-TODO: Not yet implemented:
-
-Go types: struct, complex64/128.
+The following Go types cannot be marshaled: uintptr, function, channel, array (use slice), struct, complex64/128.
-AMQP types: decimal32/64/128, char, timestamp, uuid, array.
+AMQP types not yet supported: decimal32/64/128, char, uuid, array.
*/
func Marshal(v interface{}, buffer []byte) (outbuf []byte, err error) {
defer recoverMarshal(&err)
@@ -219,6 +218,8 @@ func marshal(v interface{}, data *C.pn_data_t) {
C.pn_data_exit(data)
case AnnotationKey:
marshal(v.Get(), data)
+ case time.Time:
+ C.pn_data_put_timestamp(data, C.pn_timestamp_t(v.UnixNano()/1000))
default:
switch reflect.TypeOf(v).Kind() {
case reflect.Map:
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4edafb1a/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 959a558..0b95e06 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
@@ -23,11 +23,12 @@ import (
"fmt"
"reflect"
"testing"
+ "time"
)
func checkEqual(want interface{}, got interface{}) error {
if !reflect.DeepEqual(want, got) {
- return fmt.Errorf("%#v != %#v", want, got)
+ return fmt.Errorf("%s != %s", want, got)
}
return nil
}
@@ -53,6 +54,8 @@ func ExampleKey() {
// 42
}
+var timeValue = time.Now().Round(time.Millisecond)
+
// Values that are unchanged by a marshal/unmarshal round-trip from interface{}
// to interface{}
var rtValues = []interface{}{
@@ -65,6 +68,7 @@ var rtValues = []interface{}{
Map{"V": "X"},
List{"V", int32(1)},
Described{"D", "V"},
+ timeValue,
}
// Go values that unmarshal as an equivalent value but a different type
@@ -90,6 +94,7 @@ var vstrings = []string{
"map[V:X]",
"[V 1]",
"{D V}",
+ fmt.Sprintf("%v", timeValue),
// for oddValues
"-99", "99",
"[98 121 116 101]", /*"byte"*/
@@ -108,8 +113,8 @@ func TestTypesRoundTrip(t *testing.T) {
if err := checkUnmarshal(marshalled, &v); err != nil {
t.Error(err)
}
- if err := checkEqual(v, x); err != nil {
- t.Error(t, err)
+ if err := checkEqual(x, v); err != nil {
+ t.Error(err)
}
}
}
@@ -129,7 +134,7 @@ func TestTypesRoundTripAll(t *testing.T) {
t.Error(err)
}
v := vp.Elem().Interface()
- if err := checkEqual(v, x); err != nil {
+ if err := checkEqual(x, v); err != nil {
t.Error(err)
}
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4edafb1a/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 253d66d..d4220cd 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
@@ -28,6 +28,7 @@ import (
"io"
"reflect"
"strings"
+ "time"
"unsafe"
)
@@ -165,6 +166,8 @@ Types are converted as follows:
+------------------------+-------------------------------------------------+
|Described |described type |
+------------------------+-------------------------------------------------+
+ |Time |timestamp |
+ +------------------------+-------------------------------------------------+
An AMQP described type can unmarshal into the corresponding plain type, discarding the descriptor.
For example an AMQP described string can unmarshal into a plain go string.
@@ -197,14 +200,12 @@ Any AMQP type can unmarshal to an interface{}, the Go type used to unmarshal is
+------------------------+-------------------------------------------------+
|described type |Described |
+--------------------------------------------------------------------------+
+ |timestamp |time.Time |
+ +--------------------------------------------------------------------------+
The following Go types cannot be unmarshaled: uintptr, function, interface, channel, array (use slice), struct
-TODO: Not yet implemented:
-
-AMQP types: decimal32/64/128, char (round trip), timestamp, uuid.
-
-AMQP maps with mixed key types, or key types that are not legal Go map keys.
+AMQP types not yet supported: decimal32/64/128, char (round trip), uuid, maps with key values that are not legal Go map keys.
*/
func Unmarshal(bytes []byte, v interface{}) (n int, err error) {
defer recoverUnmarshal(&err)
@@ -459,6 +460,14 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
panic(newUnmarshalError(pnType, v))
}
+ case *time.Time:
+ switch pnType {
+ case C.PN_TIMESTAMP:
+ *v = time.Unix(0, int64(C.pn_data_get_timestamp(data))*1000)
+ default:
+ panic(newUnmarshalError(pnType, v))
+ }
+
case *interface{}:
getInterface(data, v)
@@ -541,6 +550,8 @@ func getInterface(data *C.pn_data_t, v *interface{}) {
d := Described{}
unmarshal(&d, data)
*v = d
+ case C.PN_TIMESTAMP:
+ *v = time.Unix(0, int64(C.pn_data_get_timestamp(data))*1000)
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