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


Golang common.WriteExactly函数代码示例

本文整理汇总了Golang中github.com/SlyMarbo/spdy/common.WriteExactly函数的典型用法代码示例。如果您正苦于以下问题:Golang WriteExactly函数的具体用法?Golang WriteExactly怎么用?Golang WriteExactly使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: WriteTo

func (frame *DATA) WriteTo(writer io.Writer) (int64, error) {
	length := len(frame.Data)
	if length > common.MAX_DATA_SIZE {
		return 0, errors.New("Error: Data size too large.")
	}
	if length == 0 && !frame.Flags.FIN() {
		return 0, errors.New("Error: Data is empty.")
	}

	out := make([]byte, 8)

	out[0] = frame.StreamID.B1() // Control bit and Stream ID
	out[1] = frame.StreamID.B2() // Stream ID
	out[2] = frame.StreamID.B3() // Stream ID
	out[3] = frame.StreamID.B4() // Stream ID
	out[4] = byte(frame.Flags)   // Flags
	out[5] = byte(length >> 16)  // Length
	out[6] = byte(length >> 8)   // Length
	out[7] = byte(length)        // Length

	if err := common.WriteExactly(writer, out); err != nil {
		return 0, err
	}

	if err := common.WriteExactly(writer, frame.Data); err != nil {
		return 8, err
	}

	return int64(length + 8), nil
}
开发者ID:rnapier,项目名称:spdy,代码行数:30,代码来源:data.go

示例2: WriteTo

func (frame *SETTINGS) WriteTo(writer io.Writer) (int64, error) {
	c := common.WriteCounter{W: writer}
	settings := encodeSettings(frame.Settings)
	numSettings := uint32(len(frame.Settings))
	length := 4 + len(settings)
	out := make([]byte, 12)

	out[0] = 128                     // Control bit and Version
	out[1] = 3                       // Version
	out[2] = 0                       // Type
	out[3] = 4                       // Type
	out[4] = byte(frame.Flags)       // Flags
	out[5] = byte(length >> 16)      // Length
	out[6] = byte(length >> 8)       // Length
	out[7] = byte(length)            // Length
	out[8] = byte(numSettings >> 24) // Number of Entries
	out[9] = byte(numSettings >> 16) // Number of Entries
	out[10] = byte(numSettings >> 8) // Number of Entries
	out[11] = byte(numSettings)      // Number of Entries

	err := common.WriteExactly(&c, out)
	if err != nil {
		return c.N, err
	}

	err = common.WriteExactly(&c, settings)
	if err != nil {
		return c.N, err
	}

	return c.N, nil
}
开发者ID:vonwenm,项目名称:spdy,代码行数:32,代码来源:settings.go

示例3: WriteTo

func (frame *SYN_STREAM) WriteTo(writer io.Writer) (int64, error) {
	c := common.WriteCounter{W: writer}
	if frame.rawHeader == nil {
		return c.N, errors.New("Error: Headers not written.")
	}
	if !frame.StreamID.Valid() {
		return c.N, common.StreamIdTooLarge
	}
	if frame.StreamID.Zero() {
		return c.N, common.StreamIdIsZero
	}
	if !frame.AssocStreamID.Valid() {
		return c.N, common.StreamIdTooLarge
	}

	header := frame.rawHeader
	length := 10 + len(header)
	out := make([]byte, 18)

	out[0] = 128                       // Control bit and Version
	out[1] = 2                         // Version
	out[2] = 0                         // Type
	out[3] = 1                         // Type
	out[4] = byte(frame.Flags)         // Flags
	out[5] = byte(length >> 16)        // Length
	out[6] = byte(length >> 8)         // Length
	out[7] = byte(length)              // Length
	out[8] = frame.StreamID.B1()       // Stream ID
	out[9] = frame.StreamID.B2()       // Stream ID
	out[10] = frame.StreamID.B3()      // Stream ID
	out[11] = frame.StreamID.B4()      // Stream ID
	out[12] = frame.AssocStreamID.B1() // Associated Stream ID
	out[13] = frame.AssocStreamID.B2() // Associated Stream ID
	out[14] = frame.AssocStreamID.B3() // Associated Stream ID
	out[15] = frame.AssocStreamID.B4() // Associated Stream ID
	out[16] = frame.Priority.Byte(2)   // Priority and Unused
	out[17] = 0                        // Unused

	err := common.WriteExactly(&c, out)
	if err != nil {
		return c.N, err
	}

	err = common.WriteExactly(&c, header)
	if err != nil {
		return c.N, err
	}

	return c.N, nil
}
开发者ID:vonwenm,项目名称:spdy,代码行数:50,代码来源:syn_stream.go

示例4: WriteTo

