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 02:20:49 UTC

qpid-proton git commit: [PROTON-1432] [go] Support for AMQP char type [Forced Update!]

Repository: qpid-proton
Updated Branches:
  refs/heads/master b7d60a619 -> 9157a69a6 (forced update)


[PROTON-1432] [go] Support for AMQP char 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/9157a69a
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/9157a69a
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/9157a69a

Branch: refs/heads/master
Commit: 9157a69a60f953b5af79d632683dfc84b651b557
Parents: 99a1ad1
Author: Alan Conway <ac...@redhat.com>
Authored: Thu Nov 9 21:18:26 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Thu Nov 9 21:20:44 2017 -0500

----------------------------------------------------------------------
 .../go/src/qpid.apache.org/amqp/marshal.go      |  6 +++-
 .../go/src/qpid.apache.org/amqp/types.go        |  8 +++++
 .../go/src/qpid.apache.org/amqp/types_test.go   |  4 ++-
 .../go/src/qpid.apache.org/amqp/unmarshal.go    | 32 +++++++++++---------
 4 files changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9157a69a/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 a91e8d6..0f1c78d 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
@@ -86,6 +86,8 @@ Go types are encoded as follows
  +-------------------------------------+--------------------------------------------+
  |Symbol                               |symbol                                      |
  +-------------------------------------+--------------------------------------------+
+ |Char                                 |char                                        |
+ +-------------------------------------+--------------------------------------------+
  |interface{}                          |the contained type                          |
  +-------------------------------------+--------------------------------------------+
  |nil                                  |null                                        |
@@ -107,7 +109,7 @@ Go types are encoded as follows
 
 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, array.
+AMQP types not yet supported: decimal32/64/128, array.
 */
 func Marshal(v interface{}, buffer []byte) (outbuf []byte, err error) {
 	defer recoverMarshal(&err)
@@ -224,6 +226,8 @@ func marshal(v interface{}, data *C.pn_data_t) {
 		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])))
+	case Char:
+		C.pn_data_put_char(data, (C.pn_char_t)(v))
 	default:
 		switch reflect.TypeOf(v).Kind() {
 		case reflect.Map:

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9157a69a/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 245486f..8943ff3 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
@@ -226,3 +226,11 @@ 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:])
 }
