當前位置: 首頁>>代碼示例>>Golang>>正文


Golang streambuf.New函數代碼示例

本文整理匯總了Golang中github.com/elastic/beats/libbeat/common/streambuf.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: sendAck

func sendAck(transp *mockTransport, seq uint32) {
	buf := streambuf.New(nil)
	buf.WriteByte('2')
	buf.WriteByte('A')
	buf.WriteNetUint32(seq)
	transp.sendBytes(buf.Bytes())
}
開發者ID:davidsoloman,項目名稱:beats,代碼行數:7,代碼來源:client_test.go

示例2: TestSimpleEvent

func TestSimpleEvent(t *testing.T) {
	transp := newMockTransport()
	client := newClientTestDriver(
		newLumberjackClient(transp, testMaxWindowSize, 5*time.Second))

	event := common.MapStr{"name": "me", "line": 10}
	client.Publish([]common.MapStr{event})

	// receive window message
	buf := streambuf.New(nil)
	win, err := recvMessage(buf, transp)
	assert.Nil(t, err)

	// receive data message
	msg, err := recvMessage(buf, transp)
	assert.Nil(t, err)

	// send ack
	sendAck(transp, 1)

	// stop test driver
	transp.Close()
	client.Stop()

	// validate
	assert.NotNil(t, win)
	assert.NotNil(t, msg)
	assert.Equal(t, 1, len(msg.events))
	msg = msg.events[0]
	assert.Equal(t, "me", msg.doc["name"])
	assert.Equal(t, 10.0, msg.doc["line"])
}
開發者ID:davidsoloman,項目名稱:beats,代碼行數:32,代碼來源:client_test.go

示例3: sendACK

func (c *mockConn) sendACK(seq uint32) {
	buf := streambuf.New(nil)
	buf.WriteByte('2')
	buf.WriteByte('A')
	buf.WriteNetUint32(seq)
	c.conn.Write(buf.Bytes())
}
開發者ID:radoondas,項目名稱:apachebeat,代碼行數:7,代碼來源:protocol_test.go

示例4: testCloseAfterWindowSize

func testCloseAfterWindowSize(t *testing.T, factory clientFactory) {
	enableLogging([]string{"*"})
	server := transptest.NewMockServerTCP(t, 100*time.Millisecond, "", nil)

	sock, transp, err := server.ConnectPair()
	if err != nil {
		t.Fatalf("Failed to connect server and client: %v", err)
	}
	client := factory(transp)
	conn := &mockConn{sock, streambuf.New(nil)}
	defer transp.Close()
	defer sock.Close()
	defer client.Stop()

	client.Publish([]common.MapStr{common.MapStr{
		"type":    "test",
		"message": "hello world",
	}})

	_, err = conn.recvMessage()
	if err != nil {
		t.Fatalf("failed to read window size message: %v", err)
	}

}
開發者ID:radoondas,項目名稱:apachebeat,代碼行數:25,代碼來源:client_test.go

示例5: addDatagram

func (msg *udpMessage) addDatagram(
	header *mcUdpHeader,
	data []byte,
) *streambuf.Buffer {
	if msg.isComplete {
		return nil
	}

	if msg.numDatagrams == 1 {
		msg.isComplete = true
		return streambuf.NewFixed(data)
	}

	if msg.count < msg.numDatagrams {
		if msg.datagrams[header.seqNumber] != nil {
			return nil
		}
		msg.datagrams[header.seqNumber] = data
		msg.count++
	}

	if msg.count < msg.numDatagrams {
		return nil
	}

	buffer := streambuf.New(nil)
	for _, payload := range msg.datagrams {
		buffer.Append(payload)
	}
	msg.isComplete = true
	msg.datagrams = nil
	buffer.Fix()
	return buffer
}
開發者ID:ChongFeng,項目名稱:beats,代碼行數:34,代碼來源:plugin_udp.go

示例6: newTestParser

func newTestParser(tst *testing.T, state parserState) *testParser {
	t := &testParser{
		testing: tst,
		parser:  newParser(&defaultTestParserConfig),
		buf:     streambuf.New(nil),
	}
	return t
}
開發者ID:davidsoloman,項目名稱:beats,代碼行數:8,代碼來源:parse_test.go