func (frame *CREDENTIAL) WriteTo(writer io.Writer) (int64, error) {
	c := common.WriteCounter{W: writer}
	proofLength := len(frame.Proof)
	certsLength := 0
	for _, cert := range frame.Certificates {
		certsLength += len(cert.Raw)
	}

	length := 6 + proofLength + certsLength
	out := make([]byte, 14)

	out[0] = 128                      // Control bit and Version
	out[1] = 3                        // Version
	out[2] = 0                        // Type
	out[3] = 10                       // Type
	out[4] = 0                        // common.Flags
	out[5] = byte(length >> 16)       // Length
	out[6] = byte(length >> 8)        // Length
	out[7] = byte(length)             // Length
	out[8] = byte(frame.Slot >> 8)    // Slot
	out[9] = byte(frame.Slot)         // Slot
	out[10] = byte(proofLength >> 24) // Proof Length
	out[11] = byte(proofLength >> 16) // Proof Length
	out[12] = byte(proofLength >> 8)  // Proof Length
	out[13] = byte(proofLength)       // Proof Length

	err := common.WriteExactly(&c, out)
	if err != nil {
		return c.N, err
	}

	if len(frame.Proof) > 0 {
		err = common.WriteExactly(&c, frame.Proof)
		if err != nil {
			return c.N, err
		}
	}

	written := int64(14 + len(frame.Proof))
	for _, cert := range frame.Certificates {
		err = common.WriteExactly(&c, cert.Raw)
		if err != nil {
			return c.N, err
		}
		written += int64(len(cert.Raw))
	}

	return c.N, nil
}
开发者ID:vonwenm,项目名称:spdy,代码行数:49,代码来源:credential.go

示例5: WriteTo

func (frame *RST_STREAM) WriteTo(writer io.Writer) (int64, error) {
	c := common.WriteCounter{W: writer}
	if !frame.StreamID.Valid() {
		return c.N, common.StreamIdTooLarge
	}

	out := make([]byte, 16)

	out[0] = 128                  // Control bit and Version
	out[1] = 2                    // Version
	out[2] = 0                    // Type
	out[3] = 3                    // Type
	out[4] = 0                    // Flags
	out[5] = 0                    // Length
	out[6] = 0                    // Length
	out[7] = 8                    // Length
	out[8] = frame.StreamID.B1()  // Stream ID
	out[9] = frame.StreamID.B2()  // Stream ID
	out[10] = frame.StreamID.B3() // Stream ID
	out[11] = frame.StreamID.B4() // Stream ID
	out[12] = frame.Status.B1()   // Status
	out[13] = frame.Status.B2()   // Status
	out[14] = frame.Status.B3()   // Status
	out[15] = frame.Status.B4()   // Status

	err := common.WriteExactly(&c, out)
	if err != nil {
		return c.N, err
	}

	return c.N, nil
}
开发者ID:vonwenm,项目名称:spdy,代码行数:32,代码来源:rst_stream.go

示例6: WriteTo

func (frame *GOAWAY) WriteTo(writer io.Writer) (int64, error) {
	if !frame.LastGoodStreamID.Valid() {
		return 0, common.StreamIdTooLarge
	}

	out := make([]byte, 16)

	out[0] = 128                          // Control bit and Version
	out[1] = 3                            // Version
	out[2] = 0                            // Type
	out[3] = 7                            // Type
	out[4] = 0                            // Flags
	out[5] = 0                            // Length
	out[6] = 0                            // Length
	out[7] = 8                            // Length
	out[8] = frame.LastGoodStreamID.B1()  // Last Good Stream ID
	out[9] = frame.LastGoodStreamID.B2()  // Last Good Stream ID
	out[10] = frame.LastGoodStreamID.B3() // Last Good Stream ID
	out[11] = frame.LastGoodStreamID.B4() // Last Good Stream ID
	out[12] = byte(frame.Status >> 24)    // Status Code
	out[13] = byte(frame.Status >> 16)    // Status Code
	out[14] = byte(frame.Status >> 8)     // Status Code
	out[15] = byte(frame.Status)          // Status Code

	err := common.WriteExactly(writer, out)
	if err != nil {
		return 0, err
	}

	return 16, nil
}
开发者ID:rnapier,项目名称:spdy,代码行数:31,代码来源:goaway.go

示例7: WriteTo

func (frame *WINDOW_UPDATE) WriteTo(writer io.Writer) (int64, error) {
	c := common.WriteCounter{W: writer}
	out := make([]byte, 16)

	out[0] = 128                                     // Control bit and Version
	out[1] = 3                                       // Version
	out[2] = 0                                       // Type
	out[3] = 9                                       // Type
	out[4] = 0                                       // Flags
	out[5] = 0                                       // Length
	out[6] = 0                                       // Length
	out[7] = 8                                       // Length
	out[8] = frame.StreamID.B1()                     // Stream ID
	out[9] = frame.StreamID.B2()                     // Stream ID
	out[10] = frame.StreamID.B3()                    // Stream ID
	out[11] = frame.StreamID.B4()                    // Stream ID
	out[12] = byte(frame.DeltaWindowSize>>24) & 0x7f // Delta Window Size
	out[13] = byte(frame.DeltaWindowSize >> 16)      // Delta Window Size
	out[14] = byte(frame.DeltaWindowSize >> 8)       // Delta Window Size
	out[15] = byte(frame.DeltaWindowSize)            // Delta Window Size

	err := common.WriteExactly(&c, out)
	if err != nil {
		return c.N, err
	}

	return c.N, nil
}
开发者ID:vonwenm,项目名称:spdy,代码行数:28,代码来源:window_update.go

