diff --git a/examples/client/client.go b/examples/client/client.go index dc65971..3d76f65 100644 --- a/examples/client/client.go +++ b/examples/client/client.go @@ -8,14 +8,13 @@ import ( "github.com/protocol-laboratory/opcua-go/opcua" "github.com/protocol-laboratory/opcua-go/opcua/ua" - "github.com/shoothzj/gox/netx" ) func main() { logger := slog.Default() config := &opcua.ClientConfig{ - Address: netx.Address{ + Address: opcua.Address{ Host: "localhost", Port: 4840, }, diff --git a/go.mod b/go.mod index 4b89818..8a1f26e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/protocol-laboratory/opcua-go go 1.21 require ( - github.com/shoothzj/gox v0.0.4-0.20240916105254-02a0a7039d5d + github.com/libgox/buffer v0.0.0-20241010235618-d8b51aafaff0 github.com/stretchr/testify v1.9.0 ) diff --git a/go.sum b/go.sum index 0ef0f52..643bf87 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,9 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/libgox/buffer v0.0.0-20241010235618-d8b51aafaff0 h1:b13ZQECXGS1YxtFlDTBJbJKM4LgtsOyARasu0H620tY= +github.com/libgox/buffer v0.0.0-20241010235618-d8b51aafaff0/go.mod h1:VAuNNs9Mp5NttnP8etLB4FI4ZZ67sRUnk/jTb/BnSqo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/shoothzj/gox v0.0.4-0.20240916105254-02a0a7039d5d h1:oUVTx1ezGfBFkfRb192K+FFRAjjBX5u58qkbXEHfTdo= -github.com/shoothzj/gox v0.0.4-0.20240916105254-02a0a7039d5d/go.mod h1:JrD7u6Tem/9Ut4o0kQNK+aZkMWCba/d9VeabBZSEDT4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/opcua/address.go b/opcua/address.go new file mode 100644 index 0000000..280f282 --- /dev/null +++ b/opcua/address.go @@ -0,0 +1,17 @@ +package opcua + +import ( + "net" + "strconv" +) + +type Address struct { + // Host domain name or ipv4, ipv6 address + Host string + // Port service port + Port int +} + +func (addr Address) Addr() string { + return net.JoinHostPort(addr.Host, strconv.Itoa(addr.Port)) +} diff --git a/opcua/client.go b/opcua/client.go index 2cb9a1f..3153ee8 100644 --- a/opcua/client.go +++ b/opcua/client.go @@ -9,14 +9,13 @@ import ( "net" "sync" - "github.com/shoothzj/gox/buffer" - "github.com/shoothzj/gox/netx" + "github.com/libgox/buffer" "github.com/protocol-laboratory/opcua-go/opcua/ua" ) type ClientConfig struct { - Address netx.Address + Address Address BufferMax int SendQueueSize int PendingQueueSize int @@ -169,7 +168,13 @@ func (c *Client) Close() { } func NewClient(config *ClientConfig) (*Client, error) { - conn, err := netx.Dial(config.Address, config.TlsConfig) + var conn net.Conn + var err error + if config.TlsConfig != nil { + conn, err = tls.Dial("tcp", config.Address.Addr(), config.TlsConfig) + } else { + conn, err = net.Dial("tcp", config.Address.Addr()) + } if err != nil { return nil, err diff --git a/opcua/server.go b/opcua/server.go index b97a190..9b41709 100644 --- a/opcua/server.go +++ b/opcua/server.go @@ -8,7 +8,7 @@ import ( "sync" "time" - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" "github.com/protocol-laboratory/opcua-go/opcua/ua" ) diff --git a/opcua/server_test.go b/opcua/server_test.go index b24b0d7..b9de819 100644 --- a/opcua/server_test.go +++ b/opcua/server_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/protocol-laboratory/opcua-go/opcua/ua" - "github.com/shoothzj/gox/netx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -27,7 +26,7 @@ func newTestSimpleClientServer(t *testing.T, serverConfig *ServerConfig, clientC require.NoError(t, err, "Server should start without error") clientConfig.Logger = testLogger - clientConfig.Address = netx.Address{ + clientConfig.Address = Address{ Host: serverConfig.Host, Port: port, } diff --git a/opcua/ua/message_acknowledge.go b/opcua/ua/message_acknowledge.go index 6457389..c264d6c 100644 --- a/opcua/ua/message_acknowledge.go +++ b/opcua/ua/message_acknowledge.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageAcknowledge struct { @@ -58,22 +58,22 @@ func (m *MessageAcknowledge) Buffer() (*buffer.Buffer, error) { if _, err := buf.Write([]byte{'F'}); err != nil { return nil, err } - if err := buf.PutUInt32Le(uint32(m.Length())); err != nil { + if err := buf.WriteUInt32Le(uint32(m.Length())); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.Version); err != nil { + if err := buf.WriteUInt32Le(m.Version); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.ReceiveBufferSize); err != nil { + if err := buf.WriteUInt32Le(m.ReceiveBufferSize); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.SendBufferSize); err != nil { + if err := buf.WriteUInt32Le(m.SendBufferSize); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.MaxMessageSize); err != nil { + if err := buf.WriteUInt32Le(m.MaxMessageSize); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.MaxChunkCount); err != nil { + if err := buf.WriteUInt32Le(m.MaxChunkCount); err != nil { return nil, err } return buf, nil diff --git a/opcua/ua/message_acknowledge_test.go b/opcua/ua/message_acknowledge_test.go index 30b9dfd..17a38a7 100644 --- a/opcua/ua/message_acknowledge_test.go +++ b/opcua/ua/message_acknowledge_test.go @@ -3,13 +3,12 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestDecodeMessageAcknowledge(t *testing.T) { - buffer := testx.Hex2Buffer(t, "41434b461c00000000000000ffff0000ffff00000000200040000000") + buffer := hex2Buffer(t, "41434b461c00000000000000ffff0000ffff00000000200040000000") err := buffer.Skip(8) require.Nil(t, err) msg, err := DecodeMessageAcknowledge(buffer) @@ -32,5 +31,5 @@ func TestEncodeMessageAcknowledge(t *testing.T) { } buffer, err := msg.Buffer() require.Nil(t, err) - assert.Equal(t, testx.Hex2Buffer(t, "41434b461c00000000000000ffff0000ffff00000000200040000000"), buffer) + assert.Equal(t, hex2Buffer(t, "41434b461c00000000000000ffff0000ffff00000000200040000000"), buffer) } diff --git a/opcua/ua/message_browse_req.go b/opcua/ua/message_browse_req.go index d0e8633..e878f84 100644 --- a/opcua/ua/message_browse_req.go +++ b/opcua/ua/message_browse_req.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageBrowseReq struct { diff --git a/opcua/ua/message_browse_req_test.go b/opcua/ua/message_browse_req_test.go index 1c72d9a..96a04b0 100644 --- a/opcua/ua/message_browse_req_test.go +++ b/opcua/ua/message_browse_req_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageBrowseReq(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4d534746870000000200000001000000c8000000c800000001000f020500002000000048cce1823313199f88bb583a480954a576d4fae160deef9bf25daa6e50bfbc39f6c9be3815fcda01c800000000000000ffffffffa00f00000000000000000000000000000000000000000000000100000001000f3d00000000002d01000000003f000000") + buffer := hex2Buffer(t, "4d534746870000000200000001000000c8000000c800000001000f020500002000000048cce1823313199f88bb583a480954a576d4fae160deef9bf25daa6e50bfbc39f6c9be3815fcda01c800000000000000ffffffffa00f00000000000000000000000000000000000000000000000100000001000f3d00000000002d01000000003f000000") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_browse_resp.go b/opcua/ua/message_browse_resp.go index cc41f01..87ed513 100644 --- a/opcua/ua/message_browse_resp.go +++ b/opcua/ua/message_browse_resp.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageBrowseResp struct { diff --git a/opcua/ua/message_browse_resp_test.go b/opcua/ua/message_browse_resp_test.go index 46e69de..1ec5e80 100644 --- a/opcua/ua/message_browse_resp_test.go +++ b/opcua/ua/message_browse_resp_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageBrowseResp(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4d534746480000000200000001000000fb030000c500000001001202b0c4be3815fcda01c50000000000000000ffffffff0000000100000000000000ffffffff00000000ffffffff") + buffer := hex2Buffer(t, "4d534746480000000200000001000000fb030000c500000001001202b0c4be3815fcda01c50000000000000000ffffffff0000000100000000000000ffffffff00000000ffffffff") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_close_secure_channel.go b/opcua/ua/message_close_secure_channel.go index fc4ae06..28b1004 100644 --- a/opcua/ua/message_close_secure_channel.go +++ b/opcua/ua/message_close_secure_channel.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageCloseSecureChannel struct { @@ -29,7 +29,7 @@ func (m *MessageCloseSecureChannel) Buffer() (*buffer.Buffer, error) { if _, err := buf.Write([]byte{'F'}); err != nil { return nil, err } - if err := buf.PutUInt32Le(uint32(m.Length())); err != nil { + if err := buf.WriteUInt32Le(uint32(m.Length())); err != nil { return nil, err } return buf, nil diff --git a/opcua/ua/message_close_secure_channel_test.go b/opcua/ua/message_close_secure_channel_test.go index 65c9bcd..d0164dc 100644 --- a/opcua/ua/message_close_secure_channel_test.go +++ b/opcua/ua/message_close_secure_channel_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageCloseSecureChannel(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4d5347465f0000000200000001000000e6000000e60000000100d9010500002000000048cce1823313199f88bb583a480954a576d4fae160deef9bf25daa6e50bfbc396ee1343d15fcda01e600000000000000ffffffffa00f000000000001") + buffer := hex2Buffer(t, "4d5347465f0000000200000001000000e6000000e60000000100d9010500002000000048cce1823313199f88bb583a480954a576d4fae160deef9bf25daa6e50bfbc396ee1343d15fcda01e600000000000000ffffffffa00f000000000001") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_close_session_req.go b/opcua/ua/message_close_session_req.go index e2afed8..dd0709c 100644 --- a/opcua/ua/message_close_session_req.go +++ b/opcua/ua/message_close_session_req.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageCloseSessionReq struct { diff --git a/opcua/ua/message_close_session_req_test.go b/opcua/ua/message_close_session_req_test.go index 50e7b25..d26961d 100644 --- a/opcua/ua/message_close_session_req_test.go +++ b/opcua/ua/message_close_session_req_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageCloseSessionReq(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4d5347465f0000000200000001000000e6000000e60000000100d9010500002000000048cce1823313199f88bb583a480954a576d4fae160deef9bf25daa6e50bfbc396ee1343d15fcda01e600000000000000ffffffffa00f000000000001") + buffer := hex2Buffer(t, "4d5347465f0000000200000001000000e6000000e60000000100d9010500002000000048cce1823313199f88bb583a480954a576d4fae160deef9bf25daa6e50bfbc396ee1343d15fcda01e600000000000000ffffffffa00f000000000001") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_close_session_resp.go b/opcua/ua/message_close_session_resp.go index ca09151..aa82a35 100644 --- a/opcua/ua/message_close_session_resp.go +++ b/opcua/ua/message_close_session_resp.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageCloseSessionResp struct { diff --git a/opcua/ua/message_close_session_resp_test.go b/opcua/ua/message_close_session_resp_test.go index d50d466..c34f41c 100644 --- a/opcua/ua/message_close_session_resp_test.go +++ b/opcua/ua/message_close_session_resp_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageCloseSessionResp(t *testing.T) { - buffer := testx.Hex2Buffer(t, "1e00000060090900005406400000000000000000000000000000000100000000000000000000000000000001d11afd7da59b38d0e146c88b801816eb005c00000101080a1f86fec7f584f6454d5347463400000002000000010000001c040000e60000000100dc01c07f353d15fcda01e60000000000000000ffffffff000000") + buffer := hex2Buffer(t, "1e00000060090900005406400000000000000000000000000000000100000000000000000000000000000001d11afd7da59b38d0e146c88b801816eb005c00000101080a1f86fec7f584f6454d5347463400000002000000010000001c040000e60000000100dc01c07f353d15fcda01e60000000000000000ffffffff000000") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_create_session_req.go b/opcua/ua/message_create_session_req.go index 9229494..8a38083 100644 --- a/opcua/ua/message_create_session_req.go +++ b/opcua/ua/message_create_session_req.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageCreateSessionReq struct { diff --git a/opcua/ua/message_create_session_req_test.go b/opcua/ua/message_create_session_req_test.go index f7910c2..7bd4c16 100644 --- a/opcua/ua/message_create_session_req_test.go +++ b/opcua/ua/message_create_session_req_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageCreateSessionReq(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4d5347464c010000020000000100000002000000020000000100cd010000700fb43815fcda010200000000000000ffffffffa00f00000000001800000075726e3a667265656f706375613a636c69656e742d6775691e00000075726e3a667265656f706375612e6769746875622e696f3a636c69656e7402190000005075726520507974686f6e204173796e632e20436c69656e7401000000ffffffffffffffff00000000ffffffff450000006f70632e7463703a2f2f68657a68616e676a69616e64654d6163426f6f6b2d50726f2e6c6f63616c3a35333533302f4f504355412f53696d756c6174696f6e536572766572220000005075726520507974686f6e204173796e632e20436c69656e742053657373696f6e3120000000a06ee593955cb82598cb5e9950a3f7634642941823761b762323ef23f9cc805effffffff0000000040774b4100000000") + buffer := hex2Buffer(t, "4d5347464c010000020000000100000002000000020000000100cd010000700fb43815fcda010200000000000000ffffffffa00f00000000001800000075726e3a667265656f706375613a636c69656e742d6775691e00000075726e3a667265656f706375612e6769746875622e696f3a636c69656e7402190000005075726520507974686f6e204173796e632e20436c69656e7401000000ffffffffffffffff00000000ffffffff450000006f70632e7463703a2f2f68657a68616e676a69616e64654d6163426f6f6b2d50726f2e6c6f63616c3a35333533302f4f504355412f53696d756c6174696f6e536572766572220000005075726520507974686f6e204173796e632e20436c69656e742053657373696f6e3120000000a06ee593955cb82598cb5e9950a3f7634642941823761b762323ef23f9cc805effffffff0000000040774b4100000000") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_get_endpoints_req.go b/opcua/ua/message_get_endpoints_req.go index 58a71ac..25d5039 100644 --- a/opcua/ua/message_get_endpoints_req.go +++ b/opcua/ua/message_get_endpoints_req.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageGetEndpointsReq struct { diff --git a/opcua/ua/message_get_endpoints_req_test.go b/opcua/ua/message_get_endpoints_req_test.go index 5530460..4a7e22d 100644 --- a/opcua/ua/message_get_endpoints_req_test.go +++ b/opcua/ua/message_get_endpoints_req_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageGetEndpointsReq(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4d534746a8000000010000000100000002000000020000000100ac010000a018aacbf780d9010000000000000000ffffffff60ea00000000001e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f000000000100000041000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412d50726f66696c652f5472616e73706f72742f75617463702d756173632d756162696e617279") + buffer := hex2Buffer(t, "4d534746a8000000010000000100000002000000020000000100ac010000a018aacbf780d9010000000000000000ffffffff60ea00000000001e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f000000000100000041000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412d50726f66696c652f5472616e73706f72742f75617463702d756173632d756162696e617279") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_get_endpoints_resp.go b/opcua/ua/message_get_endpoints_resp.go index 7800555..dce7e80 100644 --- a/opcua/ua/message_get_endpoints_resp.go +++ b/opcua/ua/message_get_endpoints_resp.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageGetEndpointsResp struct { diff --git a/opcua/ua/message_get_endpoints_resp_test.go b/opcua/ua/message_get_endpoints_resp_test.go index 96b6f4c..3c03881 100644 --- a/opcua/ua/message_get_endpoints_resp_test.go +++ b/opcua/ua/message_get_endpoints_resp_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageGetEndpointsResp(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4d534746a60d0000010000000100000002000000020000000100af0160edabcbf780d901000000000000000000ffffffff000000020000001e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f4500000075726e3a65636c697073653a6d696c6f3a6578616d706c65733a7365727665723a30633064313738622d356261632d343032302d386138352d6435636361353361306333311f00000075726e3a65636c697073653a6d696c6f3a6578616d706c652d7365727665720302000000656e2200000045636c69707365204d696c6f204f5043205541204578616d706c652053657276657200000000ffffffffffffffff02000000280000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f2f646973636f766572792500000068747470733a2f2f6c6f63616c686f73743a383434332f6d696c6f2f646973636f766572794f0400003082044b30820333a00302010202060187f6bf2986300d06092a864886f70d01010b050030763124302206035504030c1b45636c69707365204d696c6f204578616d706c652053657276657231153013060355040a0c0c6469676974616c7065747269310c300a060355040b0c03646576310f300d06035504070c06466f6c736f6d310b300906035504080c024341310b3009060355040613025553301e170d3233303530363136303030305a170d3236303530363136303030305a30763124302206035504030c1b45636c69707365204d696c6f204578616d706c652053657276657231153013060355040a0c0c6469676974616c7065747269310c300a060355040b0c03646576310f300d06035504070c06466f6c736f6d310b300906035504080c024341310b300906035504061302555330820122300d06092a864886f70d01010105000382010f003082010a0282010100eea7a45b5864943a777fb68a00fb390d6434f13c7486d82e5ec488d8a29290fe91c9404dd4af6bccbd318591d0b75117b54b60f3ce4e661b3e7592a903c312195cf5a9df944bc6cf79701c4d7b2d19987b561352ae8b5365cdf6146746faf274db3c3d8217ba3902ed879603e95dfa9b92a8b459b6b265afe5e63cbe015f835ea5fb2690e009c30234bf0d9c461526b4475ab46415b7c78f04499dd87b619b31d8e0dd4cc8532ad5aca684fdae506094e6fde45acf17a3ef4cd9c7927836741df9e68819a6b68a7ef0c8b4b88bb63ca16cabeb5e2f691aeef7ecfc9978b1fad483ef1db861d0512ccb334a8e5d333b3dc231aea59ada7c1ee883439c60d1f4350203010001a381de3081db301f0603551d23041830168014c572a46d2932cacb1113347277bbbee305e868f6300f0603551d13040830060101ff020100300b0603551d0f0404030202fc301d0603551d250416301406082b0601050507030206082b06010505070301305c0603551d1104553053864575726e3a65636c697073653a6d696c6f3a6578616d706c65733a7365727665723a30633064313738622d356261632d343032302d386138352d6435636361353361306333318704c0a800658704c0a84001301d0603551d0e04160414c572a46d2932cacb1113347277bbbee305e868f6300d06092a864886f70d01010b050003820101003c2979bcb26fff82fe9e0732766ca290904a00835196b552189cf9e8e9409c1d48ca1a58e5c4c898a5fddc791fad0aee7e71c760b87aecd4f2e32b25f48069c80cc10fc79a21f390df0faedd724b1fe80259ef3c88edc28b917f62c442ed552c9b566fd58268dc73a161784b2d0173e15ea562cd1597d8f0059c631506a752a7628d02e5048706be9f1ded55441334fd39bc1d45edf666333d8fd5591ae97184c26fa507eb2709142ef5eb828c7a18a0455cd4255efd5e98f7f7425ed6bf1785dc9bef2ecd8e82d9d7049ac33ff518cbb2c76d630bbdd87eed159714a5db1384b6468640bccf56e9d233689f0ed7675a3c8ae4931bc54f1896512dcedafaac07010000002f000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c696379234e6f6e650300000009000000616e6f6e796d6f757300000000ffffffffffffffffffffffff08000000757365726e616d6501000000ffffffffffffffff33000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c6963792342617369633235360b000000636572746966696361746502000000ffffffffffffffff33000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c69637923426173696332353641000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412d50726f66696c652f5472616e73706f72742f75617463702d756173632d756162696e617279201e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f4500000075726e3a65636c697073653a6d696c6f3a6578616d706c65733a7365727665723a30633064313738622d356261632d343032302d386138352d6435636361353361306333311f00000075726e3a65636c697073653a6d696c6f3a6578616d706c652d7365727665720302000000656e2200000045636c69707365204d696c6f204f5043205541204578616d706c652053657276657200000000ffffffffffffffff02000000280000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f2f646973636f766572792500000068747470733a2f2f6c6f63616c686f73743a383434332f6d696c6f2f646973636f766572794f0400003082044b30820333a00302010202060187f6bf2986300d06092a864886f70d01010b050030763124302206035504030c1b45636c69707365204d696c6f204578616d706c652053657276657231153013060355040a0c0c6469676974616c7065747269310c300a060355040b0c03646576310f300d06035504070c06466f6c736f6d310b300906035504080c024341310b3009060355040613025553301e170d3233303530363136303030305a170d3236303530363136303030305a30763124302206035504030c1b45636c69707365204d696c6f204578616d706c652053657276657231153013060355040a0c0c6469676974616c7065747269310c300a060355040b0c03646576310f300d06035504070c06466f6c736f6d310b300906035504080c024341310b300906035504061302555330820122300d06092a864886f70d01010105000382010f003082010a0282010100eea7a45b5864943a777fb68a00fb390d6434f13c7486d82e5ec488d8a29290fe91c9404dd4af6bccbd318591d0b75117b54b60f3ce4e661b3e7592a903c312195cf5a9df944bc6cf79701c4d7b2d19987b561352ae8b5365cdf6146746faf274db3c3d8217ba3902ed879603e95dfa9b92a8b459b6b265afe5e63cbe015f835ea5fb2690e009c30234bf0d9c461526b4475ab46415b7c78f04499dd87b619b31d8e0dd4cc8532ad5aca684fdae506094e6fde45acf17a3ef4cd9c7927836741df9e68819a6b68a7ef0c8b4b88bb63ca16cabeb5e2f691aeef7ecfc9978b1fad483ef1db861d0512ccb334a8e5d333b3dc231aea59ada7c1ee883439c60d1f4350203010001a381de3081db301f0603551d23041830168014c572a46d2932cacb1113347277bbbee305e868f6300f0603551d13040830060101ff020100300b0603551d0f0404030202fc301d0603551d250416301406082b0601050507030206082b06010505070301305c0603551d1104553053864575726e3a65636c697073653a6d696c6f3a6578616d706c65733a7365727665723a30633064313738622d356261632d343032302d386138352d6435636361353361306333318704c0a800658704c0a84001301d0603551d0e04160414c572a46d2932cacb1113347277bbbee305e868f6300d06092a864886f70d01010b050003820101003c2979bcb26fff82fe9e0732766ca290904a00835196b552189cf9e8e9409c1d48ca1a58e5c4c898a5fddc791fad0aee7e71c760b87aecd4f2e32b25f48069c80cc10fc79a21f390df0faedd724b1fe80259ef3c88edc28b917f62c442ed552c9b566fd58268dc73a161784b2d0173e15ea562cd1597d8f0059c631506a752a7628d02e5048706be9f1ded55441334fd39bc1d45edf666333d8fd5591ae97184c26fa507eb2709142ef5eb828c7a18a0455cd4255efd5e98f7f7425ed6bf1785dc9bef2ecd8e82d9d7049ac33ff518cbb2c76d630bbdd87eed159714a5db1384b6468640bccf56e9d233689f0ed7675a3c8ae4931bc54f1896512dcedafaac070300000039000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c6963792342617369633235365368613235360300000009000000616e6f6e796d6f757300000000ffffffffffffffffffffffff08000000757365726e616d6501000000ffffffffffffffff33000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c6963792342617369633235360b000000636572746966696361746502000000ffffffffffffffff33000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c69637923426173696332353641000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412d50726f66696c652f5472616e73706f72742f75617463702d756173632d756162696e61727988") + buffer := hex2Buffer(t, "4d534746a60d0000010000000100000002000000020000000100af0160edabcbf780d901000000000000000000ffffffff000000020000001e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f4500000075726e3a65636c697073653a6d696c6f3a6578616d706c65733a7365727665723a30633064313738622d356261632d343032302d386138352d6435636361353361306333311f00000075726e3a65636c697073653a6d696c6f3a6578616d706c652d7365727665720302000000656e2200000045636c69707365204d696c6f204f5043205541204578616d706c652053657276657200000000ffffffffffffffff02000000280000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f2f646973636f766572792500000068747470733a2f2f6c6f63616c686f73743a383434332f6d696c6f2f646973636f766572794f0400003082044b30820333a00302010202060187f6bf2986300d06092a864886f70d01010b050030763124302206035504030c1b45636c69707365204d696c6f204578616d706c652053657276657231153013060355040a0c0c6469676974616c7065747269310c300a060355040b0c03646576310f300d06035504070c06466f6c736f6d310b300906035504080c024341310b3009060355040613025553301e170d3233303530363136303030305a170d3236303530363136303030305a30763124302206035504030c1b45636c69707365204d696c6f204578616d706c652053657276657231153013060355040a0c0c6469676974616c7065747269310c300a060355040b0c03646576310f300d06035504070c06466f6c736f6d310b300906035504080c024341310b300906035504061302555330820122300d06092a864886f70d01010105000382010f003082010a0282010100eea7a45b5864943a777fb68a00fb390d6434f13c7486d82e5ec488d8a29290fe91c9404dd4af6bccbd318591d0b75117b54b60f3ce4e661b3e7592a903c312195cf5a9df944bc6cf79701c4d7b2d19987b561352ae8b5365cdf6146746faf274db3c3d8217ba3902ed879603e95dfa9b92a8b459b6b265afe5e63cbe015f835ea5fb2690e009c30234bf0d9c461526b4475ab46415b7c78f04499dd87b619b31d8e0dd4cc8532ad5aca684fdae506094e6fde45acf17a3ef4cd9c7927836741df9e68819a6b68a7ef0c8b4b88bb63ca16cabeb5e2f691aeef7ecfc9978b1fad483ef1db861d0512ccb334a8e5d333b3dc231aea59ada7c1ee883439c60d1f4350203010001a381de3081db301f0603551d23041830168014c572a46d2932cacb1113347277bbbee305e868f6300f0603551d13040830060101ff020100300b0603551d0f0404030202fc301d0603551d250416301406082b0601050507030206082b06010505070301305c0603551d1104553053864575726e3a65636c697073653a6d696c6f3a6578616d706c65733a7365727665723a30633064313738622d356261632d343032302d386138352d6435636361353361306333318704c0a800658704c0a84001301d0603551d0e04160414c572a46d2932cacb1113347277bbbee305e868f6300d06092a864886f70d01010b050003820101003c2979bcb26fff82fe9e0732766ca290904a00835196b552189cf9e8e9409c1d48ca1a58e5c4c898a5fddc791fad0aee7e71c760b87aecd4f2e32b25f48069c80cc10fc79a21f390df0faedd724b1fe80259ef3c88edc28b917f62c442ed552c9b566fd58268dc73a161784b2d0173e15ea562cd1597d8f0059c631506a752a7628d02e5048706be9f1ded55441334fd39bc1d45edf666333d8fd5591ae97184c26fa507eb2709142ef5eb828c7a18a0455cd4255efd5e98f7f7425ed6bf1785dc9bef2ecd8e82d9d7049ac33ff518cbb2c76d630bbdd87eed159714a5db1384b6468640bccf56e9d233689f0ed7675a3c8ae4931bc54f1896512dcedafaac07010000002f000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c696379234e6f6e650300000009000000616e6f6e796d6f757300000000ffffffffffffffffffffffff08000000757365726e616d6501000000ffffffffffffffff33000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c6963792342617369633235360b000000636572746966696361746502000000ffffffffffffffff33000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c69637923426173696332353641000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412d50726f66696c652f5472616e73706f72742f75617463702d756173632d756162696e617279201e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f4500000075726e3a65636c697073653a6d696c6f3a6578616d706c65733a7365727665723a30633064313738622d356261632d343032302d386138352d6435636361353361306333311f00000075726e3a65636c697073653a6d696c6f3a6578616d706c652d7365727665720302000000656e2200000045636c69707365204d696c6f204f5043205541204578616d706c652053657276657200000000ffffffffffffffff02000000280000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f2f646973636f766572792500000068747470733a2f2f6c6f63616c686f73743a383434332f6d696c6f2f646973636f766572794f0400003082044b30820333a00302010202060187f6bf2986300d06092a864886f70d01010b050030763124302206035504030c1b45636c69707365204d696c6f204578616d706c652053657276657231153013060355040a0c0c6469676974616c7065747269310c300a060355040b0c03646576310f300d06035504070c06466f6c736f6d310b300906035504080c024341310b3009060355040613025553301e170d3233303530363136303030305a170d3236303530363136303030305a30763124302206035504030c1b45636c69707365204d696c6f204578616d706c652053657276657231153013060355040a0c0c6469676974616c7065747269310c300a060355040b0c03646576310f300d06035504070c06466f6c736f6d310b300906035504080c024341310b300906035504061302555330820122300d06092a864886f70d01010105000382010f003082010a0282010100eea7a45b5864943a777fb68a00fb390d6434f13c7486d82e5ec488d8a29290fe91c9404dd4af6bccbd318591d0b75117b54b60f3ce4e661b3e7592a903c312195cf5a9df944bc6cf79701c4d7b2d19987b561352ae8b5365cdf6146746faf274db3c3d8217ba3902ed879603e95dfa9b92a8b459b6b265afe5e63cbe015f835ea5fb2690e009c30234bf0d9c461526b4475ab46415b7c78f04499dd87b619b31d8e0dd4cc8532ad5aca684fdae506094e6fde45acf17a3ef4cd9c7927836741df9e68819a6b68a7ef0c8b4b88bb63ca16cabeb5e2f691aeef7ecfc9978b1fad483ef1db861d0512ccb334a8e5d333b3dc231aea59ada7c1ee883439c60d1f4350203010001a381de3081db301f0603551d23041830168014c572a46d2932cacb1113347277bbbee305e868f6300f0603551d13040830060101ff020100300b0603551d0f0404030202fc301d0603551d250416301406082b0601050507030206082b06010505070301305c0603551d1104553053864575726e3a65636c697073653a6d696c6f3a6578616d706c65733a7365727665723a30633064313738622d356261632d343032302d386138352d6435636361353361306333318704c0a800658704c0a84001301d0603551d0e04160414c572a46d2932cacb1113347277bbbee305e868f6300d06092a864886f70d01010b050003820101003c2979bcb26fff82fe9e0732766ca290904a00835196b552189cf9e8e9409c1d48ca1a58e5c4c898a5fddc791fad0aee7e71c760b87aecd4f2e32b25f48069c80cc10fc79a21f390df0faedd724b1fe80259ef3c88edc28b917f62c442ed552c9b566fd58268dc73a161784b2d0173e15ea562cd1597d8f0059c631506a752a7628d02e5048706be9f1ded55441334fd39bc1d45edf666333d8fd5591ae97184c26fa507eb2709142ef5eb828c7a18a0455cd4255efd5e98f7f7425ed6bf1785dc9bef2ecd8e82d9d7049ac33ff518cbb2c76d630bbdd87eed159714a5db1384b6468640bccf56e9d233689f0ed7675a3c8ae4931bc54f1896512dcedafaac070300000039000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c6963792342617369633235365368613235360300000009000000616e6f6e796d6f757300000000ffffffffffffffffffffffff08000000757365726e616d6501000000ffffffffffffffff33000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c6963792342617369633235360b000000636572746966696361746502000000ffffffffffffffff33000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c69637923426173696332353641000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412d50726f66696c652f5472616e73706f72742f75617463702d756173632d756162696e61727988") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_hello.go b/opcua/ua/message_hello.go index 863d6d2..d5fd7c3 100644 --- a/opcua/ua/message_hello.go +++ b/opcua/ua/message_hello.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageHello struct { @@ -35,7 +35,7 @@ func DecodeMessageHello(buf *buffer.Buffer) (msg *MessageHello, err error) { if err != nil { return nil, err } - msg.EndpointUrl, err = buf.ReadStringLe() + msg.EndpointUrl, err = buf.ReadLengthPrefixedStringLe() if err != nil { return nil, err } @@ -65,25 +65,25 @@ func (m *MessageHello) Buffer() (*buffer.Buffer, error) { if _, err := buf.Write([]byte{'F'}); err != nil { return nil, err } - if err := buf.PutUInt32Le(uint32(m.Length())); err != nil { + if err := buf.WriteUInt32Le(uint32(m.Length())); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.Version); err != nil { + if err := buf.WriteUInt32Le(m.Version); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.ReceiveBufferSize); err != nil { + if err := buf.WriteUInt32Le(m.ReceiveBufferSize); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.SendBufferSize); err != nil { + if err := buf.WriteUInt32Le(m.SendBufferSize); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.MaxMessageSize); err != nil { + if err := buf.WriteUInt32Le(m.MaxMessageSize); err != nil { return nil, err } - if err := buf.PutUInt32Le(m.MaxChunkCount); err != nil { + if err := buf.WriteUInt32Le(m.MaxChunkCount); err != nil { return nil, err } - if err := buf.PutStringLe(m.EndpointUrl); err != nil { + if err := buf.WriteLengthPrefixedStringLe(m.EndpointUrl); err != nil { return nil, err } return buf, nil diff --git a/opcua/ua/message_hello_test.go b/opcua/ua/message_hello_test.go index afcb069..3c0db95 100644 --- a/opcua/ua/message_hello_test.go +++ b/opcua/ua/message_hello_test.go @@ -3,13 +3,12 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestDecodeMessageHello(t *testing.T) { - buffer := testx.Hex2Buffer(t, "48454c463e00000000000000ffff0000ffff000000002000400000001e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f") + buffer := hex2Buffer(t, "48454c463e00000000000000ffff0000ffff000000002000400000001e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f") err := buffer.Skip(8) require.Nil(t, err) msg, err := DecodeMessageHello(buffer) @@ -34,5 +33,5 @@ func TestEncodeMessageHello(t *testing.T) { } buffer, err := msg.Buffer() require.Nil(t, err) - assert.Equal(t, testx.Hex2Buffer(t, "48454c463e00000000000000ffff0000ffff000000002000400000001e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f"), buffer) + assert.Equal(t, hex2Buffer(t, "48454c463e00000000000000ffff0000ffff000000002000400000001e0000006f70632e7463703a2f2f6c6f63616c686f73743a31323638362f6d696c6f"), buffer) } diff --git a/opcua/ua/message_open_secure_channel.go b/opcua/ua/message_open_secure_channel.go index 798b23b..c0f95f5 100644 --- a/opcua/ua/message_open_secure_channel.go +++ b/opcua/ua/message_open_secure_channel.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageOpenSecureChannel struct { @@ -41,7 +41,7 @@ func (m *MessageOpenSecureChannel) Buffer() (*buffer.Buffer, error) { if _, err := buf.Write([]byte{'F'}); err != nil { return nil, err } - if err := buf.PutUInt32Le(uint32(m.Length())); err != nil { + if err := buf.WriteUInt32Le(uint32(m.Length())); err != nil { return nil, err } return buf, nil diff --git a/opcua/ua/message_open_secure_channel_test.go b/opcua/ua/message_open_secure_channel_test.go index 8b72da6..f6119cf 100644 --- a/opcua/ua/message_open_secure_channel_test.go +++ b/opcua/ua/message_open_secure_channel_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageOpenSecureChannel(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4f504e4684000000000000002f000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c696379234e6f6e65ffffffffffffffff01000000010000000100be0100000092a8cbf780d9010000000000000000ffffffff60ea0000000000000000000000000001000000ffffffff80ee3600") + buffer := hex2Buffer(t, "4f504e4684000000000000002f000000687474703a2f2f6f7063666f756e646174696f6e2e6f72672f55412f5365637572697479506f6c696379234e6f6e65ffffffffffffffff01000000010000000100be0100000092a8cbf780d9010000000000000000ffffffff60ea0000000000000000000000000001000000ffffffff80ee3600") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_read_req.go b/opcua/ua/message_read_req.go index 11547c4..3998ff9 100644 --- a/opcua/ua/message_read_req.go +++ b/opcua/ua/message_read_req.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageReadReq struct { diff --git a/opcua/ua/message_read_req_test.go b/opcua/ua/message_read_req_test.go index 1ecdbde..5ad5892 100644 --- a/opcua/ua/message_read_req_test.go +++ b/opcua/ua/message_read_req_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageReadReq(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4d534746800000000200000001000000e4000000e4000000010077020500002000000048cce1823313199f88bb583a480954a576d4fae160deef9bf25daa6e50bfbc39fa284e3c15fcda01e400000000000000ffffffffa00f0000000000000000000000000000000000010000000100d3080d000000ffffffff0000ffffffff") + buffer := hex2Buffer(t, "4d534746800000000200000001000000e4000000e4000000010077020500002000000048cce1823313199f88bb583a480954a576d4fae160deef9bf25daa6e50bfbc39fa284e3c15fcda01e400000000000000ffffffffa00f0000000000000000000000000000000000010000000100d3080d000000ffffffff0000ffffffff") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/message_read_resp.go b/opcua/ua/message_read_resp.go index 9a0afaf..dead555 100644 --- a/opcua/ua/message_read_resp.go +++ b/opcua/ua/message_read_resp.go @@ -1,7 +1,7 @@ package ua import ( - "github.com/shoothzj/gox/buffer" + "github.com/libgox/buffer" ) type MessageReadResp struct { diff --git a/opcua/ua/message_read_resp_test.go b/opcua/ua/message_read_resp_test.go index 23b5994..6952c52 100644 --- a/opcua/ua/message_read_resp_test.go +++ b/opcua/ua/message_read_resp_test.go @@ -3,12 +3,11 @@ package ua import ( "testing" - "github.com/shoothzj/gox/testx" "github.com/stretchr/testify/require" ) func TestDecodeMessageReadResp(t *testing.T) { - buffer := testx.Hex2Buffer(t, "4d5347464a00000002000000010000001a040000e400000001007a02207b4e3c15fcda01e40000000000000000ffffffff00000001000000050600000000206b273c15fcda01ffffffff") + buffer := hex2Buffer(t, "4d5347464a00000002000000010000001a040000e400000001007a02207b4e3c15fcda01e40000000000000000ffffffff00000001000000050600000000206b273c15fcda01ffffffff") err := buffer.Skip(8) require.Nil(t, err) } diff --git a/opcua/ua/test_util.go b/opcua/ua/test_util.go new file mode 100644 index 0000000..68c05e7 --- /dev/null +++ b/opcua/ua/test_util.go @@ -0,0 +1,15 @@ +package ua + +import ( + "encoding/hex" + "testing" + + "github.com/libgox/buffer" + "github.com/stretchr/testify/require" +) + +func hex2Buffer(t *testing.T, str string) *buffer.Buffer { + bytes, err := hex.DecodeString(str) + require.NoError(t, err) + return buffer.NewBufferFromBytes(bytes) +}