示例7: sockSendACK

func sockSendACK(out io.Writer, seq uint32) error {
	buf := streambuf.New(nil)
	buf.WriteByte('2')
	buf.WriteByte('A')
	buf.WriteNetUint32(seq)
	_, err := out.Write(buf.Bytes())
	return err
}
開發者ID:junk16,項目名稱:beats,代碼行數:8,代碼來源:logstash_test.go

示例8: prepareBinMessage

func prepareBinMessage(
	hdr *binHeader,
	extras []extraFn,
	key valueFn,
	value valueFn,
) (*streambuf.Buffer, error) {
	buf := streambuf.New(nil)
	gen := genBinMessage(hdr, extras, key, value)
	err := gen(buf)
	return buf, err
}
開發者ID:davidsoloman,項目名稱:beats,代碼行數:11,代碼來源:parse_test.go

示例9: NewLine

// NewLine creates a new Line reader object
func NewLine(input io.Reader, codec encoding.Encoding, bufferSize int) (*Line, error) {

	encoder := codec.NewEncoder()

	// Create newline char based on encoding
	nl, _, err := transform.Bytes(encoder, []byte{'\n'})
	if err != nil {
		return nil, err
	}

	return &Line{
		reader:     input,
		codec:      codec,
		bufferSize: bufferSize,
		nl:         nl,
		decoder:    codec.NewDecoder(),
		inBuffer:   streambuf.New(nil),
		outBuffer:  streambuf.New(nil),
	}, nil
}
開發者ID:YaSuenag,項目名稱:hsbeat,代碼行數:21,代碼來源:line.go

示例10: init

func (l *LineReader) init(
	input io.Reader,
	codec encoding.Encoding,
	bufferSize int,
) error {
	l.rawInput = input
	l.codec = codec
	l.bufferSize = bufferSize

	l.codec.NewEncoder()
	nl, _, err := transform.Bytes(l.codec.NewEncoder(), []byte{'\n'})
	if err != nil {
		return err
	}

	l.nl = nl
	l.decoder = l.codec.NewDecoder()
	l.inBuffer = streambuf.New(nil)
	l.outBuffer = streambuf.New(nil)
	return nil
}
開發者ID:davidsoloman,項目名稱:beats,代碼行數:21,代碼來源:reader.go

示例11: testStructuredEvent

func testStructuredEvent(t *testing.T, factory clientFactory) {
	enableLogging([]string{"*"})
	server := transptest.NewMockServerTCP(t, 1*time.Second, "", nil)

	sock, transp, err := server.ConnectPair()
	if err != nil {
		t.Fatalf("Failed to connect server and client: %v", err)
	}
	client := factory(transp)
	conn := &mockConn{sock, streambuf.New(nil)}
	defer transp.Close()
	defer sock.Close()

	event := common.MapStr{
		"type": "test",
		"name": "test",
		"struct": common.MapStr{
			"field1": 1,
			"field2": true,
			"field3": []int{1, 2, 3},
			"field4": []interface{}{
				1,
				"test",
				common.MapStr{
					"sub": "field",
				},
			},
			"field5": common.MapStr{
				"sub1": 2,
			},
		},
	}
	client.Publish([]common.MapStr{event})

	win, err := conn.recvMessage()
	assert.Nil(t, err)

	msg, err := conn.recvMessage()
	assert.Nil(t, err)

	conn.sendACK(1)
	defer client.Stop()

	// validate
	assert.NotNil(t, win)
	assert.NotNil(t, msg)
	assert.Equal(t, 1, len(msg.events))
	msg = msg.events[0]
	assert.Equal(t, "test", msg.doc["name"])
	assert.Equal(t, 1.0, msg.doc.get("struct.field1"))
	assert.Equal(t, true, msg.doc.get("struct.field2"))
	assert.Equal(t, 2.0, msg.doc.get("struct.field5.sub1"))
}
開發者ID:radoondas,項目名稱:apachebeat,代碼行數:53,代碼來源:client_test.go

