// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package trace

import 

// Writer is a test trace writer.
type Writer struct {
	bytes.Buffer
}

func () *Writer {
	 := new(Writer)
	.Write([]byte("go 1.9 trace\x00\x00\x00\x00"))
	return 
}

// Emit writes an event record to the trace.
// See Event types for valid types and required arguments.
func ( *Writer) ( byte,  ...uint64) {
	 := byte(len()) - 1
	if  > 3 {
		 = 3
	}
	 := []byte{ | <<6}
	if  == 3 {
		 = append(, 0)
	}
	for ,  := range  {
		 = appendVarint(, )
	}
	if  == 3 {
		[1] = byte(len() - 2)
	}
	,  := .Write()
	if  != len() ||  != nil {
		panic("failed to write")
	}
}

func appendVarint( []byte,  uint64) []byte {
	for ;  >= 0x80;  >>= 7 {
		 = append(, 0x80|byte())
	}
	 = append(, byte())
	return 
}