+
+// Char is an AMQP unicode character, equivalent to a Go rune.
+// It is defined as a distinct type so it can be distinguished from an AMQP int
+type Char rune
+
+func (c Char) String() string {
+	return fmt.Sprintf("%c", c)
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9157a69a/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 46f5278..b9d6a40 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
@@ -28,7 +28,7 @@ import (
 
 func checkEqual(want interface{}, got interface{}) error {
 	if !reflect.DeepEqual(want, got) {
-		return fmt.Errorf("%s != %s", want, got)
+		return fmt.Errorf("%#v != %#v", want, got)
 	}
 	return nil
 }
@@ -70,6 +70,7 @@ var rtValues = []interface{}{
 	Described{"D", "V"},
 	timeValue,
 	UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
+	Char('\u2318'),
 }
 
 // Go values that unmarshal as an equivalent value but a different type
@@ -97,6 +98,7 @@ var vstrings = []string{
 	"{D V}",
 	fmt.Sprintf("%v", timeValue),
 	"UUID(01020304-0506-0708-090a-0b0c0d0e0f10)",
+	"\u2318",
 	// for oddValues
 	"-99", "99",
 	"[98 121 116 101]", /*"byte"*/

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9157a69a/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 9dc84c0..719b399 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
@@ -148,7 +148,7 @@ Types are converted as follows:
  |bool                    |bool                                             |
  +------------------------+-------------------------------------------------+
  |int, int8, int16, int32,|Equivalent or smaller signed integer type: byte, |
- |int64                   |short, int, long.                                |
+ |int64                   |short, int, long or char.                        |
  +------------------------+-------------------------------------------------+
  |uint, uint8, uint16,    |Equivalent or smaller unsigned integer type:     |
  |uint32, uint64          |ubyte, ushort, uint, ulong                       |
@@ -159,6 +159,8 @@ Types are converted as follows:
  +------------------------+-------------------------------------------------+
  |Symbol                  |symbol                                           |
  +------------------------+-------------------------------------------------+
+ |Char                    |char                                             |
+ +------------------------+-------------------------------------------------+
  |map[K]T                 |map, provided all keys and values can unmarshal  |
  |                        |to types K,T                                     |
  +------------------------+-------------------------------------------------+
@@ -168,6 +170,8 @@ Types are converted as follows:
  +------------------------+-------------------------------------------------+
  |Time                    |timestamp                                        |
  +------------------------+-------------------------------------------------+
+ |UUID                    |uuid                                             |
+ +--------------------------------------------------------------------------+
 
 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.
@@ -190,6 +194,8 @@ Any AMQP type can unmarshal to an interface{}, the Go type used to unmarshal is
  +------------------------+-------------------------------------------------+
  |symbol                  |Symbol                                           |
  +------------------------+-------------------------------------------------+
+ |char                    |Char                                             |
+ +------------------------+-------------------------------------------------+
  |binary                  |Binary                                           |
  +------------------------+-------------------------------------------------+
  |null                    |nil                                              |
@@ -207,7 +213,7 @@ Any AMQP type can unmarshal to an interface{}, the Go type used to unmarshal is
 
 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), maps with key values that are not legal Go map keys.
+AMQP types not yet supported: decimal32/64/128, maps with key values that are not legal Go map keys.
 */
 func Unmarshal(bytes []byte, v interface{}) (n int, err error) {
 	defer recoverUnmarshal(&err)
@@ -269,8 +275,6 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
 		}
 	case *int8:
 		switch pnType {
-		case C.PN_CHAR:
-			*v = int8(C.pn_data_get_char(data))
 		case C.PN_BYTE:
 			*v = int8(C.pn_data_get_byte(data))
 		default:
@@ -278,8 +282,6 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
 		}
 	case *uint8:
 		switch pnType {
-		case C.PN_CHAR:
-			*v = uint8(C.pn_data_get_char(data))
 		case C.PN_UBYTE:
 			*v = uint8(C.pn_data_get_ubyte(data))
 		default:
@@ -287,8 +289,6 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
 		}
 	case *int16:
 		switch pnType {
-		case C.PN_CHAR:
-			*v = int16(C.pn_data_get_char(data))
 		case C.PN_BYTE:
 			*v = int16(C.pn_data_get_byte(data))
 		case C.PN_SHORT:
@@ -298,8 +298,6 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
 		}
 	case *uint16:
 		switch pnType {
-		case C.PN_CHAR:
-			*v = uint16(C.pn_data_get_char(data))
 		case C.PN_UBYTE:
 			*v = uint16(C.pn_data_get_ubyte(data))
 		case C.PN_USHORT:
@@ -333,7 +331,6 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
 		default:
 			panic(newUnmarshalError(pnType, v))
 		}
-
 	case *int64:
 		switch pnType {
 		case C.PN_CHAR:
@@ -349,7 +346,6 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
 		default:
 			panic(newUnmarshalError(pnType, v))
 		}
-
 	case *uint64:
 		switch pnType {
 		case C.PN_CHAR:
@@ -363,7 +359,6 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
 		default:
 			panic(newUnmarshalError(pnType, v))
 		}
-
 	case *int:
 		switch pnType {
 		case C.PN_CHAR:
@@ -383,7 +378,6 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
 		default:
 			panic(newUnmarshalError(pnType, v))
 		}
-
 	case *uint:
 		switch pnType {
 		case C.PN_CHAR:
@@ -404,6 +398,14 @@ func unmarshal(v interface{}, data *C.pn_data_t) {
 			panic(newUnmarshalError(pnType, v))
 		}
 
+	case *Char:
+		switch pnType {
+		case C.PN_CHAR:
+			*v = Char(C.pn_data_get_char(data))
+		default:
+			panic(newUnmarshalError(pnType, v))
+		}
+
 	case *float32:
 		switch pnType {
 		case C.PN_FLOAT:
@@ -534,7 +536,7 @@ func getInterface(data *C.pn_data_t, v *interface{}) {
 	case C.PN_INT:
 		*v = int32(C.pn_data_get_int(data))
 	case C.PN_CHAR:
-		*v = uint8(C.pn_data_get_char(data))
+		*v = Char(C.pn_data_get_char(data))
 	case C.PN_ULONG:
 		*v = uint64(C.pn_data_get_ulong(data))
 	case C.PN_LONG:


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org