You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@inlong.apache.org by GitBox <gi...@apache.org> on 2021/05/10 08:33:39 UTC

[GitHub] [incubator-inlong] charlely commented on a change in pull request #465: [INLONG-603]Codec for Go sdk

charlely commented on a change in pull request #465:
URL: https://github.com/apache/incubator-inlong/pull/465#discussion_r629149209



##########
File path: tubemq-client-twins/tubemq-client-go/codec/codec.go
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Package codec defines the encoding and decoding logic between TubeMQ.
+// If the protocol of encoding and decoding is changed, only this package
+// will need to be changed.
+package codec
+
+// Response is the abstraction of the transport response.
+type Response interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// GetBuffer returns the body of the response.
+	GetBuffer() []byte
+}
+
+// Decoder is the abstraction of the decoder which is used to decode the response.
+type Decoder interface {
+	// Decode will decode the response to frame head and body.
+	Decode() (Response, error)
+}
+
+// RPCRequest represents the RPC request protocol.
+type RPCRequest interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// Encode encodes the RPCRequest to bytes.
+	Encode() ([]byte, error)

Review comment:
       Change Encode to Unmarshal

##########
File path: tubemq-client-twins/tubemq-client-go/transport/client.go
##########
@@ -0,0 +1,53 @@
+package transport
+
+import (
+	"context"
+
+	"github.com/apache/incubator-inlong/tubemq-client-twins/tubemq-client-go/codec"
+	"github.com/apache/incubator-inlong/tubemq-client-twins/tubemq-client-go/multiplexing"
+)
+
+// ClientOptions represents the transport options
+type ClientOptions struct {
+	Address string
+
+	CACertFile    string
+	TLSCertFile   string
+	TLSKeyFile    string
+	TLSServerName string
+}
+
+// Client is the transport layer to TubeMQ which is used to communicate with TubeMQ
+type Client struct {
+	opts *ClientOptions
+	Pool *multiplexing.Pool
+}
+
+// SendRequest sends the request and receive the response
+func (c *Client) SendRequest(ctx context.Context, serial uint32, req []byte) (codec.Response, error) {

Review comment:
       Function name SendRequest -> DoRequest ? Why input param is []byte serial, not a codec.Req ?

##########
File path: tubemq-client-twins/tubemq-client-go/codec/codec.go
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Package codec defines the encoding and decoding logic between TubeMQ.
+// If the protocol of encoding and decoding is changed, only this package
+// will need to be changed.
+package codec
+
+// Response is the abstraction of the transport response.
+type Response interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// GetBuffer returns the body of the response.
+	GetBuffer() []byte
+}
+
+// Decoder is the abstraction of the decoder which is used to decode the response.
+type Decoder interface {
+	// Decode will decode the response to frame head and body.
+	Decode() (Response, error)
+}
+
+// RPCRequest represents the RPC request protocol.
+type RPCRequest interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// Encode encodes the RPCRequest to bytes.
+	Encode() ([]byte, error)
+}
+
+// RPCResponse represents the RPC response from TubeMQ.
+type RPCResponse interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// Decode decodes the Response.
+	Decode(response Response) error
+	// GetException returns the exception msg.
+	GetException() string
+	// GetStackTrace returns the stack track msg.
+	GetStackTrace() string

Review comment:
       GetStackTrace cann't use to common function.

##########
File path: tubemq-client-twins/tubemq-client-go/codec/codec.go
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Package codec defines the encoding and decoding logic between TubeMQ.
+// If the protocol of encoding and decoding is changed, only this package
+// will need to be changed.
+package codec
+
+// Response is the abstraction of the transport response.
+type Response interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// GetBuffer returns the body of the response.
+	GetBuffer() []byte
+}
+
+// Decoder is the abstraction of the decoder which is used to decode the response.
+type Decoder interface {
+	// Decode will decode the response to frame head and body.
+	Decode() (Response, error)
+}
+
+// RPCRequest represents the RPC request protocol.
+type RPCRequest interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// Encode encodes the RPCRequest to bytes.
+	Encode() ([]byte, error)
+}
+
+// RPCResponse represents the RPC response from TubeMQ.
+type RPCResponse interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// Decode decodes the Response.
+	Decode(response Response) error

