本文整理汇总了Golang中github.com/MJKWoolnough/byteio.StickyWriter.WriteInt32方法的典型用法代码示例。如果您正苦于以下问题:Golang StickyWriter.WriteInt32方法的具体用法?Golang StickyWriter.WriteInt32怎么用?Golang StickyWriter.WriteInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/MJKWoolnough/byteio.StickyWriter
的用法示例。
在下文中一共展示了StickyWriter.WriteInt32方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: transferFile
//.........这里部分代码省略.........
return
}
defer conn.Close()
w := byteio.StickyWriter{Writer: byteio.LittleEndianWriter{Writer: conn}}
r := byteio.StickyReader{Reader: byteio.LittleEndianReader{Reader: conn}}
pb := progress.New(color.RGBA{255, 0, 0, 0}, color.RGBA{0, 0, 255, 0}, 400, 50)
d.AppendChild(pb)
if url.Checked {
w.WriteUint8(typeID << 1)
data.WriteString(&w, urlI.Value)
length := int(r.ReadInt32())
total := 0
for total < length {
switch v := r.ReadUint8(); v {
case 1:
i := int(r.ReadInt32())
total += i
pb.Percent(100 * total / length)
default:
xjs.SetInnerText(status, ReadError(&r).Error())
return
}
}
} else {
f := files.NewFileReader(files.NewFile(fileI.Files()[0]))
l := f.Len()
if l == 0 {
xjs.SetInnerText(status, "Zero-length file")
return
}
w.WriteUint8(typeID<<1 | 1)
w.WriteInt32(int32(l))
io.Copy(&w, pb.Reader(f, l))
}
d.RemoveChild(pb)
xjs.SetInnerText(status, "Checking File")
data.WriteString(&w, name.Value)
var ctx *dom.CanvasRenderingContext2D
for {
switch v := r.ReadUint8(); v {
case 0:
if r.Err != nil {
xjs.SetInnerText(status, r.Err.Error())
} else {
xjs.SetInnerText(status, ReadError(&r).Error())
}
return
case 1:
files := make([]xform.Option, r.ReadInt16())
for i := range files {
files[i] = xform.Option{
Value: strconv.Itoa(i),
Label: data.ReadString(&r),
}
}
j := xform.SelectBox("files", files...)
sel := xjs.SetInnerText(xdom.Button(), "Select")
fo := overlay.New(xjs.AppendChildren(xdom.Div(), xjs.AppendChildren(xdom.Fieldset(),
xjs.SetInnerText(xdom.Legend(), "Please select the "+typeName+" file"),
xform.Label("File", "files"),
示例2: generate
func generate(r *byteio.StickyReader, w *byteio.StickyWriter, of *os.File) error {
memoryLimit := r.ReadUint64()
size := r.ReadInt64()
gPath := data.ReadString(r)
levelName := data.ReadString(r)
mapPath := data.ReadString(r)
if r.Err != nil {
return r.Err
}
o, err := ora.Open(of, size)
if err != nil {
return err
}
f, err := os.Open(path.Join(gPath, "data.gen"))
if err != nil {
return err
}
g, err := LoadGenerator(f)
if e := f.Close(); e != nil {
return e
}
if err != nil {
return err
}
b := o.Bounds()
w.WriteUint8(2)
w.WriteInt32(int32(b.Max.X) >> 4)
w.WriteInt32(int32(b.Max.Y) >> 4)
c := make(chan paint, 1024)
m := make(chan string, 4)
e := make(chan struct{}, 0)
go func() {
defer close(e)
defer close(m)
defer close(c)
for {
select {
case message := <-m:
w.WriteUint8(3)
data.WriteString(w, message)
case p := <-c:
w.WriteUint8(4)
w.WriteInt32(p.X)
w.WriteInt32(p.Y)
r, g, b, a := p.RGBA()
w.WriteUint8(uint8(r >> 8))
w.WriteUint8(uint8(g >> 8))
w.WriteUint8(uint8(b >> 8))
w.WriteUint8(uint8(a >> 8))
case <-e:
return
}
}
}()
err = g.Generate(levelName, mapPath, o, c, m, memoryLimit)
e <- struct{}{}
<-e
return err
}
示例3: serverConsole
func serverConsole(s data.Server) func(dom.Element) {
return func(c dom.Element) {
log := xform.TextArea("log", "")
log.ReadOnly = true
command := xform.InputText("command", "")
command.Required = true
send := xform.InputSubmit("Send")
c.AppendChild(xjs.AppendChildren(xdom.Form(), xjs.AppendChildren(xdom.Fieldset(),
xjs.SetInnerText(xdom.Legend(), "Console"),
xform.Label("Log", ""), log, xdom.Br(),
xform.Label("Command", "command"), command, send,
)))
if s.State == data.StateStopped {
send.Disabled = true
command.Disabled = true
} else {
send.AddEventListener("click", false, func(e dom.Event) {
if command.Value == "" {
return
}
e.PreventDefault()
send.Disabled = true
cmd := command.Value
log.Value += "\n>" + cmd + "\n"
log.Set("scrollTop", log.Get("scrollHeight"))
command.Value = ""
go func() {
err := RPC.WriteCommand(s.ID, cmd)
if err != nil {
xjs.Alert("Error sending command: %s", err)
return
}
send.Disabled = false
}()
})
}
go func() {
conn, err := websocket.Dial("ws://" + js.Global.Get("location").Get("host").String() + "/console")
if err != nil {
xjs.Alert("Failed to connect to console: %s", err)
return
}
defer conn.Close()
w := byteio.StickyWriter{Writer: byteio.LittleEndianWriter{Writer: conn}}
r := byteio.StickyReader{Reader: byteio.LittleEndianReader{Reader: conn}}
updateStop := make(chan struct{})
registerUpdateStopper(c, updateStop)
done := false
go func() {
<-updateStop
done = true
conn.Close()
}()
w.WriteInt32(int32(s.ID))
for {
state := r.ReadUint8()
switch state {
case 0:
if !done {
err := ReadError(&r)
if r.Err != nil {
err = r.Err
}
log.Value += "\n\nError reading from console: " + err.Error()
log.Set("scrollTop", log.Get("scrollHeight"))
}
return
case 1:
log.Value += data.ReadString(&r)
log.Set("scrollTop", log.Get("scrollHeight"))
}
}
}()
}
}