| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package bindings | 5 package bindings |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/binary" | 8 "encoding/binary" |
| 9 "fmt" | 9 "fmt" |
| 10 "math" | 10 "math" |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 for _, b := range bytes { | 298 for _, b := range bytes { |
| 299 if err := e.WriteUint8(b); err != nil { | 299 if err := e.WriteUint8(b); err != nil { |
| 300 return err | 300 return err |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 return e.Finish() | 303 return e.Finish() |
| 304 } | 304 } |
| 305 | 305 |
| 306 // WritePointer writes a pointer to first unclaimed byte index. | 306 // WritePointer writes a pointer to first unclaimed byte index. |
| 307 func (e *Encoder) WritePointer() error { | 307 func (e *Encoder) WritePointer() error { |
| 308 e.state().alignOffsetToBytes() |
| 309 e.state().offset = align(e.state().offset, 8) |
| 308 return e.WriteUint64(uint64(e.end - e.state().offset)) | 310 return e.WriteUint64(uint64(e.end - e.state().offset)) |
| 309 } | 311 } |
| 310 | 312 |
| 311 // WriteInvalidHandle an invalid handle. | 313 // WriteInvalidHandle an invalid handle. |
| 312 func (e *Encoder) WriteInvalidHandle() error { | 314 func (e *Encoder) WriteInvalidHandle() error { |
| 313 return e.WriteInt32(-1) | 315 return e.WriteInt32(-1) |
| 314 } | 316 } |
| 315 | 317 |
| 316 // WriteHandle writes a handle and invalidates the passed handle object. | 318 // WriteHandle writes a handle and invalidates the passed handle object. |
| 317 func (e *Encoder) WriteHandle(handle system.Handle) error { | 319 func (e *Encoder) WriteHandle(handle system.Handle) error { |
| 318 if !handle.IsValid() { | 320 if !handle.IsValid() { |
| 319 return fmt.Errorf("can't write an invalid handle") | 321 return fmt.Errorf("can't write an invalid handle") |
| 320 } | 322 } |
| 321 UntypedHandle := handle.ToUntypedHandle() | 323 UntypedHandle := handle.ToUntypedHandle() |
| 322 e.handles = append(e.handles, UntypedHandle) | 324 e.handles = append(e.handles, UntypedHandle) |
| 323 return e.WriteUint32(uint32(len(e.handles) - 1)) | 325 return e.WriteUint32(uint32(len(e.handles) - 1)) |
| 324 } | 326 } |
| OLD | NEW |