示例12: connectPair

func (s *protocolServer) connectPair(compressLevel int) (*mockConn, *protocol, error) {
	client, transp, err := s.MockServer.ConnectPair()
	if err != nil {
		return nil, nil, err
	}

	proto, err := newClientProcol(transp, 100*time.Millisecond, compressLevel, "test")
	if err != nil {
		return nil, nil, err
	}

	conn := &mockConn{client, streambuf.New(nil)}
	return conn, proto, nil
}
開發者ID:radoondas,項目名稱:apachebeat,代碼行數:14,代碼來源:protocol_test.go

示例13: connectPair

func (s *clientServer) connectPair(compressLevel int) (*mockConn, *client, error) {
	client, transp, err := s.mockServer.connectPair(100 * time.Millisecond)
	if err != nil {
		return nil, nil, err
	}

	lc, err := newLumberjackClient(transp, compressLevel,
		defaultMaxWindowSize, 100*time.Millisecond)
	if err != nil {
		return nil, nil, err
	}

	conn := &mockConn{client, streambuf.New(nil)}
	return conn, lc, nil
}
開發者ID:junk16,項目名稱:beats,代碼行數:15,代碼來源:sync_test.go

示例14: TestStructuredEvent

func TestStructuredEvent(t *testing.T) {
	transp := newMockTransport()
	client := newClientTestDriver(
		newLumberjackClient(transp, testMaxWindowSize, 5*time.Second))
	event := common.MapStr{
		"name": "test",
		"struct": common.MapStr{
			"field1": 1,
			"field2": true,
			"field3": []int{1, 2, 3},
			"field4": []interface{}{
				1,
				"test",
				common.MapStr{
					"sub": "field",
				},
			},
			"field5": common.MapStr{
				"sub1": 2,
			},
		},
	}
	client.Publish([]common.MapStr{event})

	buf := streambuf.New(nil)
	win, err := recvMessage(buf, transp)
	assert.Nil(t, err)

	msg, err := recvMessage(buf, transp)
	assert.Nil(t, err)

	sendAck(transp, 1)

	transp.Close()
	client.Stop()

	// validate
	assert.NotNil(t, win)
	assert.NotNil(t, msg)
	assert.Equal(t, 1, len(msg.events))
	msg = msg.events[0]
	assert.Equal(t, "test", msg.doc["name"])
	assert.Equal(t, 1.0, msg.doc.get("struct.field1"))
	assert.Equal(t, true, msg.doc.get("struct.field2"))
	assert.Equal(t, 2.0, msg.doc.get("struct.field5.sub1"))
}
開發者ID:davidsoloman,項目名稱:beats,代碼行數:46,代碼來源:client_test.go

示例15: testSimpleEvent

func testSimpleEvent(t *testing.T, factory clientFactory) {
	enableLogging([]string{"*"})
	server := newMockServerTCP(t, 1*time.Second, "")

	sock, transp, err := server.connectPair(1 * time.Second)
	if err != nil {
		t.Fatalf("Failed to connect server and client: %v", err)
	}
	client := factory(transp)
	conn := &mockConn{sock, streambuf.New(nil)}
	defer transp.Close()
	defer sock.Close()

	event := common.MapStr{"name": "me", "line": 10}
	client.Publish([]common.MapStr{event})

	// receive window message
	err = sock.SetReadDeadline(time.Now().Add(1 * time.Second))
	win, err := conn.recvMessage()
	assert.Nil(t, err)

	// receive data message
	msg, err := conn.recvMessage()
	assert.Nil(t, err)

	// send ack
	conn.sendACK(1)

	client.Stop()

	// validate
	assert.NotNil(t, win)
	assert.NotNil(t, msg)
	assert.Equal(t, 1, len(msg.events))
	msg = msg.events[0]
	assert.Equal(t, "me", msg.doc["name"])
	assert.Equal(t, 10.0, msg.doc["line"])
}
開發者ID:jarpy,項目名稱:beats,代碼行數:38,代碼來源:client_test.go


注:本文中的github.com/elastic/beats/libbeat/common/streambuf.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。