本文整理汇总了Golang中github.com/skriptble/nine/element.Element.WriteBytes方法的典型用法代码示例。如果您正苦于以下问题:Golang Element.WriteBytes方法的具体用法?Golang Element.WriteBytes怎么用?Golang Element.WriteBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skriptble/nine/element.Element
的用法示例。
在下文中一共展示了Element.WriteBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WriteElement
// WriteElement converts the element to bytes and writes to the underlying
// tcp connection. This method should generally be used for basic elements such
// as those used during SASL negotiation. WriteStanzas should be used when
// sending stanzas.
func (t *TCP) WriteElement(el element.Element) error {
var b []byte
b = el.WriteBytes()
_, err := t.Write(b)
return err
}
示例2: TestNext
func TestNext(t *testing.T) {
t.Parallel()
var want, got interface{}
var err error
var el element.Element
pipe1, pipe2 := net.Pipe()
el = element.New("testing").AddAttr("foo", "bar").
SetText("random text").
AddChild(element.New("baz-quux"))
tcpTsp := NewTCP(pipe1, stream.Receiving, nil, true)
// Should be able to get a token from the transport
go func() {
_, err := pipe2.Write(el.WriteBytes())
if err != nil {
t.Errorf("An unexpected error occurred: %s", err)
}
}()
want = el
got, err = tcpTsp.Next()
if err != nil {
t.Errorf("An unexpected error occurred: %s", err)
}
if !reflect.DeepEqual(want, got) {
t.Error("Should be able to get a token from the transport.")
t.Errorf("\nWant:%+v\nGot :%+v", want, got)
}
// Stream element should return token and not attempt to read the entire stream.
pipe1, pipe2 = net.Pipe()
tcpTsp = NewTCP(pipe1, stream.Receiving, nil, true)
go func() {
_, err := pipe2.Write(stream.Header{}.WriteBytes())
if err != nil {
t.Errorf("An unexpected error occurred: %s", err)
}
_, err = pipe2.Write([]byte("<foo/></stream:stream>"))
if err != nil {
t.Errorf("An unexpected error occurred: %s", err)
}
}()
el, err = tcpTsp.Next()
if err != nil {
t.Errorf("An unexpected error occurred: %s", err)
}
if el.Space != namespace.Stream || el.Tag != "stream" {
t.Error("Stream element should return token and not attempt to read the entire stream.")
}
got, err = tcpTsp.Next()
if err != nil {
t.Errorf("An unexpected error occurred: %s", err)
}
want = element.New("foo")
if !reflect.DeepEqual(want, got) {
t.Error("Stream element should return token and not attempt to read the entire stream.")
t.Errorf("\nWant:%+v\nGot :%+v", want, got)
}
}