When writing, don't pad the length of bytes produced from inner

structs/unions. Each type should take care of its own padding.

Close #14.
This commit is contained in:
Andrew Gallant 2013-12-28 09:33:09 -05:00 committed by Přemysl Janouch
parent f0385db3a7
commit 2dc9914b5e
Signed by: p
GPG Key ID: A0420B94F92B9493
10 changed files with 57 additions and 57 deletions

View File

@ -162,13 +162,13 @@ func (v NotifyEvent) Bytes() []byte {
{ {
structBytes := v.Area.Bytes() structBytes := v.Area.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.Geometry.Bytes() structBytes := v.Geometry.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
return buf return buf

View File

@ -504,15 +504,6 @@ func ModeInfoListBytes(buf []byte, list []ModeInfo) int {
return xgb.Pad(b) return xgb.Pad(b)
} }
const (
NotifyCrtcChange = 0
NotifyOutputChange = 1
NotifyOutputProperty = 2
NotifyProviderChange = 3
NotifyProviderProperty = 4
NotifyResourceChange = 5
)
// Notify is the event number for a NotifyEvent. // Notify is the event number for a NotifyEvent.
const Notify = 1 const Notify = 1
@ -556,7 +547,7 @@ func (v NotifyEvent) Bytes() []byte {
{ {
unionBytes := v.U.Bytes() unionBytes := v.U.Bytes()
copy(buf[b:], unionBytes) copy(buf[b:], unionBytes)
b += xgb.Pad(len(unionBytes)) b += len(unionBytes)
} }
return buf return buf
@ -581,6 +572,15 @@ func init() {
xgb.NewExtEventFuncs["RANDR"][1] = NotifyEventNew xgb.NewExtEventFuncs["RANDR"][1] = NotifyEventNew
} }
const (
NotifyCrtcChange = 0
NotifyOutputChange = 1
NotifyOutputProperty = 2
NotifyProviderChange = 3
NotifyProviderProperty = 4
NotifyResourceChange = 5
)
// NotifyDataUnion is a represention of the NotifyDataUnion union type. // NotifyDataUnion is a represention of the NotifyDataUnion union type.
// Note that to *create* a Union, you should *never* create // Note that to *create* a Union, you should *never* create
// this struct directly (unless you know what you're doing). // this struct directly (unless you know what you're doing).
@ -608,7 +608,7 @@ func NotifyDataUnionCcNew(Cc CrtcChange) NotifyDataUnion {
{ {
structBytes := Cc.Bytes() structBytes := Cc.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
// Create the Union type // Create the Union type
@ -651,7 +651,7 @@ func NotifyDataUnionOcNew(Oc OutputChange) NotifyDataUnion {
{ {
structBytes := Oc.Bytes() structBytes := Oc.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
// Create the Union type // Create the Union type
@ -694,7 +694,7 @@ func NotifyDataUnionOpNew(Op OutputProperty) NotifyDataUnion {
{ {
structBytes := Op.Bytes() structBytes := Op.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
// Create the Union type // Create the Union type
@ -737,7 +737,7 @@ func NotifyDataUnionPcNew(Pc ProviderChange) NotifyDataUnion {
{ {
structBytes := Pc.Bytes() structBytes := Pc.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
// Create the Union type // Create the Union type
@ -780,7 +780,7 @@ func NotifyDataUnionPpNew(Pp ProviderProperty) NotifyDataUnion {
{ {
structBytes := Pp.Bytes() structBytes := Pp.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
// Create the Union type // Create the Union type
@ -823,7 +823,7 @@ func NotifyDataUnionRcNew(Rc ResourceChange) NotifyDataUnion {
{ {
structBytes := Rc.Bytes() structBytes := Rc.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
// Create the Union type // Create the Union type
@ -909,7 +909,7 @@ func (v NotifyDataUnion) Bytes() []byte {
{ {
structBytes := v.Cc.Bytes() structBytes := v.Cc.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
return buf return buf
} }
@ -2133,7 +2133,7 @@ func createModeRequest(c *xgb.Conn, Window xproto.Window, ModeInfo ModeInfo, Nam
{ {
structBytes := ModeInfo.Bytes() structBytes := ModeInfo.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
copy(buf[b:], Name[:len(Name)]) copy(buf[b:], Name[:len(Name)])
@ -5139,7 +5139,7 @@ func setCrtcTransformRequest(c *xgb.Conn, Crtc Crtc, Transform render.Transform,
{ {
structBytes := Transform.Bytes() structBytes := Transform.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put16(buf[b:], FilterLen) xgb.Put16(buf[b:], FilterLen)

View File

@ -213,13 +213,13 @@ func (v ExtRange) Bytes() []byte {
{ {
structBytes := v.Major.Bytes() structBytes := v.Major.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.Minor.Bytes() structBytes := v.Minor.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
return buf return buf
@ -315,43 +315,43 @@ func (v Range) Bytes() []byte {
{ {
structBytes := v.CoreRequests.Bytes() structBytes := v.CoreRequests.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.CoreReplies.Bytes() structBytes := v.CoreReplies.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.ExtRequests.Bytes() structBytes := v.ExtRequests.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.ExtReplies.Bytes() structBytes := v.ExtReplies.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.DeliveredEvents.Bytes() structBytes := v.DeliveredEvents.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.DeviceEvents.Bytes() structBytes := v.DeviceEvents.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.Errors.Bytes() structBytes := v.Errors.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
if v.ClientStarted { if v.ClientStarted {

View File

@ -570,13 +570,13 @@ func (v Linefix) Bytes() []byte {
{ {
structBytes := v.P1.Bytes() structBytes := v.P1.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.P2.Bytes() structBytes := v.P2.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
return buf return buf
@ -898,7 +898,7 @@ func (v Pictforminfo) Bytes() []byte {
{ {
structBytes := v.Direct.Bytes() structBytes := v.Direct.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put32(buf[b:], uint32(v.Colormap)) xgb.Put32(buf[b:], uint32(v.Colormap))
@ -1382,13 +1382,13 @@ func (v Trap) Bytes() []byte {
{ {
structBytes := v.Top.Bytes() structBytes := v.Top.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.Bot.Bytes() structBytes := v.Bot.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
return buf return buf
@ -1456,13 +1456,13 @@ func (v Trapezoid) Bytes() []byte {
{ {
structBytes := v.Left.Bytes() structBytes := v.Left.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.Right.Bytes() structBytes := v.Right.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
return buf return buf
@ -1520,19 +1520,19 @@ func (v Triangle) Bytes() []byte {
{ {
structBytes := v.P1.Bytes() structBytes := v.P1.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.P2.Bytes() structBytes := v.P2.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := v.P3.Bytes() structBytes := v.P3.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
return buf return buf
@ -2205,7 +2205,7 @@ func createConicalGradientRequest(c *xgb.Conn, Picture Picture, Center Pointfix,
{ {
structBytes := Center.Bytes() structBytes := Center.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put32(buf[b:], uint32(Angle)) xgb.Put32(buf[b:], uint32(Angle))
@ -2402,13 +2402,13 @@ func createLinearGradientRequest(c *xgb.Conn, Picture Picture, P1 Pointfix, P2 P
{ {
structBytes := P1.Bytes() structBytes := P1.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := P2.Bytes() structBytes := P2.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put32(buf[b:], NumStops) xgb.Put32(buf[b:], NumStops)
@ -2549,13 +2549,13 @@ func createRadialGradientRequest(c *xgb.Conn, Picture Picture, Inner Pointfix, O
{ {
structBytes := Inner.Bytes() structBytes := Inner.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
{ {
structBytes := Outer.Bytes() structBytes := Outer.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put32(buf[b:], uint32(InnerRadius)) xgb.Put32(buf[b:], uint32(InnerRadius))
@ -2633,7 +2633,7 @@ func createSolidFillRequest(c *xgb.Conn, Picture Picture, Color Color) []byte {
{ {
structBytes := Color.Bytes() structBytes := Color.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
return buf return buf
@ -2699,7 +2699,7 @@ func fillRectanglesRequest(c *xgb.Conn, Op byte, Dst Picture, Color Color, Rects
{ {
structBytes := Color.Bytes() structBytes := Color.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
b += xproto.RectangleListBytes(buf[b:], Rects) b += xproto.RectangleListBytes(buf[b:], Rects)
@ -3543,7 +3543,7 @@ func setPictureTransformRequest(c *xgb.Conn, Picture Picture, Transform Transfor
{ {
structBytes := Transform.Bytes() structBytes := Transform.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
return buf return buf

View File

@ -194,7 +194,7 @@ func (v ClientIdValue) Bytes() []byte {
{ {
structBytes := v.Spec.Bytes() structBytes := v.Spec.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put32(buf[b:], v.Length) xgb.Put32(buf[b:], v.Length)
@ -328,7 +328,7 @@ func (v ResourceSizeSpec) Bytes() []byte {
{ {
structBytes := v.Spec.Bytes() structBytes := v.Spec.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put32(buf[b:], v.Bytes) xgb.Put32(buf[b:], v.Bytes)
@ -395,7 +395,7 @@ func (v ResourceSizeValue) Bytes() []byte {
{ {
structBytes := v.Size.Bytes() structBytes := v.Size.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put32(buf[b:], v.NumCrossReferences) xgb.Put32(buf[b:], v.NumCrossReferences)

View File

@ -467,7 +467,7 @@ func sendRequest(c *xgb.Conn, Event Event, DataType uint32) []byte {
{ {
structBytes := Event.Bytes() structBytes := Event.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put32(buf[b:], DataType) xgb.Put32(buf[b:], DataType)

View File

@ -1801,7 +1801,7 @@ func invertRegionRequest(c *xgb.Conn, Source Region, Bounds xproto.Rectangle, De
{ {
structBytes := Bounds.Bytes() structBytes := Bounds.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
xgb.Put32(buf[b:], uint32(Destination)) xgb.Put32(buf[b:], uint32(Destination))

View File

@ -152,13 +152,13 @@ func (f *SingleField) Write(c *Context, prefix string) {
c.Putln("{") c.Putln("{")
c.Putln("unionBytes := %s%s.Bytes()", prefix, f.SrcName()) c.Putln("unionBytes := %s%s.Bytes()", prefix, f.SrcName())
c.Putln("copy(buf[b:], unionBytes)") c.Putln("copy(buf[b:], unionBytes)")
c.Putln("b += xgb.Pad(len(unionBytes))") c.Putln("b += len(unionBytes)")
c.Putln("}") c.Putln("}")
case *Struct: case *Struct:
c.Putln("{") c.Putln("{")
c.Putln("structBytes := %s%s.Bytes()", prefix, f.SrcName()) c.Putln("structBytes := %s%s.Bytes()", prefix, f.SrcName())
c.Putln("copy(buf[b:], structBytes)") c.Putln("copy(buf[b:], structBytes)")
c.Putln("b += xgb.Pad(len(structBytes))") c.Putln("b += len(structBytes)")
c.Putln("}") c.Putln("}")
default: default:
log.Fatalf("Cannot read field '%s' with %T type.", f.XmlName(), f.Type) log.Fatalf("Cannot read field '%s' with %T type.", f.XmlName(), f.Type)

View File

@ -886,7 +886,7 @@ func (v ClientMessageEvent) Bytes() []byte {
{ {
unionBytes := v.Data.Bytes() unionBytes := v.Data.Bytes()
copy(buf[b:], unionBytes) copy(buf[b:], unionBytes)
b += xgb.Pad(len(unionBytes)) b += len(unionBytes)
} }
return buf return buf

View File

@ -458,7 +458,7 @@ func (v EncodingInfo) Bytes() []byte {
{ {
structBytes := v.Rate.Bytes() structBytes := v.Rate.Bytes()
copy(buf[b:], structBytes) copy(buf[b:], structBytes)
b += xgb.Pad(len(structBytes)) b += len(structBytes)
} }
copy(buf[b:], v.Name[:v.NameSize]) copy(buf[b:], v.Name[:v.NameSize])