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/06/09 01:26:10 UTC
[47/50] [abbrv] qpid-proton git commit: PROTON-1450: Rename
AnnotationKey, correct ApplicationProperties
PROTON-1450: Rename AnnotationKey, correct ApplicationProperties
Renamed Key->AnnotationKey and constructors XXXKey() to AnnotationKeyXXX()
ApplicationProperties map keyed by string in accordance with AMQP spec.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4cf899be
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4cf899be
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4cf899be
Branch: refs/heads/go1
Commit: 4cf899be7058fb47148a1d384aeb2ee46c1641e0
Parents: da959b6
Author: Alan Conway <ac...@redhat.com>
Authored: Thu Jun 8 17:13:10 2017 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Thu Jun 8 21:18:47 2017 -0400
----------------------------------------------------------------------
.../go/src/qpid.apache.org/amqp/marshal.go | 2 +-
.../go/src/qpid.apache.org/amqp/marshal_test.go | 12 +++---
.../go/src/qpid.apache.org/amqp/message.go | 42 +++++++++++---------
.../go/src/qpid.apache.org/amqp/message_test.go | 34 ++++++----------
.../go/src/qpid.apache.org/amqp/types.go | 14 +++----
.../go/src/qpid.apache.org/amqp/types_test.go | 4 +-
.../go/src/qpid.apache.org/amqp/unmarshal.go | 2 +-
7 files changed, 53 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4cf899be/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 04ecf04..dad3d25 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
@@ -209,7 +209,7 @@ func marshal(v interface{}, data *C.pn_data_t) {
marshal(v.Descriptor, data)
marshal(v.Value, data)
C.pn_data_exit(data)
- case Key:
+ case AnnotationKey:
marshal(v.Get(), data)
default:
switch reflect.TypeOf(v).Kind() {
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4cf899be/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal_test.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal_test.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal_test.go
index 2eda33c..d8e0711 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal_test.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/marshal_test.go
@@ -24,11 +24,11 @@ import (
)
func TestSymbolKey(t *testing.T) {
- bytes, err := Marshal(SymbolKey("foo"), nil)
+ bytes, err := Marshal(AnnotationKeySymbol("foo"), nil)
if err != nil {
t.Fatal(err)
}
- var k Key
+ var k AnnotationKey
if _, err := Unmarshal(bytes, &k); err != nil {
t.Error(err)
}
@@ -46,11 +46,11 @@ func TestSymbolKey(t *testing.T) {
}
func TestStringKey(t *testing.T) {
- bytes, err := Marshal(StringKey("foo"), nil)
+ bytes, err := Marshal(AnnotationKeyString("foo"), nil)
if err != nil {
t.Fatal(err)
}
- var k Key
+ var k AnnotationKey
if _, err := Unmarshal(bytes, &k); err != nil {
t.Error(err)
}
@@ -68,11 +68,11 @@ func TestStringKey(t *testing.T) {
}
func TestIntKey(t *testing.T) {
- bytes, err := Marshal(IntKey(12345), nil)
+ bytes, err := Marshal(AnnotationKeyUint64(12345), nil)
if err != nil {
t.Fatal(err)
}
- var k Key
+ var k AnnotationKey
if _, err := Unmarshal(bytes, &k); err != nil {
t.Error(err)
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4cf899be/proton-c/bindings/go/src/qpid.apache.org/amqp/message.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/message.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/message.go
index 9f4d7d1..f2270f0 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/message.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/message.go
@@ -119,18 +119,18 @@ type Message interface {
// Property map set by the application to be carried with the message.
// Values must be simple types (not maps, lists or sequences)
- ApplicationProperties() map[Key]interface{}
- SetApplicationProperties(map[Key]interface{})
+ ApplicationProperties() map[string]interface{}
+ SetApplicationProperties(map[string]interface{})
// Per-delivery annotations to provide delivery instructions.
// May be added or removed by intermediaries during delivery.
- DeliveryAnnotations() map[Key]interface{}
- SetDeliveryAnnotations(map[Key]interface{})
+ DeliveryAnnotations() map[AnnotationKey]interface{}
+ SetDeliveryAnnotations(map[AnnotationKey]interface{})
// Message annotations added as part of the bare message at creation, usually
// by an AMQP library. See ApplicationProperties() for adding application data.
- MessageAnnotations() map[Key]interface{}
- SetMessageAnnotations(map[Key]interface{})
+ MessageAnnotations() map[AnnotationKey]interface{}
+ SetMessageAnnotations(map[AnnotationKey]interface{})
// Inferred indicates how the message content
// is encoded into AMQP sections. If inferred is true then binary and
@@ -245,21 +245,27 @@ func (m *message) GroupId() string { return C.GoString(C.pn_message_get_g
func (m *message) GroupSequence() int32 { return int32(C.pn_message_get_group_sequence(m.pn)) }
func (m *message) ReplyToGroupId() string { return C.GoString(C.pn_message_get_reply_to_group_id(m.pn)) }
-func getAnnotations(data *C.pn_data_t) (v map[Key]interface{}) {
+func getAnnotations(data *C.pn_data_t) (v map[AnnotationKey]interface{}) {
C.pn_data_rewind(data)
C.pn_data_next(data)
unmarshal(&v, data)
return v
}
-func (m *message) DeliveryAnnotations() map[Key]interface{} {
+func (m *message) DeliveryAnnotations() map[AnnotationKey]interface{} {
return getAnnotations(C.pn_message_instructions(m.pn))
}
-func (m *message) MessageAnnotations() map[Key]interface{} {
+func (m *message) MessageAnnotations() map[AnnotationKey]interface{} {
return getAnnotations(C.pn_message_annotations(m.pn))
}
-func (m *message) ApplicationProperties() map[Key]interface{} {
- return getAnnotations(C.pn_message_properties(m.pn))
+
+func (m *message) ApplicationProperties() map[string]interface{} {
+ var v map[string]interface{}
+ data := C.pn_message_properties(m.pn)
+ C.pn_data_rewind(data)
+ C.pn_data_next(data)
+ unmarshal(&v, data)
+ return v
}
// ==== message set methods
@@ -314,13 +320,13 @@ func (m *message) SetReplyToGroupId(s string) {
C.msg_set_str(m.pn, C.CString(s), C.set_fn(C.pn_message_set_reply_to_group_id))
}
-func (m *message) SetDeliveryAnnotations(v map[Key]interface{}) {
+func (m *message) SetDeliveryAnnotations(v map[AnnotationKey]interface{}) {
setData(v, C.pn_message_instructions(m.pn))
}
-func (m *message) SetMessageAnnotations(v map[Key]interface{}) {
+func (m *message) SetMessageAnnotations(v map[AnnotationKey]interface{}) {
setData(v, C.pn_message_annotations(m.pn))
}
-func (m *message) SetApplicationProperties(v map[Key]interface{}) {
+func (m *message) SetApplicationProperties(v map[string]interface{}) {
setData(v, C.pn_message_properties(m.pn))
}
@@ -384,11 +390,11 @@ func (m *message) Properties() map[string]interface{} {
return oldGetAnnotations(C.pn_message_properties(m.pn))
}
-// Convert old string-keyed annotations to a Key map
-func fixAnnotations(old map[string]interface{}) (annotations map[Key]interface{}) {
- annotations = make(map[Key]interface{})
+// Convert old string-keyed annotations to an AnnotationKey map
+func fixAnnotations(old map[string]interface{}) (annotations map[AnnotationKey]interface{}) {
+ annotations = make(map[AnnotationKey]interface{})
for k, v := range old {
- annotations[StringKey(k)] = v
+ annotations[AnnotationKeyString(k)] = v
}
return
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4cf899be/proton-c/bindings/go/src/qpid.apache.org/amqp/message_test.go
----------------------------------------------------------------------
diff --git a/proton-c/bindings/go/src/qpid.apache.org/amqp/message_test.go b/proton-c/bindings/go/src/qpid.apache.org/amqp/message_test.go
index 3081cc5..bfebfa1 100644
--- a/proton-c/bindings/go/src/qpid.apache.org/amqp/message_test.go
+++ b/proton-c/bindings/go/src/qpid.apache.org/amqp/message_test.go
@@ -55,9 +55,9 @@ func TestDefaultMessage(t *testing.T) {
{m.ReplyToGroupId(), ""},
{m.MessageId(), nil},
{m.CorrelationId(), nil},
- {m.DeliveryAnnotations(), map[Key]interface{}{}},
- {m.MessageAnnotations(), map[Key]interface{}{}},
- {m.ApplicationProperties(), map[Key]interface{}{}},
+ {m.DeliveryAnnotations(), map[AnnotationKey]interface{}{}},
+ {m.MessageAnnotations(), map[AnnotationKey]interface{}{}},
+ {m.ApplicationProperties(), map[string]interface{}{}},
// Deprecated
{m.Instructions(), map[string]interface{}{}},
@@ -91,9 +91,9 @@ func TestMessageRoundTrip(t *testing.T) {
m.SetReplyToGroupId("replytogroup")
m.SetMessageId("id")
m.SetCorrelationId("correlation")
- m.SetDeliveryAnnotations(map[Key]interface{}{SymbolKey("instructions"): "foo"})
- m.SetMessageAnnotations(map[Key]interface{}{SymbolKey("annotations"): "bar"})
- m.SetApplicationProperties(map[Key]interface{}{SymbolKey("int"): int32(32), SymbolKey("bool"): true, IntKey(42): "42"})
+ m.SetDeliveryAnnotations(map[AnnotationKey]interface{}{AnnotationKeySymbol("instructions"): "foo"})
+ m.SetMessageAnnotations(map[AnnotationKey]interface{}{AnnotationKeySymbol("annotations"): "bar"})
+ m.SetApplicationProperties(map[string]interface{}{"int": int32(32), "bool": true})
m.Marshal("hello")
for _, data := range [][]interface{}{
@@ -113,9 +113,9 @@ func TestMessageRoundTrip(t *testing.T) {
{m.MessageId(), "id"},
{m.CorrelationId(), "correlation"},
- {m.DeliveryAnnotations(), map[Key]interface{}{SymbolKey("instructions"): "foo"}},
- {m.MessageAnnotations(), map[Key]interface{}{SymbolKey("annotations"): "bar"}},
- {m.ApplicationProperties(), map[Key]interface{}{SymbolKey("int"): int32(32), SymbolKey("bool"): true, IntKey(42): "42"}},
+ {m.DeliveryAnnotations(), map[AnnotationKey]interface{}{AnnotationKeySymbol("instructions"): "foo"}},
+ {m.MessageAnnotations(), map[AnnotationKey]interface{}{AnnotationKeySymbol("annotations"): "bar"}},
+ {m.ApplicationProperties(), map[string]interface{}{"int": int32(32), "bool": true}},
{m.Body(), "hello"},
// Deprecated
@@ -129,16 +129,6 @@ func TestMessageRoundTrip(t *testing.T) {
if err := roundTrip(m); err != nil {
t.Error(err)
}
-
- func() { // Expect a panic
- defer func() {
- if x, ok := recover().(*UnmarshalError); !ok {
- t.Errorf("Expected UnmarshalError, got %#v", x)
- }
- }()
- m.Properties()
- t.Error("Expected panic")
- }()
}
func TestDeprecated(t *testing.T) {
@@ -149,9 +139,9 @@ func TestDeprecated(t *testing.T) {
m.SetProperties(map[string]interface{}{"int": int32(32), "bool": true})
for _, data := range [][]interface{}{
- {m.DeliveryAnnotations(), map[Key]interface{}{SymbolKey("instructions"): "foo"}},
- {m.MessageAnnotations(), map[Key]interface{}{SymbolKey("annotations"): "bar"}},
- {m.ApplicationProperties(), map[Key]interface{}{SymbolKey("int"): int32(32), SymbolKey("bool"): true}},
+ {m.DeliveryAnnotations(), map[AnnotationKey]interface{}{AnnotationKeySymbol("instructions"): "foo"}},
+ {m.MessageAnnotations(), map[AnnotationKey]interface{}{AnnotationKeySymbol("annotations"): "bar"}},
+ {m.ApplicationProperties(), map[string]interface{}{"int": int32(32), "bool": true}},
{m.Instructions(), map[string]interface{}{"instructions": "foo"}},
{m.Annotations(), map[string]interface{}{"annotations": "bar"}},
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4cf899be/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 6e2ebc8..9d41de6 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
@@ -195,21 +195,21 @@ func cLen(b []byte) C.size_t {
return C.size_t(len(b))
}
-// Key is used as a map key for some AMQP "restricted" maps which are
+// AnnotationKey is used as a map key for AMQP annotation maps which are
// allowed to have keys that are either symbol or ulong but no other type.
//
-type Key struct {
+type AnnotationKey struct {
value interface{}
}
-func SymbolKey(v Symbol) Key { return Key{v} }
-func IntKey(v uint64) Key { return Key{v} }
-func StringKey(v string) Key { return Key{Symbol(v)} }
+func AnnotationKeySymbol(v Symbol) AnnotationKey { return AnnotationKey{v} }
+func AnnotationKeyUint64(v uint64) AnnotationKey { return AnnotationKey{v} }
+func AnnotationKeyString(v string) AnnotationKey { return AnnotationKey{Symbol(v)} }
// Returns the value which must be Symbol, uint64 or nil
-func (k Key) Get() interface{} { return k.value }
+func (k AnnotationKey) Get() interface{} { return k.value }
-func (k Key) String() string { return fmt.Sprintf("%v", k.Get()) }
+func (k AnnotationKey) String() string { return fmt.Sprintf("%v", k.Get()) }
// Described represents an AMQP described type, which is really
// just a pair of AMQP values - the first is treated as a "descriptor",
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4cf899be/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 096d27f..959a558 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
@@ -44,9 +44,9 @@ func checkUnmarshal(marshalled []byte, v interface{}) error {
}
func ExampleKey() {
- var k Key = SymbolKey(Symbol("foo"))
+ var k AnnotationKey = AnnotationKeySymbol(Symbol("foo"))
fmt.Println(k.Get().(Symbol))
- k = IntKey(42)
+ k = AnnotationKeyUint64(42)
fmt.Println(k.Get().(uint64))
// Output:
// foo
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4cf899be/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 b49727e..f679abc 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
@@ -455,7 +455,7 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
case *interface{}:
getInterface(data, v)
- case *Key:
+ case *AnnotationKey:
if pnType == C.PN_ULONG || pnType == C.PN_SYMBOL || pnType == C.PN_STRING {
unmarshal(&v.value, data)
} else {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org