当前位置: 首页>>代码示例>>Golang>>正文


Golang Message.Force方法代码示例

本文整理汇总了Golang中femebe.Message.Force方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.Force方法的具体用法?Golang Message.Force怎么用?Golang Message.Force使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在femebe.Message的用法示例。


在下文中一共展示了Message.Force方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestStartupSerDes

func TestStartupSerDes(t *testing.T) {
	ms, _ := newTestClientStream(t)
	var m femebe.Message
	s := Startup{Params: make(map[string]string)}

	s.Params["hello"] = "world"
	s.Params["goodbye"] = "world"
	s.Params["glory"] = "spite"

	s.FillMessage(&m)
	ms.Send(&m)

	var deserM femebe.Message
	ms.Next(&deserM)

	serBytes, _ := m.Force()
	deserBytes, _ := deserM.Force()
	if !bytes.Equal(serBytes, deserBytes) {
		t.Fatal()
	}
}
开发者ID:ericfode,项目名称:femebe,代码行数:21,代码来源:first_test.go

示例2: processLogMsg

// Process a log message, sending it to the client.
func processLogMsg(die dieCh, lpc *logplexc.Client, msgInit msgInit,
	sr *serveRecord, exit exitFn) {
	var m femebe.Message

	for {
		// Poll request to exit
		select {
		case <-die:
			return
		default:
			break
		}

		msgInit(&m, exit)

		// Refuse to handle any log message above an arbitrary
		// size.  Furthermore, exit the worker, closing the0
		// connection, so that the client doesn't even bother
		// to wait for this process to drain the oversized
		// item and anything following it; these will be
		// dropped.  It's on the client to gracefully handle
		// the error and re-connect after this happens.
		if m.Size() > 1*MB {
			exit("client %q sent oversized log record")
		}

		payload, err := m.Force()
		if err != nil {
			exit("could not retrieve payload of message: %v",
				err)
		}

		var lr logRecord
		parseLogRecord(&lr, payload, exit)
		processLogRec(&lr, lpc, sr, exit)
	}
}
开发者ID:uhoh-itsmaciek,项目名称:pg_logplexcollector,代码行数:38,代码来源:pg_logplexcollector.go

示例3: ReadStartupMessage

func ReadStartupMessage(m *femebe.Message) (*Startup, error) {
	var err error

	if remainingSz := m.Size() - 4; remainingSz > 10000 {
		// Startup packets longer than this are considered
		// invalid.  Copied from the PostgreSQL source code.
		err = ErrTooBig{fmt.Errorf(
			"Rejecting oversized startup packet: got %v",
			m.Size())}
		return nil, err
	} else if remainingSz < 4 {
		// We expect all initialization messages to
		// have at least a 4-byte header
		err = ErrWrongSize{
			fmt.Errorf(
				"Expected message of at least 4 bytes; got %v",
				remainingSz)}
		return nil, err
	}

	body, err := m.Force()
	if err != nil {
		return nil, err
	}

	var b femebe.Reader
	b.InitReader(body)
	protoVer, _ := femebe.ReadInt32(&b)

	const SUPPORTED_PROTOVER = 0x00030000
	if protoVer != SUPPORTED_PROTOVER {
		err = ErrStartupVersion{
			fmt.Errorf("bad version: got %x expected %x",
				protoVer, SUPPORTED_PROTOVER)}
		return nil, err
	}

	params := make(map[string]string)
	for remaining := b.Len(); remaining > 1; {
		key, err := femebe.ReadCString(&b)
		if err != nil {
			return nil, err
		}

		val, err := femebe.ReadCString(&b)
		if err != nil {
			return nil, err
		}

		remaining -= len(key) + len(val) + 2 /* null bytes */
		params[key] = val
	}

	// Fidelity check on the startup packet, whereby the last byte
	// must be a NUL.
	if d, _ := femebe.ReadByte(&b); d != '\000' {
		return nil, ErrStartupFmt{
			errors.New("malformed startup packet")}
	}

	return &Startup{params}, nil
}
开发者ID:ericfode,项目名称:femebe,代码行数:62,代码来源:first.go


注:本文中的femebe.Message.Force方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。