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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 func (e *Encoder) StartArray(length, elementBitSize uint32) { | 144 func (e *Encoder) StartArray(length, elementBitSize uint32) { |
145 dataSize := dataHeaderSize + bytesForBits(uint64(length)*uint64(elementB
itSize)) | 145 dataSize := dataHeaderSize + bytesForBits(uint64(length)*uint64(elementB
itSize)) |
146 header := DataHeader{uint32(dataSize), length} | 146 header := DataHeader{uint32(dataSize), length} |
147 e.pushState(header, elementBitSize) | 147 e.pushState(header, elementBitSize) |
148 } | 148 } |
149 | 149 |
150 // StartMap starts encoding a map and writes its data header. | 150 // StartMap starts encoding a map and writes its data header. |
151 // Note: it doesn't write a pointer to the encoded map. | 151 // Note: it doesn't write a pointer to the encoded map. |
152 // Call |Finish()| after writing keys array and values array. | 152 // Call |Finish()| after writing keys array and values array. |
153 func (e *Encoder) StartMap() { | 153 func (e *Encoder) StartMap() { |
154 » e.pushState(mapHeader, pointerBitSize) | 154 » e.pushState(mapHeader, 0) |
155 } | 155 } |
156 | 156 |
157 // StartStruct starts encoding a struct and writes its data header. | 157 // StartStruct starts encoding a struct and writes its data header. |
158 // Note: it doesn't write a pointer to the encoded struct. | 158 // Note: it doesn't write a pointer to the encoded struct. |
159 // Call |Finish()| after writing all fields. | 159 // Call |Finish()| after writing all fields. |
160 func (e *Encoder) StartStruct(size, version uint32) { | 160 func (e *Encoder) StartStruct(size, version uint32) { |
161 dataSize := dataHeaderSize + int(size) | 161 dataSize := dataHeaderSize + int(size) |
162 header := DataHeader{uint32(dataSize), version} | 162 header := DataHeader{uint32(dataSize), version} |
163 e.pushState(header, 0) | 163 e.pushState(header, 0) |
164 } | 164 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 336 |
337 // WriteInterface writes an interface and invalidates the passed handle object. | 337 // WriteInterface writes an interface and invalidates the passed handle object. |
338 func (e *Encoder) WriteInterface(handle system.Handle) error { | 338 func (e *Encoder) WriteInterface(handle system.Handle) error { |
339 if err := e.WriteHandle(handle); err != nil { | 339 if err := e.WriteHandle(handle); err != nil { |
340 return err | 340 return err |
341 } | 341 } |
342 e.state().elementsProcessed-- | 342 e.state().elementsProcessed-- |
343 // Set the version field to 0 for now. | 343 // Set the version field to 0 for now. |
344 return e.WriteUint32(0) | 344 return e.WriteUint32(0) |
345 } | 345 } |
OLD | NEW |