示例8: WriteTo

func (frame *GOAWAY) WriteTo(writer io.Writer) (int64, error) {
	c := common.WriteCounter{W: writer}
	if !frame.LastGoodStreamID.Valid() {
		return c.N, common.StreamIdTooLarge
	}

	out := make([]byte, 12)

	out[0] = 128                          // Control bit and Version
	out[1] = 2                            // Version
	out[2] = 0                            // Type
	out[3] = 7                            // Type
	out[4] = 0                            // Flags
	out[5] = 0                            // Length
	out[6] = 0                            // Length
	out[7] = 4                            // Length
	out[8] = frame.LastGoodStreamID.B1()  // Last Good Stream ID
	out[9] = frame.LastGoodStreamID.B2()  // Last Good Stream ID
	out[10] = frame.LastGoodStreamID.B3() // Last Good Stream ID
	out[11] = frame.LastGoodStreamID.B4() // Last Good Stream ID

	err := common.WriteExactly(&c, out)
	if err != nil {
		return c.N, err
	}

	return c.N, nil
}
开发者ID:vonwenm,项目名称:spdy,代码行数:28,代码来源:goaway.go

示例9: WriteTo

func (frame *SYN_REPLY) WriteTo(writer io.Writer) (int64, error) {
	if frame.rawHeader == nil {
		return 0, errors.New("Error: Header not written.")
	}
	if !frame.StreamID.Valid() {
		return 0, common.StreamIdTooLarge
	}
	if frame.StreamID.Zero() {
		return 0, common.StreamIdIsZero
	}

	header := frame.rawHeader
	length := 6 + len(header)
	out := make([]byte, 14)

	out[0] = 128                  // Control bit and Version
	out[1] = 2                    // Version
	out[2] = 0                    // Type
	out[3] = 2                    // Type
	out[4] = byte(frame.Flags)    // Flags
	out[5] = byte(length >> 16)   // Length
	out[6] = byte(length >> 8)    // Length
	out[7] = byte(length)         // Length
	out[8] = frame.StreamID.B1()  // Stream ID
	out[9] = frame.StreamID.B2()  // Stream ID
	out[10] = frame.StreamID.B3() // Stream ID
	out[11] = frame.StreamID.B4() // Stream ID
	out[12] = 0                   // Unused
	out[13] = 0                   // Unused

	err := common.WriteExactly(writer, out)
	if err != nil {
		return 0, err
	}

	err = common.WriteExactly(writer, header)
	if err != nil {
		return 14, err
	}

	return int64(len(header) + 14), nil
}
开发者ID:rnapier,项目名称:spdy,代码行数:42,代码来源:syn_reply.go

示例10: WriteTo

func (frame *HEADERS) WriteTo(writer io.Writer) (int64, error) {
	c := common.WriteCounter{W: writer}
	if frame.rawHeader == nil {
		return c.N, errors.New("Error: Headers not written.")
	}
	if !frame.StreamID.Valid() {
		return c.N, common.StreamIdTooLarge
	}
	if frame.StreamID.Zero() {
		return c.N, common.StreamIdIsZero
	}

	header := frame.rawHeader
	length := 4 + len(header)
	out := make([]byte, 16)

	out[0] = 128                  // Control bit and Version
	out[1] = 2                    // Version
	out[2] = 0                    // Type
	out[3] = 8                    // Type
	out[4] = byte(frame.Flags)    // Flags
	out[5] = byte(length >> 16)   // Length
	out[6] = byte(length >> 8)    // Length
	out[7] = byte(length)         // Length
	out[8] = frame.StreamID.B1()  // Stream ID
	out[9] = frame.StreamID.B2()  // Stream ID
	out[10] = frame.StreamID.B3() // Stream ID
	out[11] = frame.StreamID.B4() // Stream ID

	err := common.WriteExactly(&c, out)
	if err != nil {
		return c.N, err
	}

	err = common.WriteExactly(&c, header)
	if err != nil {
		return c.N, err
	}

	return c.N, nil
}
开发者ID:vonwenm,项目名称:spdy,代码行数:41,代码来源:headers.go

示例11: WriteTo

func (frame *PING) WriteTo(writer io.Writer) (int64, error) {
	out := make([]byte, 12)

	out[0] = 128                      // Control bit and Version
	out[1] = 2                        // Version
	out[2] = 0                        // Type
	out[3] = 6                        // Type
	out[4] = 0                        // Flags
	out[5] = 0                        // Length
	out[6] = 0                        // Length
	out[7] = 4                        // Length
	out[8] = byte(frame.PingID >> 24) // Ping ID
	out[9] = byte(frame.PingID >> 16) // Ping ID
	out[10] = byte(frame.PingID >> 8) // Ping ID
	out[11] = byte(frame.PingID)      // Ping ID

	err := common.WriteExactly(writer, out)
	if err != nil {
		return 0, err
	}

	return 12, nil
}
开发者ID:rnapier,项目名称:spdy,代码行数:23,代码来源:ping.go


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