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


Golang Writer.WriteByte方法代码示例

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


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

示例1: writeOne

func writeOne(bw *bufio.Writer, x interface{}) error {
	switch y := x.(type) {
	case bool:
		fmt.Fprintf(bw, "%t", y)
	case byte:
		fmt.Fprintf(bw, "'%c'", y)
	case string:
		fmt.Fprintf(bw, "\"%s\"", y)
	case int, int64:
		fmt.Fprintf(bw, "%d", y)
	case float32, float64:
		fmt.Fprintf(bw, "%f", y)
	default:
		slice := reflect.ValueOf(x)
		if slice.Kind() != reflect.Slice {
			return NewErrType(slice.Type())
		}
		bw.WriteByte('[')
		for i := 0; i < slice.Len(); i++ {
			if i != 0 {
				bw.WriteString(", ")
			}
			elem := slice.Index(i)
			if err := writeOne(bw, elem.Interface()); err != nil {
				return err
			}
		}
		bw.WriteByte(']')
	}
	return nil
}
开发者ID:webglider,项目名称:gettc,代码行数:31,代码来源:writer.go

示例2: writeTo

func (f *FML) writeTo(parentKey string, writer *bufio.Writer) {
	for key, val := range f.dict {
		fullKey := key
		if len(parentKey) != 0 {
			fullKey = parentKey + "." + key
		}
		switch v := val.(type) {
		case []*FML:
			defer func() {
				writeNodeName(fullKey, writer)
				for i := 0; i < len(v); i++ {
					writer.Write([]byte{'-', ' '})
					v[i].writeTo(fullKey, writer)
				}
			}()
		case *FML:
			defer func() {
				writeNodeName(fullKey, writer)
				v.writeTo(fullKey, writer)
			}()
		default:
			//log.Println("write",key)
			writer.WriteString(key)
			writer.WriteByte(':')
			writer.WriteString(wrapVal(v))
			//writer.WriteString("after key value")
			writer.WriteByte('\n')
		}
	}
}
开发者ID:FIPress,项目名称:fml,代码行数:30,代码来源:fml.go

示例3: HandshakeSample

func HandshakeSample(c net.Conn, br *bufio.Reader, bw *bufio.Writer, timeout time.Duration) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = r.(error)
		}
	}()
	// Send C0+C1
	err = bw.WriteByte(0x03)
	c1 := CreateRandomBlock(RTMP_SIG_SIZE)
	for i := 0; i < 8; i++ {
		c1[i] = 0
	}
	bw.Write(c1)
	err = bw.Flush()
	CheckError(err, "Handshake() Flush C0+C1")
	// Read S0+S1+S2
	s0, err := br.ReadByte()
	CheckError(err, "Handshake() Read S0")
	if s0 != 0x03 {
		return errors.New(fmt.Sprintf("Handshake() Got S0: %x", s0))
	}
	s1 := make([]byte, RTMP_SIG_SIZE)
	_, err = io.ReadAtLeast(br, s1, RTMP_SIG_SIZE)
	CheckError(err, "Handshake() Read S1")
	bw.Write(s1)
	err = bw.Flush()
	CheckError(err, "Handshake() Flush C2")
	_, err = io.ReadAtLeast(br, s1, RTMP_SIG_SIZE)
	CheckError(err, "Handshake() Read S2")
	return
}
开发者ID:TrevorSStone,项目名称:gortmp,代码行数:31,代码来源:handshake.go

示例4: Write

// Write embeddings to a binary file accepted by word2vec
func (e *Embeddings) Write(w *bufio.Writer) error {
	nWords := len(e.words)
	if nWords == 0 {
		return nil
	}

	if e.embedSize == 0 {
		return nil
	}

	if _, err := fmt.Fprintf(w, "%d %d\n", nWords, e.embedSize); err != nil {
		return err
	}

	for idx, word := range e.words {
		if _, err := w.WriteString(word + " "); err != nil {
			return err
		}

		if err := binary.Write(w, binary.LittleEndian, e.lookupIdx(idx)); err != nil {
			return err
		}

		w.WriteByte(0x0a)
	}

	return nil
}
开发者ID:postfix,项目名称:go2vec,代码行数:29,代码来源:go2vec.go

示例5: emit_nocall_ref

