From c7f535a631fd26012ad47616b1d9d86afab712dd Mon Sep 17 00:00:00 2001 From: johnabass Date: Sat, 28 May 2022 10:00:47 -0700 Subject: [PATCH 1/6] added qos; regenerated code --- messages_codec.go | 150 ++++++++++++++++++++++----------------------- qos.go | 36 +++++++++++ qoslevel_string.go | 26 ++++++++ 3 files changed, 137 insertions(+), 75 deletions(-) create mode 100644 qos.go create mode 100644 qoslevel_string.go diff --git a/messages_codec.go b/messages_codec.go index 0e43556..f369f98 100644 --- a/messages_codec.go +++ b/messages_codec.go @@ -14,28 +14,28 @@ import ( const ( // ----- content types ---- - codecSelferCcUTF82836 = 1 - codecSelferCcRAW2836 = 255 + codecSelferCcUTF8319 = 1 + codecSelferCcRAW319 = 255 // ----- value types used ---- - codecSelferValueTypeArray2836 = 10 - codecSelferValueTypeMap2836 = 9 - codecSelferValueTypeString2836 = 6 - codecSelferValueTypeInt2836 = 2 - codecSelferValueTypeUint2836 = 3 - codecSelferValueTypeFloat2836 = 4 - codecSelferValueTypeNil2836 = 1 - codecSelferBitsize2836 = uint8(32 << (^uint(0) >> 63)) - codecSelferDecContainerLenNil2836 = -2147483648 + codecSelferValueTypeArray319 = 10 + codecSelferValueTypeMap319 = 9 + codecSelferValueTypeString319 = 6 + codecSelferValueTypeInt319 = 2 + codecSelferValueTypeUint319 = 3 + codecSelferValueTypeFloat319 = 4 + codecSelferValueTypeNil319 = 1 + codecSelferBitsize319 = uint8(32 << (^uint(0) >> 63)) + codecSelferDecContainerLenNil319 = -2147483648 ) var ( - errCodecSelferOnlyMapOrArrayEncodeToStruct2836 = errors.New(`only encoded map or array can be decoded into a struct`) + errCodecSelferOnlyMapOrArrayEncodeToStruct319 = errors.New(`only encoded map or array can be decoded into a struct`) ) -type codecSelfer2836 struct{} +type codecSelfer319 struct{} -func codecSelfer2836False() bool { return false } -func codecSelfer2836True() bool { return true } +func codecSelfer319False() bool { return false } +func codecSelfer319True() bool { return true } func init() { if codec1978.GenVersion != 25 { @@ -47,7 +47,7 @@ func init() { func (Message) codecSelferViaCodecgen() {} func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -437,32 +437,32 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *Message) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil2836 { + if yyct2 == codecSelferValueTypeNil319 { *(x) = Message{} - } else if yyct2 == codecSelferValueTypeMap2836 { + } else if yyct2 == codecSelferValueTypeMap319 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray2836 { + } else if yyct2 == codecSelferValueTypeArray319 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct2836) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) } } func (x *Message) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -554,7 +554,7 @@ func (x *Message) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *Message) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj31 int @@ -828,7 +828,7 @@ func (x *Message) IsCodecEmpty() bool { func (SimpleRequestResponse) codecSelferViaCodecgen() {} func (x *SimpleRequestResponse) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -1146,32 +1146,32 @@ func (x *SimpleRequestResponse) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *SimpleRequestResponse) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil2836 { + if yyct2 == codecSelferValueTypeNil319 { *(x) = SimpleRequestResponse{} - } else if yyct2 == codecSelferValueTypeMap2836 { + } else if yyct2 == codecSelferValueTypeMap319 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray2836 { + } else if yyct2 == codecSelferValueTypeArray319 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct2836) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) } } func (x *SimpleRequestResponse) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -1255,7 +1255,7 @@ func (x *SimpleRequestResponse) codecDecodeSelfFromMap(l int, d *codec1978.Decod } func (x *SimpleRequestResponse) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj27 int @@ -1481,7 +1481,7 @@ func (x *SimpleRequestResponse) IsCodecEmpty() bool { func (SimpleEvent) codecSelferViaCodecgen() {} func (x *SimpleEvent) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -1674,32 +1674,32 @@ func (x *SimpleEvent) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *SimpleEvent) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil2836 { + if yyct2 == codecSelferValueTypeNil319 { *(x) = SimpleEvent{} - } else if yyct2 == codecSelferValueTypeMap2836 { + } else if yyct2 == codecSelferValueTypeMap319 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray2836 { + } else if yyct2 == codecSelferValueTypeArray319 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct2836) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) } } func (x *SimpleEvent) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -1746,7 +1746,7 @@ func (x *SimpleEvent) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *SimpleEvent) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj18 int @@ -1885,7 +1885,7 @@ func (x *SimpleEvent) IsCodecEmpty() bool { func (CRUD) codecSelferViaCodecgen() {} func (x *CRUD) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -2197,32 +2197,32 @@ func (x *CRUD) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *CRUD) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil2836 { + if yyct2 == codecSelferValueTypeNil319 { *(x) = CRUD{} - } else if yyct2 == codecSelferValueTypeMap2836 { + } else if yyct2 == codecSelferValueTypeMap319 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray2836 { + } else if yyct2 == codecSelferValueTypeArray319 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct2836) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) } } func (x *CRUD) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -2306,7 +2306,7 @@ func (x *CRUD) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *CRUD) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj27 int @@ -2532,7 +2532,7 @@ func (x *CRUD) IsCodecEmpty() bool { func (ServiceRegistration) codecSelferViaCodecgen() {} func (x *ServiceRegistration) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -2586,32 +2586,32 @@ func (x *ServiceRegistration) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *ServiceRegistration) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil2836 { + if yyct2 == codecSelferValueTypeNil319 { *(x) = ServiceRegistration{} - } else if yyct2 == codecSelferValueTypeMap2836 { + } else if yyct2 == codecSelferValueTypeMap319 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray2836 { + } else if yyct2 == codecSelferValueTypeArray319 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct2836) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) } } func (x *ServiceRegistration) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -2646,7 +2646,7 @@ func (x *ServiceRegistration) codecDecodeSelfFromMap(l int, d *codec1978.Decoder } func (x *ServiceRegistration) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj8 int @@ -2713,7 +2713,7 @@ func (x *ServiceRegistration) IsCodecEmpty() bool { func (ServiceAlive) codecSelferViaCodecgen() {} func (x *ServiceAlive) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -2751,32 +2751,32 @@ func (x *ServiceAlive) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *ServiceAlive) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil2836 { + if yyct2 == codecSelferValueTypeNil319 { *(x) = ServiceAlive{} - } else if yyct2 == codecSelferValueTypeMap2836 { + } else if yyct2 == codecSelferValueTypeMap319 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray2836 { + } else if yyct2 == codecSelferValueTypeArray319 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct2836) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) } } func (x *ServiceAlive) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -2807,7 +2807,7 @@ func (x *ServiceAlive) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *ServiceAlive) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int @@ -2850,7 +2850,7 @@ func (x *ServiceAlive) IsCodecEmpty() bool { func (Unknown) codecSelferViaCodecgen() {} func (x *Unknown) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -2888,32 +2888,32 @@ func (x *Unknown) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *Unknown) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil2836 { + if yyct2 == codecSelferValueTypeNil319 { *(x) = Unknown{} - } else if yyct2 == codecSelferValueTypeMap2836 { + } else if yyct2 == codecSelferValueTypeMap319 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray2836 { + } else if yyct2 == codecSelferValueTypeArray319 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct2836) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) } } func (x *Unknown) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -2944,7 +2944,7 @@ func (x *Unknown) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *Unknown) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer2836 + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int @@ -2985,8 +2985,8 @@ func (x *Unknown) IsCodecEmpty() bool { return !(x.Type != 0 || false) } -func (x codecSelfer2836) encSliceSlicestring(v [][]string, e *codec1978.Encoder) { - var h codecSelfer2836 +func (x codecSelfer319) encSliceSlicestring(v [][]string, e *codec1978.Encoder) { + var h codecSelfer319 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { @@ -3005,8 +3005,8 @@ func (x codecSelfer2836) encSliceSlicestring(v [][]string, e *codec1978.Encoder) z.EncWriteArrayEnd() } -func (x codecSelfer2836) decSliceSlicestring(v *[][]string, d *codec1978.Decoder) { - var h codecSelfer2836 +func (x codecSelfer319) decSliceSlicestring(v *[][]string, d *codec1978.Decoder) { + var h codecSelfer319 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r diff --git a/qos.go b/qos.go new file mode 100644 index 0000000..d7209f8 --- /dev/null +++ b/qos.go @@ -0,0 +1,36 @@ +package wrp + +//go:generate stringer -type=QOSLevel -linecomment + +// QOSLevel is the quality of service level associated with a WRP message. +type QOSLevel int + +const ( + QOSLow QOSLevel = iota // Low + QOSMedium // Medium + QOSHigh // High + QOSCritical // Critical +) + +// QOSValue is the quality of service value set in a WRP message. Values of this +// type determine what QOSLevel a message has. +type QOSValue int + +// Level determines the QOSLevel for this value. Negative values are assumed +// to be QOSLow. Values higher than the highest value (99) are assumed to +// be QOSCritical. +func (qv QOSValue) Level() QOSLevel { + switch { + case qv < 25: + return QOSLow + + case qv < 50: + return QOSMedium + + case qv < 75: + return QOSHigh + + default: + return QOSCritical + } +} diff --git a/qoslevel_string.go b/qoslevel_string.go new file mode 100644 index 0000000..61992bb --- /dev/null +++ b/qoslevel_string.go @@ -0,0 +1,26 @@ +// Code generated by "stringer -type=QOSLevel -linecomment"; DO NOT EDIT. + +package wrp + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[QOSLow-0] + _ = x[QOSMedium-1] + _ = x[QOSHigh-2] + _ = x[QOSCritical-3] +} + +const _QOSLevel_name = "LowMediumHighCritical" + +var _QOSLevel_index = [...]uint8{0, 3, 9, 13, 21} + +func (i QOSLevel) String() string { + if i < 0 || i >= QOSLevel(len(_QOSLevel_index)-1) { + return "QOSLevel(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _QOSLevel_name[_QOSLevel_index[i]:_QOSLevel_index[i+1]] +} From 0c9e90e75c0c871471519427d416f351c7774475 Mon Sep 17 00:00:00 2001 From: johnabass Date: Sat, 28 May 2022 10:09:05 -0700 Subject: [PATCH 2/6] fixed comments; deprecated structs other than Message --- messages.go | 80 +++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/messages.go b/messages.go index 9332d52..9a26f94 100644 --- a/messages.go +++ b/messages.go @@ -91,104 +91,82 @@ type Routable interface { // // swagger:response Message type Message struct { - // Type The message type for the message + // Type is the message type for the message. // - // required: true - // example: 4 + // example: SimpleRequestResponseMessageType Type MessageType `json:"msg_type"` - // Source The device_id name of the device originating the request or response. + // Source is the device_id name of the device originating the request or response. // - // required: false // example: dns:talaria.xmidt.example.com Source string `json:"source,omitempty"` - // Destination The device_id name of the target device of the request or response. + // Destination is the device_id name of the target device of the request or response. // - // required: false // example: event:device-status/mac:ffffffffdae4/online Destination string `json:"dest,omitempty"` // TransactionUUID The transaction key for the message // - // required: false // example: 546514d4-9cb6-41c9-88ca-ccd4c130c525 TransactionUUID string `json:"transaction_uuid,omitempty"` // ContentType The media type of the payload. // - // required: false // example: json ContentType string `json:"content_type,omitempty"` - // Accept The media type accepted in the response. - // - // required: false + // Accept is the media type accepted in the response. Accept string `json:"accept,omitempty"` - // Status The response status from the originating service. - // - // required: false + // Status is the response status from the originating service. Status *int64 `json:"status,omitempty"` - // RequestDeliveryResponse The request delivery response is the delivery result of the previous (implied request) - // message with a matching transaction_uuid - // - // required: false + // RequestDeliveryResponse is the request delivery response is the delivery result + // of the previous (implied request) message with a matching transaction_uuid RequestDeliveryResponse *int64 `json:"rdr,omitempty"` - // Headers The headers associated with the payload. - // - // required: false + // Headers is the headers associated with the payload. Headers []string `json:"headers,omitempty"` - // Metadata The map of name/value pairs used by consumers of WRP messages for filtering & other purposes. + // Metadata is the map of name/value pairs used by consumers of WRP messages for filtering & other purposes. // - // required: false // example: {"/boot-time":1542834188,"/last-reconnect-reason":"spanish inquisition"} Metadata map[string]string `json:"metadata,omitempty"` - // Spans An array of arrays of timing values as a list in the format: "parent" (string), "name" (string), + // Spans is an array of arrays of timing values as a list in the format: "parent" (string), "name" (string), // "start time" (int), "duration" (int), "status" (int) - // - // required: false Spans [][]string `json:"spans,omitempty"` - // IncludeSpans (Deprecated) If the timing values should be included in the response. + // IncludeSpans indicates whether timing values should be included in the response. // - // required: false + // Deprecated: A future version of wrp will remove this field. IncludeSpans *bool `json:"include_spans,omitempty"` - // Path The path to which to apply the payload. - // - // required: false + // Path is the path to which to apply the payload. Path string `json:"path,omitempty"` - // Payload The string encoded of the ContentType + // Payload is the payload for this message. It's format is expected to match ContentType. + // + // For JSON, this field must be a UTF-8 string. Binary payloads may be base64-encoded. + // + // For msgpack, this field may be raw binary or a UTF-8 string. // - // required: false // example: eyJpZCI6IjUiLCJ0cyI6IjIwMTktMDItMTJUMTE6MTA6MDIuNjE0MTkxNzM1WiIsImJ5dGVzLXNlbnQiOjAsIm1lc3NhZ2VzLXNlbnQiOjEsImJ5dGVzLXJlY2VpdmVkIjowLCJtZXNzYWdlcy1yZWNlaXZlZCI6MH0= Payload []byte `json:"payload,omitempty"` - // ServiceName The originating point of the request or response - // - // required: false + // ServiceName is the originating point of the request or response. ServiceName string `json:"service_name,omitempty"` - // URL The url to use when connecting to the nanomsg pipeline - // - // required: false + // URL is the url to use when connecting to the nanomsg pipeline. URL string `json:"url,omitempty"` - // PartnerIDs The list of partner ids the message is meant to target. + // PartnerIDs is the list of partner ids the message is meant to target. // - // required: false // example: ["hello","world"] PartnerIDs []string `json:"partner_ids,omitempty"` - // SessionID The ID for the current session with Talaria. - // - // required: false + // SessionID is the ID for the current session. SessionID string `json:"session_id,omitempty"` } @@ -247,6 +225,8 @@ func (msg *Message) SetIncludeSpans(value bool) *Message { // SimpleRequestResponse represents a WRP message of type SimpleRequestResponseMessageType. // // https://github.com/xmidt-org/wrp-c/wiki/Web-Routing-Protocol#simple-request-response-definition +// +// Deprecated: A future version of wrp will remove this type. type SimpleRequestResponse struct { // Type is exposed principally for encoding. This field *must* be set to SimpleRequestResponseMessageType, // and is automatically set by the BeforeEncode method. @@ -330,6 +310,8 @@ func (msg *SimpleRequestResponse) Response(newSource string, requestDeliveryResp // the Routable interface. // // https://github.com/xmidt-org/wrp-c/wiki/Web-Routing-Protocol#simple-event-definition +// +// Deprecated: A future version of wrp will remove this type. type SimpleEvent struct { // Type is exposed principally for encoding. This field *must* be set to SimpleEventMessageType, // and is automatically set by the BeforeEncode method. @@ -383,6 +365,8 @@ func (msg *SimpleEvent) Response(newSource string, requestDeliveryResponse int64 // and so does not automatically set the Type field. Client code must set the Type code appropriately. // // https://github.com/xmidt-org/wrp-c/wiki/Web-Routing-Protocol#crud-message-definition +// +// Deprecated: A future version of wrp will remove this type. type CRUD struct { Type MessageType `json:"msg_type"` Source string `json:"source"` @@ -450,6 +434,8 @@ func (msg *CRUD) Response(newSource string, requestDeliveryResponse int64) Routa // ServiceRegistration represents a WRP message of type ServiceRegistrationMessageType. // // https://github.com/xmidt-org/wrp-c/wiki/Web-Routing-Protocol#on-device-service-registration-message-definition +// +// Deprecated: A future version of wrp will remove this type. type ServiceRegistration struct { // Type is exposed principally for encoding. This field *must* be set to ServiceRegistrationMessageType, // and is automatically set by the BeforeEncode method. @@ -466,6 +452,8 @@ func (msg *ServiceRegistration) BeforeEncode() error { // ServiceAlive represents a WRP message of type ServiceAliveMessageType. // // https://github.com/xmidt-org/wrp-c/wiki/Web-Routing-Protocol#on-device-service-alive-message-definition +// +// Deprecated: A future version of wrp will remove this type. type ServiceAlive struct { // Type is exposed principally for encoding. This field *must* be set to ServiceAliveMessageType, // and is automatically set by the BeforeEncode method. @@ -480,6 +468,8 @@ func (msg *ServiceAlive) BeforeEncode() error { // Unknown represents a WRP message of type UnknownMessageType. // // https://github.com/xmidt-org/wrp-c/wiki/Web-Routing-Protocol#unknown-message-definition +// +// Deprecated: A future version of wrp will remove this type. type Unknown struct { // Type is exposed principally for encoding. This field *must* be set to UnknownMessageType, // and is automatically set by the BeforeEncode method. From 00cb1b86ff70cb8b5b0280e17860a7e5a13362fe Mon Sep 17 00:00:00 2001 From: johnabass Date: Sat, 28 May 2022 10:12:51 -0700 Subject: [PATCH 3/6] add the qos field; regenerated code --- messages.go | 5 + messages_codec.go | 431 +++++++++++++++++++++++++--------------------- 2 files changed, 241 insertions(+), 195 deletions(-) diff --git a/messages.go b/messages.go index 9a26f94..6b5e294 100644 --- a/messages.go +++ b/messages.go @@ -168,6 +168,11 @@ type Message struct { // SessionID is the ID for the current session. SessionID string `json:"session_id,omitempty"` + + // QualityOfService is the qos value associated with this message. Values between 0 and 99, inclusive, + // are defined by the wrp spec. Negative values are assumed to be zero, and values larger than 99 + // are assumed to be 99. + QualityOfService QOSValue `json:"qos"` } func (msg *Message) FindEventStringSubMatch() string { diff --git a/messages_codec.go b/messages_codec.go index f369f98..241da33 100644 --- a/messages_codec.go +++ b/messages_codec.go @@ -14,28 +14,28 @@ import ( const ( // ----- content types ---- - codecSelferCcUTF8319 = 1 - codecSelferCcRAW319 = 255 + codecSelferCcUTF85645 = 1 + codecSelferCcRAW5645 = 255 // ----- value types used ---- - codecSelferValueTypeArray319 = 10 - codecSelferValueTypeMap319 = 9 - codecSelferValueTypeString319 = 6 - codecSelferValueTypeInt319 = 2 - codecSelferValueTypeUint319 = 3 - codecSelferValueTypeFloat319 = 4 - codecSelferValueTypeNil319 = 1 - codecSelferBitsize319 = uint8(32 << (^uint(0) >> 63)) - codecSelferDecContainerLenNil319 = -2147483648 + codecSelferValueTypeArray5645 = 10 + codecSelferValueTypeMap5645 = 9 + codecSelferValueTypeString5645 = 6 + codecSelferValueTypeInt5645 = 2 + codecSelferValueTypeUint5645 = 3 + codecSelferValueTypeFloat5645 = 4 + codecSelferValueTypeNil5645 = 1 + codecSelferBitsize5645 = uint8(32 << (^uint(0) >> 63)) + codecSelferDecContainerLenNil5645 = -2147483648 ) var ( - errCodecSelferOnlyMapOrArrayEncodeToStruct319 = errors.New(`only encoded map or array can be decoded into a struct`) + errCodecSelferOnlyMapOrArrayEncodeToStruct5645 = errors.New(`only encoded map or array can be decoded into a struct`) ) -type codecSelfer319 struct{} +type codecSelfer5645 struct{} -func codecSelfer319False() bool { return false } -func codecSelfer319True() bool { return true } +func codecSelfer5645False() bool { return false } +func codecSelfer5645True() bool { return true } func init() { if codec1978.GenVersion != 25 { @@ -47,7 +47,7 @@ func init() { func (Message) codecSelferViaCodecgen() {} func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -63,7 +63,7 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { var yyn9 bool = x.Status == nil var yyn10 bool = x.RequestDeliveryResponse == nil var yyn14 bool = x.IncludeSpans == nil - var yyq2 = [18]bool{ // should field at this index be written? + var yyq2 = [19]bool{ // should field at this index be written? true, // msg_type x.Source != "", // source x.Destination != "", // dest @@ -82,13 +82,14 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { x.URL != "", // url len(x.PartnerIDs) != 0, // partner_ids x.SessionID != "", // session_id + true, // qos } _ = yyq2 if yyr2 || yy2arr2 { - z.EncWriteArrayStart(18) + z.EncWriteArrayStart(19) z.EncWriteArrayElem() - if yyxt21 := z.Extension(x.Type); yyxt21 != nil { - z.EncExtension(x.Type, yyxt21) + if yyxt22 := z.Extension(x.Type); yyxt22 != nil { + z.EncExtension(x.Type, yyxt22) } else { r.EncodeInt(int64(x.Type)) } @@ -128,8 +129,8 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { } else { z.EncWriteArrayElem() if yyq2[6] { - yy27 := *x.Status - r.EncodeInt(int64(yy27)) + yy28 := *x.Status + r.EncodeInt(int64(yy28)) } else { r.EncodeNil() } @@ -140,8 +141,8 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { } else { z.EncWriteArrayElem() if yyq2[7] { - yy29 := *x.RequestDeliveryResponse - r.EncodeInt(int64(yy29)) + yy30 := *x.RequestDeliveryResponse + r.EncodeInt(int64(yy30)) } else { r.EncodeNil() } @@ -182,8 +183,8 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { } else { z.EncWriteArrayElem() if yyq2[11] { - yy34 := *x.IncludeSpans - r.EncodeBool(bool(yy34)) + yy35 := *x.IncludeSpans + r.EncodeBool(bool(yy35)) } else { r.EncodeNil() } @@ -232,6 +233,12 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { } else { r.EncodeString("") } + z.EncWriteArrayElem() + if yyxt43 := z.Extension(x.QualityOfService); yyxt43 != nil { + z.EncExtension(x.QualityOfService, yyxt43) + } else { + r.EncodeInt(int64(x.QualityOfService)) + } z.EncWriteArrayEnd() } else { var yynn2 int @@ -245,8 +252,8 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { z.EncWriteMapElemKey() r.EncodeString(`msg_type`) z.EncWriteMapElemValue() - if yyxt42 := z.Extension(x.Type); yyxt42 != nil { - z.EncExtension(x.Type, yyxt42) + if yyxt44 := z.Extension(x.Type); yyxt44 != nil { + z.EncExtension(x.Type, yyxt44) } else { r.EncodeInt(int64(x.Type)) } @@ -303,8 +310,8 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { if yyn9 { r.EncodeNil() } else { - yy48 := *x.Status - r.EncodeInt(int64(yy48)) + yy50 := *x.Status + r.EncodeInt(int64(yy50)) } } if yyq2[7] { @@ -318,8 +325,8 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { if yyn10 { r.EncodeNil() } else { - yy50 := *x.RequestDeliveryResponse - r.EncodeInt(int64(yy50)) + yy52 := *x.RequestDeliveryResponse + r.EncodeInt(int64(yy52)) } } if yyq2[8] { @@ -371,8 +378,8 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { if yyn14 { r.EncodeNil() } else { - yy55 := *x.IncludeSpans - r.EncodeBool(bool(yy55)) + yy57 := *x.IncludeSpans + r.EncodeBool(bool(yy57)) } } if yyq2[12] { @@ -431,38 +438,50 @@ func (x *Message) CodecEncodeSelf(e *codec1978.Encoder) { z.EncWriteMapElemValue() r.EncodeString(string(x.SessionID)) } + z.EncWriteMapElemKey() + if z.IsJSONHandle() { + z.WriteStr("\"qos\"") + } else { + r.EncodeString(`qos`) + } + z.EncWriteMapElemValue() + if yyxt65 := z.Extension(x.QualityOfService); yyxt65 != nil { + z.EncExtension(x.QualityOfService, yyxt65) + } else { + r.EncodeInt(int64(x.QualityOfService)) + } z.EncWriteMapEnd() } } } func (x *Message) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil319 { + if yyct2 == codecSelferValueTypeNil5645 { *(x) = Message{} - } else if yyct2 == codecSelferValueTypeMap319 { + } else if yyct2 == codecSelferValueTypeMap5645 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray319 { + } else if yyct2 == codecSelferValueTypeArray5645 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct5645) } } func (x *Message) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -547,6 +566,12 @@ func (x *Message) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { z.F.DecSliceStringX(&x.PartnerIDs, d) case "session_id": x.SessionID = (string)(z.DecStringZC(r.DecodeStringAsBytes())) + case "qos": + if yyxt32 := z.Extension(x.QualityOfService); yyxt32 != nil { + z.DecExtension(&x.QualityOfService, yyxt32) + } else { + x.QualityOfService = (QOSValue)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize5645)) + } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 @@ -554,95 +579,95 @@ func (x *Message) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *Message) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r - var yyj31 int - var yyb31 bool - var yyhl31 bool = l >= 0 - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + var yyj33 int + var yyb33 bool + var yyhl33 bool = l >= 0 + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() - if yyxt33 := z.Extension(x.Type); yyxt33 != nil { - z.DecExtension(&x.Type, yyxt33) + if yyxt35 := z.Extension(x.Type); yyxt35 != nil { + z.DecExtension(&x.Type, yyxt35) } else { x.Type = (MessageType)(r.DecodeInt64()) } - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Source = (string)(z.DecStringZC(r.DecodeStringAsBytes())) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Destination = (string)(z.DecStringZC(r.DecodeStringAsBytes())) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TransactionUUID = (string)(z.DecStringZC(r.DecodeStringAsBytes())) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.ContentType = (string)(z.DecStringZC(r.DecodeStringAsBytes())) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Accept = (string)(z.DecStringZC(r.DecodeStringAsBytes())) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } @@ -657,13 +682,13 @@ func (x *Message) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } *x.Status = (int64)(r.DecodeInt64()) } - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } @@ -678,49 +703,49 @@ func (x *Message) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } *x.RequestDeliveryResponse = (int64)(r.DecodeInt64()) } - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.Headers, d) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringStringX(&x.Metadata, d) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSliceSlicestring((*[][]string)(&x.Spans), d) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } @@ -735,100 +760,116 @@ func (x *Message) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { } *x.IncludeSpans = (bool)(r.DecodeBool()) } - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Path = (string)(z.DecStringZC(r.DecodeStringAsBytes())) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Payload = z.DecodeBytesInto(([]byte)(x.Payload)) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.ServiceName = (string)(z.DecStringZC(r.DecodeStringAsBytes())) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.URL = (string)(z.DecStringZC(r.DecodeStringAsBytes())) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.PartnerIDs, d) - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.SessionID = (string)(z.DecStringZC(r.DecodeStringAsBytes())) + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l + } else { + yyb33 = z.DecCheckBreak() + } + if yyb33 { + z.DecReadArrayEnd() + return + } + z.DecReadArrayElem() + if yyxt62 := z.Extension(x.QualityOfService); yyxt62 != nil { + z.DecExtension(&x.QualityOfService, yyxt62) + } else { + x.QualityOfService = (QOSValue)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize5645)) + } for { - yyj31++ - if yyhl31 { - yyb31 = yyj31 > l + yyj33++ + if yyhl33 { + yyb33 = yyj33 > l } else { - yyb31 = z.DecCheckBreak() + yyb33 = z.DecCheckBreak() } - if yyb31 { + if yyb33 { break } z.DecReadArrayElem() - z.DecStructFieldNotFound(yyj31-1, "") + z.DecStructFieldNotFound(yyj33-1, "") } } func (x *Message) IsCodecEmpty() bool { - return !(x.Type != 0 || x.Source != "" || x.Destination != "" || x.TransactionUUID != "" || x.ContentType != "" || x.Accept != "" || len(x.Headers) != 0 || len(x.Metadata) != 0 || len(x.Spans) != 0 || x.Path != "" || len(x.Payload) != 0 || x.ServiceName != "" || x.URL != "" || len(x.PartnerIDs) != 0 || x.SessionID != "" || false) + return !(x.Type != 0 || x.Source != "" || x.Destination != "" || x.TransactionUUID != "" || x.ContentType != "" || x.Accept != "" || len(x.Headers) != 0 || len(x.Metadata) != 0 || len(x.Spans) != 0 || x.Path != "" || len(x.Payload) != 0 || x.ServiceName != "" || x.URL != "" || len(x.PartnerIDs) != 0 || x.SessionID != "" || x.QualityOfService != 0 || false) } func (SimpleRequestResponse) codecSelferViaCodecgen() {} func (x *SimpleRequestResponse) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -1146,32 +1187,32 @@ func (x *SimpleRequestResponse) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *SimpleRequestResponse) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil319 { + if yyct2 == codecSelferValueTypeNil5645 { *(x) = SimpleRequestResponse{} - } else if yyct2 == codecSelferValueTypeMap319 { + } else if yyct2 == codecSelferValueTypeMap5645 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray319 { + } else if yyct2 == codecSelferValueTypeArray5645 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct5645) } } func (x *SimpleRequestResponse) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -1255,7 +1296,7 @@ func (x *SimpleRequestResponse) codecDecodeSelfFromMap(l int, d *codec1978.Decod } func (x *SimpleRequestResponse) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj27 int @@ -1481,7 +1522,7 @@ func (x *SimpleRequestResponse) IsCodecEmpty() bool { func (SimpleEvent) codecSelferViaCodecgen() {} func (x *SimpleEvent) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -1674,32 +1715,32 @@ func (x *SimpleEvent) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *SimpleEvent) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil319 { + if yyct2 == codecSelferValueTypeNil5645 { *(x) = SimpleEvent{} - } else if yyct2 == codecSelferValueTypeMap319 { + } else if yyct2 == codecSelferValueTypeMap5645 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray319 { + } else if yyct2 == codecSelferValueTypeArray5645 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct5645) } } func (x *SimpleEvent) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -1746,7 +1787,7 @@ func (x *SimpleEvent) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *SimpleEvent) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj18 int @@ -1885,7 +1926,7 @@ func (x *SimpleEvent) IsCodecEmpty() bool { func (CRUD) codecSelferViaCodecgen() {} func (x *CRUD) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -2197,32 +2238,32 @@ func (x *CRUD) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *CRUD) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil319 { + if yyct2 == codecSelferValueTypeNil5645 { *(x) = CRUD{} - } else if yyct2 == codecSelferValueTypeMap319 { + } else if yyct2 == codecSelferValueTypeMap5645 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray319 { + } else if yyct2 == codecSelferValueTypeArray5645 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct5645) } } func (x *CRUD) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -2306,7 +2347,7 @@ func (x *CRUD) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *CRUD) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj27 int @@ -2532,7 +2573,7 @@ func (x *CRUD) IsCodecEmpty() bool { func (ServiceRegistration) codecSelferViaCodecgen() {} func (x *ServiceRegistration) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -2586,32 +2627,32 @@ func (x *ServiceRegistration) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *ServiceRegistration) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil319 { + if yyct2 == codecSelferValueTypeNil5645 { *(x) = ServiceRegistration{} - } else if yyct2 == codecSelferValueTypeMap319 { + } else if yyct2 == codecSelferValueTypeMap5645 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray319 { + } else if yyct2 == codecSelferValueTypeArray5645 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct5645) } } func (x *ServiceRegistration) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -2646,7 +2687,7 @@ func (x *ServiceRegistration) codecDecodeSelfFromMap(l int, d *codec1978.Decoder } func (x *ServiceRegistration) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj8 int @@ -2713,7 +2754,7 @@ func (x *ServiceRegistration) IsCodecEmpty() bool { func (ServiceAlive) codecSelferViaCodecgen() {} func (x *ServiceAlive) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -2751,32 +2792,32 @@ func (x *ServiceAlive) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *ServiceAlive) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil319 { + if yyct2 == codecSelferValueTypeNil5645 { *(x) = ServiceAlive{} - } else if yyct2 == codecSelferValueTypeMap319 { + } else if yyct2 == codecSelferValueTypeMap5645 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray319 { + } else if yyct2 == codecSelferValueTypeArray5645 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct5645) } } func (x *ServiceAlive) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -2807,7 +2848,7 @@ func (x *ServiceAlive) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *ServiceAlive) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int @@ -2850,7 +2891,7 @@ func (x *ServiceAlive) IsCodecEmpty() bool { func (Unknown) codecSelferViaCodecgen() {} func (x *Unknown) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { @@ -2888,32 +2929,32 @@ func (x *Unknown) CodecEncodeSelf(e *codec1978.Encoder) { } func (x *Unknown) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeNil319 { + if yyct2 == codecSelferValueTypeNil5645 { *(x) = Unknown{} - } else if yyct2 == codecSelferValueTypeMap319 { + } else if yyct2 == codecSelferValueTypeMap5645 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() - } else if yyct2 == codecSelferValueTypeArray319 { + } else if yyct2 == codecSelferValueTypeArray5645 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct319) + panic(errCodecSelferOnlyMapOrArrayEncodeToStruct5645) } } func (x *Unknown) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 @@ -2944,7 +2985,7 @@ func (x *Unknown) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { } func (x *Unknown) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer319 + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int @@ -2985,8 +3026,8 @@ func (x *Unknown) IsCodecEmpty() bool { return !(x.Type != 0 || false) } -func (x codecSelfer319) encSliceSlicestring(v [][]string, e *codec1978.Encoder) { - var h codecSelfer319 +func (x codecSelfer5645) encSliceSlicestring(v [][]string, e *codec1978.Encoder) { + var h codecSelfer5645 z, r := codec1978.GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { @@ -3005,8 +3046,8 @@ func (x codecSelfer319) encSliceSlicestring(v [][]string, e *codec1978.Encoder) z.EncWriteArrayEnd() } -func (x codecSelfer319) decSliceSlicestring(v *[][]string, d *codec1978.Decoder) { - var h codecSelfer319 +func (x codecSelfer5645) decSliceSlicestring(v *[][]string, d *codec1978.Decoder) { + var h codecSelfer5645 z, r := codec1978.GenHelper().Decoder(d) _, _, _ = h, z, r From eaf4a455240cd171306a5475a340d5a192079086 Mon Sep 17 00:00:00 2001 From: johnabass Date: Sat, 28 May 2022 11:47:18 -0700 Subject: [PATCH 4/6] fleshed out QOS tests; added .swp to ignore --- .gitignore | 3 ++ qos_test.go | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 qos_test.go diff --git a/.gitignore b/.gitignore index 846a894..e1011d8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ *.so *.dylib +# vim +*.swp + # Test binary, build with `go test -c` *.test diff --git a/qos_test.go b/qos_test.go new file mode 100644 index 0000000..d7eb683 --- /dev/null +++ b/qos_test.go @@ -0,0 +1,88 @@ +package wrp + +import ( + "strconv" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestQOSLevel(t *testing.T) { + for _, v := range []QOSLevel{QOSLow, QOSMedium, QOSHigh, QOSCritical} { + t.Run(strconv.Itoa(int(v)), func(t *testing.T) { + assert.NotEmpty(t, v.String()) + }) + } +} + +func TestQOSValue(t *testing.T) { + t.Run("Level", func(t *testing.T) { + testCases := []struct { + value QOSValue + expected QOSLevel + }{ + { + value: -1, + expected: QOSLow, + }, + { + value: 0, + expected: QOSLow, + }, + { + value: 9, + expected: QOSLow, + }, + { + value: 24, + expected: QOSLow, + }, + { + value: 25, + expected: QOSMedium, + }, + { + value: 32, + expected: QOSMedium, + }, + { + value: 49, + expected: QOSMedium, + }, + { + value: 50, + expected: QOSHigh, + }, + { + value: 61, + expected: QOSHigh, + }, + { + value: 74, + expected: QOSHigh, + }, + { + value: 75, + expected: QOSCritical, + }, + { + value: 84, + expected: QOSCritical, + }, + { + value: 99, + expected: QOSCritical, + }, + { + value: 34876123, + expected: QOSCritical, + }, + } + + for _, testCase := range testCases { + t.Run(strconv.Itoa(int(testCase.value)), func(t *testing.T) { + assert.Equal(t, testCase.expected, testCase.value.Level()) + }) + } + }) +} From d444c60fb2e2fb41e93f1eee72eab6db63575e1b Mon Sep 17 00:00:00 2001 From: johnabass Date: Sat, 28 May 2022 11:50:15 -0700 Subject: [PATCH 5/6] updated --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6be61a9..649c956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] - Fix `500 Invalid WRP content type` for invalid `Accept` headers [#74](https://github.com/xmidt-org/wrp-go/pull/74) +- Deprecated the concrete message structs, e.g. SimpleEvent +- Added support for the new qos field. ## [v3.1.2] - Move ParseID func and relevant consts from webpa-common to wrp-go. [#75](https://github.com/xmidt-org/wrp-go/pull/75) From 8bbcf03378f7ceb5e078a38d00952b9c3963cdd4 Mon Sep 17 00:00:00 2001 From: johnabass Date: Sat, 28 May 2022 11:53:52 -0700 Subject: [PATCH 6/6] added a qos field for verification --- messages_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/messages_test.go b/messages_test.go index 989b0a0..030894f 100644 --- a/messages_test.go +++ b/messages_test.go @@ -161,10 +161,11 @@ func TestMessage(t *testing.T) { messages = []Message{ {}, { - Type: SimpleEventMessageType, - Source: "mac:121234345656", - Destination: "foobar.com/service", - TransactionUUID: "a unique identifier", + Type: SimpleEventMessageType, + Source: "mac:121234345656", + Destination: "foobar.com/service", + TransactionUUID: "a unique identifier", + QualityOfService: 24, }, { Type: SimpleRequestResponseMessageType,