Review comment:
       Change Decode to Marshal

##########
File path: tubemq-client-twins/tubemq-client-go/transport/client.go
##########
@@ -0,0 +1,53 @@
+package transport
+
+import (
+	"context"
+
+	"github.com/apache/incubator-inlong/tubemq-client-twins/tubemq-client-go/codec"
+	"github.com/apache/incubator-inlong/tubemq-client-twins/tubemq-client-go/multiplexing"
+)
+
+// ClientOptions represents the transport options
+type ClientOptions struct {

Review comment:
       Can use Options?

##########
File path: tubemq-client-twins/tubemq-client-go/transport/client.go
##########
@@ -0,0 +1,53 @@
+package transport
+
+import (
+	"context"
+
+	"github.com/apache/incubator-inlong/tubemq-client-twins/tubemq-client-go/codec"
+	"github.com/apache/incubator-inlong/tubemq-client-twins/tubemq-client-go/multiplexing"
+)
+
+// ClientOptions represents the transport options
+type ClientOptions struct {
+	Address string
+
+	CACertFile    string
+	TLSCertFile   string
+	TLSKeyFile    string
+	TLSServerName string
+}
+
+// Client is the transport layer to TubeMQ which is used to communicate with TubeMQ
+type Client struct {
+	opts *ClientOptions
+	Pool *multiplexing.Pool
+}
+
+// SendRequest sends the request and receive the response
+func (c *Client) SendRequest(ctx context.Context, serial uint32, req []byte) (codec.Response, error) {
+	opts := &multiplexing.DialOptions{
+		Address: c.opts.Address,
+		Network: "tcp",
+	}
+	if c.opts.CACertFile != "none" {

Review comment:
       Default is "", not has New function init to none.

##########
File path: tubemq-client-twins/tubemq-client-go/codec/codec.go
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Package codec defines the encoding and decoding logic between TubeMQ.
+// If the protocol of encoding and decoding is changed, only this package
+// will need to be changed.
+package codec
+
+// Response is the abstraction of the transport response.
+type Response interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// GetBuffer returns the body of the response.
+	GetBuffer() []byte
+}
+
+// Decoder is the abstraction of the decoder which is used to decode the response.
+type Decoder interface {
+	// Decode will decode the response to frame head and body.
+	Decode() (Response, error)
+}
+
+// RPCRequest represents the RPC request protocol.
+type RPCRequest interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// Encode encodes the RPCRequest to bytes.
+	Encode() ([]byte, error)
+}
+
+// RPCResponse represents the RPC response from TubeMQ.
+type RPCResponse interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// Decode decodes the Response.
+	Decode(response Response) error
+	// GetException returns the exception msg.
+	GetException() string

Review comment:
       GetExeption cann't use to common function.

##########
File path: tubemq-client-twins/tubemq-client-go/codec/codec.go
##########
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Package codec defines the encoding and decoding logic between TubeMQ.
+// If the protocol of encoding and decoding is changed, only this package
+// will need to be changed.
+package codec
+
+// Response is the abstraction of the transport response.
+type Response interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// GetBuffer returns the body of the response.
+	GetBuffer() []byte
+}
+
+// Decoder is the abstraction of the decoder which is used to decode the response.
+type Decoder interface {
+	// Decode will decode the response to frame head and body.
+	Decode() (Response, error)
+}
+
+// RPCRequest represents the RPC request protocol.
+type RPCRequest interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// Encode encodes the RPCRequest to bytes.
+	Encode() ([]byte, error)
+}
+
+// RPCResponse represents the RPC response from TubeMQ.
+type RPCResponse interface {
+	// GetSerialNo returns the `serialNo` of the corresponding request.
+	GetSerialNo() uint32
+	// Decode decodes the Response.
+	Decode(response Response) error

Review comment:
       Input param is []byte




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org