func emit_nocall_ref(start_pos int64, n int64, ref_ain *simplestream.SimpleStream, aout *bufio.Writer) (int64, error) {

	end_pos := start_pos + n
	for ; start_pos < end_pos; start_pos++ {

		if ref_ain.Pos >= ref_ain.N {
			if e := ref_ain.Refresh(); e != nil {
				return 0, e
			}
		}

		bp := ref_ain.Buf[ref_ain.Pos]
		ref_ain.Pos++

		switch bp {
		case 'a', 'A':
			aout.WriteByte('A')
		case 'c', 'C':
			aout.WriteByte('C')
		case 'g', 'G':
			aout.WriteByte('G')
		case 't', 'T':
			aout.WriteByte('T')
		default:
			aout.WriteByte(bp)
		}

		gCounter++

	}

	return start_pos, nil

}
开发者ID:abeconnelly,项目名称:pasta,代码行数:34,代码来源:gvcf2pasta.go

示例6: bcastCommit

func (r *Replica) bcastCommit(cstruct []int32) {
	defer func() {
		if err := recover(); err != nil {
			dlog.Println("Commit bcast failed:", err)
		}
	}()
	args := &gpaxosproto.Commit{cstruct}

	n := r.N - 1
	q := r.Id
	var w *bufio.Writer
	for sent := 0; sent < n; {
		q = (q + 1) % int32(r.N)
		if q == r.Id {
			break
		}
		if !r.Alive[q] {
			continue
		}
		sent++
		w = r.PeerWriters[q]
		w.WriteByte(gpaxosproto.COMMIT)
		args.Marshal(w)
		w.Flush()
	}
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:26,代码来源:gpaxos.go

示例7: writeFrame

/*
	Frame physical write.
*/
func (f *Frame) writeFrame(w *bufio.Writer, l string) error {
	// Write the frame Command
	if _, e := w.WriteString(f.Command + "\n"); e != nil {
		return e
	}
	// Content length - Always add it if client does not suppress it and
	// does not supply it.
	if _, ok := f.Headers.Contains("suppress-content-length"); !ok {
		if _, clok := f.Headers.Contains("content-length"); !clok {
			f.Headers = append(f.Headers, "content-length", strconv.Itoa(len(f.Body)))
		}
	}
	// Write the frame Headers
	for i := 0; i < len(f.Headers); i += 2 {
		if l > SPL_10 && f.Command != CONNECT {
			f.Headers[i] = encode(f.Headers[i])
			f.Headers[i+1] = encode(f.Headers[i+1])
		}
		_, e := w.WriteString(f.Headers[i] + ":" + f.Headers[i+1] + "\n")
		if e != nil {
			return e
		}
	}
	// Write the last Header LF
	if e := w.WriteByte('\n'); e != nil {
		return e
	}
	// Write the body
	if len(f.Body) != 0 { // Foolish to write 0 length data
		if _, e := w.Write(f.Body); e != nil {
			return e
		}
	}
	return nil
}
开发者ID:danieltmiles,项目名称:stompngo,代码行数:38,代码来源:writer.go

示例8: bcastPrepare

func (r *Replica) bcastPrepare(replica int32, instance int32, ballot int32) {
	defer func() {
		if err := recover(); err != nil {
			dlog.Println("Prepare bcast failed:", err)
		}
	}()
	args := &gpaxosproto.Prepare{r.Id, instance, ballot}

	n := r.N - 1
	//TODO: fix quorum size
	if r.Thrifty {
		n = r.N >> 1
	}
	q := r.Id
	var w *bufio.Writer
	for sent := 0; sent < n; {
		q = (q + 1) % int32(r.N)
		if q == r.Id {
			dlog.Println("Not enough replicas alive!")
			break
		}
		if !r.Alive[q] {
			continue
		}
		sent++
		w = r.PeerWriters[q]
		w.WriteByte(gpaxosproto.PREPARE)
		args.Marshal(w)
		w.Flush()
	}
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:31,代码来源:gpaxos.go

示例9: bcast2a

func (r *Replica) bcast2a(balnum int32, cstruct []int32, fast bool) {
	defer func() {
		if err := recover(); err != nil {
			dlog.Println("1a bcast failed:", err)
		}
	}()
	args := &gpaxosproto.M_2a{r.Id, balnum, cstruct}

	n := r.N - 1
	if r.Thrifty {
		if fast {
			n = r.fastQSize - 1
		} else {
			n = r.N >> 1
		}
	}
	q := r.Id
	var w *bufio.Writer
	for sent := 0; sent < n; {
		q = (q + 1) % int32(r.N)
		if q == r.Id {
			break
		}
		if !r.Alive[q] {
			continue
		}
		sent++
		w = r.PeerWriters[q]
		w.WriteByte(gpaxosproto.M2A)
		args.Marshal(w)
		w.Flush()
	}
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:33,代码来源:gpaxos.go

示例10: writeTo

// writeTo serializes the processing instruction to the writer.
func (p *ProcInst) writeTo(w *bufio.Writer) {
	w.WriteString("<?")
	w.WriteString(p.Target)
	w.WriteByte(' ')
	w.WriteString(p.Inst)
	w.WriteString("?>")
}
开发者ID:hzmnet,项目名称:etree,代码行数:8,代码来源:etree.go

示例11: write

/**
 * Write long data packet
 */
func (pkt *packetLongData) write(writer *bufio.Writer) (err os.Error) {
	// Construct packet header
	pkt.header = new(packetHeader)
	pkt.header.length = 7 + uint32(len(pkt.data))
	pkt.header.sequence = pkt.sequence
	err = pkt.header.write(writer)
	if err != nil {
		return
	}
	// Write command
	err = writer.WriteByte(byte(pkt.command))
	if err != nil {
		return
	}
	// Write statement id
	err = pkt.writeNumber(writer, uint64(pkt.statementId), 4)
	if err != nil {
		return
	}
	// Write param number
	err = pkt.writeNumber(writer, uint64(pkt.paramNumber), 2)
	if err != nil {
		return
	}
	// Write data
	_, err = writer.WriteString(pkt.data)
	if err != nil {
		return
	}
	// Flush
	err = writer.Flush()
	return
}
开发者ID:thomaslee,项目名称:GoMySQL,代码行数:36,代码来源:mysql_packet.go

示例12: WriteResponse

func (r *AsyncResponse) WriteResponse(buf *bufio.Writer) error {
	_, err := buf.WriteString("+ASYNC ")
	_, err = buf.WriteString(r.asyncID)
	err = buf.WriteByte(' ')
	err = r.resp.WriteResponse(buf)
	return err
}
开发者ID:vburenin,项目名称:firempq,代码行数:7,代码来源:response.go

示例13: WritePastaByte

func (g *CGIRefVar) WritePastaByte(pasta_ch byte, out *bufio.Writer) {
	out.WriteByte(pasta_ch)
	g.OCounter++
	if (g.LFMod > 0) && (g.OCounter > 0) && ((g.OCounter % g.LFMod) == 0) {
		out.WriteByte('\n')
	}
}
开发者ID:abeconnelly,项目名称:pasta,代码行数:7,代码来源:pasta_cgivar.go

示例14: WriteResponse

func (p *MsgResponseItem) WriteResponse(buf *bufio.Writer) error {

	v := 5
	if p.msg.UnlockTs > 0 {
		v = 6
	}

	err := enc.WriteDictSize(buf, v)
	_, err = buf.WriteString(" ID ")
	err = enc.WriteString(buf, p.msg.StrId)

	_, err = buf.WriteString(" PL ")
	err = enc.WriteBytes(buf, p.payload)

	_, err = buf.WriteString(" ETS ")
	err = enc.WriteInt64(buf, p.msg.ExpireTs)

	_, err = buf.WriteString(" POPCNT ")
	err = enc.WriteInt64(buf, p.msg.PopCount)

	_, err = buf.WriteString(" UTS ")
	err = enc.WriteInt64(buf, p.msg.UnlockTs)

	if p.msg.UnlockTs > 0 {
		_, err = buf.WriteString(" RCPT ")
		_, err = buf.WriteString(enc.EncodeTo36Base(p.msg.SerialNumber))
		err = buf.WriteByte('-')
		_, err = buf.WriteString(enc.EncodeTo36Base(uint64(p.msg.PopCount)))
	}
	return err
}
开发者ID:vburenin,项目名称:firempq,代码行数:31,代码来源:pqmsg_response.go

示例15: groupLs

func groupLs(r *bufio.Reader, w *bufio.Writer, args []string, thisUser *utils.User) (err error) {

	if len(args) != 2 {
		fmt.Println("Wrong number of arguments for call to group-ls:")
		fmt.Println("Format should be: group-ls GID")
		return nil
	}

	err = w.WriteByte(23)
	w.Flush()
	if err != nil {
		return err
	}

	// send the group id
	w.WriteString(args[1] + "\n")
	w.Flush()

	// get success (1) or fail (2)
	success, _ := r.ReadByte()
	if success != 1 {
		fmt.Println("The group does not exist")
		return err
	}

	// get uuids of the group
	result, _ := r.ReadString('\n')
	result = strings.TrimSuffix(strings.TrimSpace(result), ",")

	fmt.Println("Members of Group " + args[1] + ": " + result)

	return err
}
开发者ID:CPSSD,项目名称:MDFS,代码行数:33,代码来源:mdfs-client.go


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