summaryrefslogtreecommitdiff
path: root/src/encoding
Commit message (Collapse)AuthorAgeFilesLines
* encoding/json: Fixed the comment specifying Marshal behavior for maps.Aaron Jacobs2015-02-181-2/+2
| | | | | | | | | | | The comment previously was reversed in sense (it appeared to be describing unmarshaling). I've fixed that, and added the caveat that map keys are subject to UTF-8 coercion like other strings. Change-Id: Id08082aa71401a6e7530a42f979fbb50bd1f4e6a Reviewed-on: https://go-review.googlesource.com/5221 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
* encoding/xml: encoding name spaces correctlyRoger Peppe2015-02-134-87/+344
| | | | | | | | | | | | | The current XML printer does not understand the xmlns attribute. This change changes it so that it interprets the xmlns attributes in the tokens being printed, and uses appropriate prefixes. Fixes #7535. Change-Id: I20fae291d20602d37deb41ed42fab4c9a50ec85d Reviewed-on: https://go-review.googlesource.com/2660 Reviewed-by: Nigel Tao <nigeltao@golang.org>
* encoding/xml: add more EncodeToken tests.Nigel Tao2015-02-091-25/+347
| | | | | | | | | | There are no behavior changes in this CL, only specifying the status quo. A follow-up CL, https://go-review.googlesource.com/#/c/2660/, will change the EncodeToken behavior. Change-Id: I6ecbcfb05ae681de71fa1099d054df2826ed4acb Reviewed-on: https://go-review.googlesource.com/4167 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/xml: avoid an allocation for tags without attributesBrian Smith2015-02-071-2/+6
| | | | | | | | | | | | | Before, an array of size 4 would always be allocated even if a tag doesn't have any attributes. Now that array is allocated only if needed. benchmark old allocs new allocs delta BenchmarkUnmarshal 191 176 -8.5% Change-Id: I4d214b228883d0a6e892c0d6eb00dfe2da84c116 Reviewed-on: https://go-review.googlesource.com/4160 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: don't refer to code.google.com/p/go{,-wiki}/Péter Surányi2015-02-061-1/+1
| | | | | | | | | | Only documentation / comment changes. Update references to point to golang.org permalinks or go.googlesource.com/go. References in historical release notes under doc are left as is. Change-Id: Icfc14e4998723e2c2d48f9877a91c5abef6794ea Reviewed-on: https://go-review.googlesource.com/4060 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* encoding/json: add UnmarshalTypeError.OffsetAlex Plugaru2015-01-292-21/+22
| | | | | | | | | Fixes #9693 Change-Id: Ibf07199729bfc883b2a7e051cafd98185f912acd Reviewed-on: https://go-review.googlesource.com/3283 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/xml: remove unnecessary memory allocation in UnmarshalDmitry Vyukov2015-01-152-4/+6
| | | | | | | | | | | | benchmark old ns/op new ns/op delta BenchmarkUnmarshal 75256 72626 -3.49% benchmark old allocs new allocs delta BenchmarkUnmarshal 259 219 -15.44% Change-Id: I7fd30739b045e35b95e6ef6a8ef2f15b0dd6839c Reviewed-on: https://go-review.googlesource.com/2758 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/gob: address go vet reportEmil Hessman2014-12-281-1/+1
| | | | | | | | Use Fatalf for formatting directive rather than plain Fatal. Change-Id: Iebd30cd6326890e9501746113a6d97480949e3d2 Reviewed-on: https://go-review.googlesource.com/2161 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/json: address go vet reportsEmil Hessman2014-12-282-2/+3
| | | | | | | | | | | | | | | | | | The error message for decoding a unquoted value into a struct field with the ,string option specified has two arguments when one is needed. Make the error message take one argument and add a test in order to cover the case when a unquoted value is specified. Also add error value as the missing argument for Fatalf call in test. Fixes the following go vet reports: decode.go:602: wrong number of args for format in Errorf call: 1 needed but 2 args decode_test.go:1088: missing argument for Fatalf("%v"): format reads arg 1, have only 0 args Change-Id: Id036e10c54c4a7c1ee9952f6910858ecc2b84134 Reviewed-on: https://go-review.googlesource.com/2109 Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
* encoding/binary: check for unsigned integers in intDataSize.Stan Schwertly2014-12-221-4/+4
| | | | | | | | | | intDataSize ignores unsigned integers, forcing reads/writes to miss the fast path. Fixes #8956 Change-Id: Ie79b565b037db3c469aa1dc6d0a8a5a9252d5f0a Reviewed-on: https://go-review.googlesource.com/1777 Reviewed-by: Russ Cox <rsc@golang.org>
* encoding/base64: add unpadded encodings, and test all encodings.Bryan Ford2014-12-222-41/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some applications use unpadded base64 format, omitting the trailing '=' padding characters from the standard base64 format, either to minimize size or (more justifiably) to avoid use of the '=' character. Unpadded flavors are standard and documented in section 3.2 of RFC 4648. To support these unpadded flavors, this change adds two predefined encoding variables, RawStdEncoding and RawURLEncoding, for unpadded encodings using the standard and URL character set, respectively. The change also adds a function WithPadding() to customize the padding character or disable padding in a custom Encoding. Finally, I noticed that the existing base64 test-suite was only exercising the StdEncoding, and not referencing URLEncoding at all. This change adds test-suite functionality to exercise all four encodings (the two existing ones and the two new unpadded flavors), although it still doesn't run *every* test on all four encodings. Naming: I used the "Raw" prefix because it's more concise than "Unpadded" and seemed just as expressive, but I have no strong preferences here. Another short alternative prefix would be "Min" ("minimal" encoding). Change-Id: Ic0423e02589b39a6b2bb7d0763bd073fd244f469 Reviewed-on: https://go-review.googlesource.com/1511 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/pem: eliminate allocations for newlines during encodingBen Burkert2014-12-212-3/+24
| | | | | | | | | | | | benchmark old MB/s new MB/s speedup BenchmarkEncode 243.20 279.89 1.15x benchmark old allocs new allocs delta BenchmarkEncode 1370 4 -99.71% Change-Id: I3920bcc04b6dd89efa5da89db5594d4434426d74 Reviewed-on: https://go-review.googlesource.com/1924 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/json: mention that the "string" tag applies to booleansAndrew Gerrand2014-12-141-2/+2
| | | | | | | | Fixes #9284 Change-Id: I0410a9ed82b861686a0a986c9ca4eeeacac8f296 Reviewed-on: https://go-review.googlesource.com/1534 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/xml: remove SyntaxError.ByteRuss Cox2014-12-051-1/+0
| | | | | | | | | | It is unused. It was introduced in the CL that added InputOffset. I suspect it was an editing mistake. LGTM=bradfitz R=bradfitz CC=golang-codereviews https://golang.org/cl/182580043
* encoding/json: encode \t as \t instead of \u0009Russ Cox2014-10-272-1/+59
| | | | | | | | | Shorter and easier to read form for a common character. LGTM=bradfitz R=adg, bradfitz CC=golang-codereviews, zimmski https://golang.org/cl/162340043
* encoding/csv: for Postgres, unquote empty strings, quote \.Russ Cox2014-10-232-2/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In theory both of these lines encode the same three fields: a,,c a,"",c However, Postgres defines that when importing CSV, the unquoted version is treated as NULL (missing), while the quoted version is treated as a string value (empty string). If the middle field is supposed to be an integer value, the first line can be imported (NULL is okay), but the second line cannot (empty string is not). Postgres's import command (COPY FROM) has an option to force the unquoted empty to be interpreted as a string but it does not have an option to force the quoted empty to be interpreted as a NULL. From http://www.postgresql.org/docs/9.0/static/sql-copy.html: The CSV format has no standard way to distinguish a NULL value from an empty string. PostgreSQL's COPY handles this by quoting. A NULL is output as the NULL parameter string and is not quoted, while a non-NULL value matching the NULL parameter string is quoted. For example, with the default settings, a NULL is written as an unquoted empty string, while an empty string data value is written with double quotes (""). Reading values follows similar rules. You can use FORCE_NOT_NULL to prevent NULL input comparisons for specific columns. Therefore printing the unquoted empty is more flexible for imports into Postgres than printing the quoted empty. In addition to making the output more useful with Postgres, not quoting empty strings makes the output smaller and easier to read. It also matches the behavior of Microsoft Excel and Google Drive. Since we are here and making concessions for Postgres, handle this case too (again quoting the Postgres docs): Because backslash is not a special character in the CSV format, \., the end-of-data marker, could also appear as a data value. To avoid any misinterpretation, a \. data value appearing as a lone entry on a line is automatically quoted on output, and on input, if quoted, is not interpreted as the end-of-data marker. If you are loading a file created by another application that has a single unquoted column and might have a value of \., you might need to quote that value in the input file. Fixes #7586. LGTM=bradfitz R=bradfitz CC=golang-codereviews https://golang.org/cl/164760043
* encoding/gob: add custom decoder buffer for performanceRob Pike2014-10-203-39/+78
| | | | | | | | | | | | | | | | | | | | | | | | | As we did with encoding, provide a trivial byte reader for faster decoding. We can also reduce some of the copying by doing the allocation all at once using a slightly different interface from byte buffers. benchmark old ns/op new ns/op delta BenchmarkEndToEndPipe 13368 12902 -3.49% BenchmarkEndToEndByteBuffer 5969 5642 -5.48% BenchmarkEndToEndSliceByteBuffer 479485 470798 -1.81% BenchmarkEncodeComplex128Slice 92367 92201 -0.18% BenchmarkEncodeFloat64Slice 39990 38960 -2.58% BenchmarkEncodeInt32Slice 30510 27938 -8.43% BenchmarkEncodeStringSlice 33753 33365 -1.15% BenchmarkDecodeComplex128Slice 232278 196704 -15.32% BenchmarkDecodeFloat64Slice 150258 128191 -14.69% BenchmarkDecodeInt32Slice 133806 115748 -13.50% BenchmarkDecodeStringSlice 335117 300534 -10.32% LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/154360049
* encoding/gob: fix print format in generated decoder helpersRob Pike2014-10-192-17/+17
| | | | | | | | | Needed a %% to quote a percent in the format. LGTM=adg R=golang-codereviews, adg CC=golang-codereviews https://golang.org/cl/156330043
* encoding/gob: use simple append-only buffer for encodingRob Pike2014-10-174-35/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | Bytes buffers have more API and are a little slower. Since appending is a key part of the path in encode, using a faster implementation speeds things up measurably. The couple of positive swings are likely garbage-collection related since memory allocation looks different in the benchmark now. I am not concerned by them. benchmark old ns/op new ns/op delta BenchmarkEndToEndPipe 6620 6388 -3.50% BenchmarkEndToEndByteBuffer 3548 3600 +1.47% BenchmarkEndToEndSliceByteBuffer 336678 367980 +9.30% BenchmarkEncodeComplex128Slice 78199 71297 -8.83% BenchmarkEncodeFloat64Slice 37731 32258 -14.51% BenchmarkEncodeInt32Slice 26780 22977 -14.20% BenchmarkEncodeStringSlice 35882 26492 -26.17% BenchmarkDecodeComplex128Slice 194819 185126 -4.98% BenchmarkDecodeFloat64Slice 120538 120102 -0.36% BenchmarkDecodeInt32Slice 106442 107275 +0.78% BenchmarkDecodeStringSlice 272902 269866 -1.11% LGTM=ruiu R=golang-codereviews, ruiu CC=golang-codereviews https://golang.org/cl/160990043
* encoding/gob: custom array/slice decodersRob Pike2014-10-177-29/+874
| | | | | | | | | | | | | | | | | Use go generate to write better loops for decoding arrays, just as we did for encoding. It doesn't help as much, relatively speaking, but it's still noticeable. benchmark old ns/op new ns/op delta BenchmarkDecodeComplex128Slice 202348 184529 -8.81% BenchmarkDecodeFloat64Slice 135800 120979 -10.91% BenchmarkDecodeInt32Slice 121200 105149 -13.24% BenchmarkDecodeStringSlice 288129 278214 -3.44% LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/154420044
* encoding/gob: speed up encoding of arrays and slicesRob Pike2014-10-174-3/+708
| | | | | | | | | | | | | | | | | | | | | | | | We borrow a trick from the fmt package and avoid reflection to walk the elements when possible. We could push further with unsafe (and we may) but this is a good start. Decode can benefit similarly; it will be done separately. Use go generate (engen.go) to produce the helper functions (enc_helpers.go). benchmark old ns/op new ns/op delta BenchmarkEndToEndPipe 6593 6482 -1.68% BenchmarkEndToEndByteBuffer 3662 3684 +0.60% BenchmarkEndToEndSliceByteBuffer 350306 351693 +0.40% BenchmarkComplex128Slice 96347 80045 -16.92% BenchmarkInt32Slice 42484 26008 -38.78% BenchmarkFloat64Slice 51143 36265 -29.09% BenchmarkStringSlice 53402 35077 -34.32% LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/156310043
* encoding/gob: make encoding structs a little fasterRob Pike2014-10-141-4/+6
| | | | | | | | | | | | | FieldByIndex never returns an invalid Value, so the validity test can be avoided if the field is not indirect. BenchmarkGobEncode 12768642 12424022 -2.70% BenchmarkGobEncode 60.11 61.78 1.03x LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/158890045
* encoding/asn1: fix explicitly tagged Times.Adam Langley2014-10-092-2/+50
| | | | | | | | | | | | | | | | | | https://golang.org/cl/153770043/ tried to fix the case where a implicitly tagged Time, that happened to have the same tag as GENERALIZEDTIME, shouldn't be parsed as a GENERALIZEDTIME. It did so, mistakenly, by testing whether params.tag != nil. But explicitly tagged values also have a non-nil tag and there the inner tag actually does encode the type of the value. This change instead tests whether the tag class is UNIVERSAL before assuming that the tag contains type information. LGTM=iant R=iant CC=golang-codereviews https://golang.org/cl/152380044
* encoding/json: fix handling of null with ,string fieldsRuss Cox2014-10-072-11/+50
| | | | | | | | | Fixes #8587. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews, iant, r https://golang.org/cl/152270044
* encoding/json: document that embedded interfaces look like non-embedded onesRuss Cox2014-10-061-0/+2
| | | | | | | | | Fixes #8386. LGTM=r R=golang-codereviews, r CC=golang-codereviews, iant https://golang.org/cl/149570043
* encoding/binary: fix error messageRobert Griesemer2014-10-022-40/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the process, simplified internal sizeOf and dataSize functions. Minor positive impact on performance. Added test case. benchmark old ns/op new ns/op delta BenchmarkReadSlice1000Int32s 14006 14122 +0.83% BenchmarkReadStruct 2508 2447 -2.43% BenchmarkReadInts 921 928 +0.76% BenchmarkWriteInts 2086 2081 -0.24% BenchmarkWriteSlice1000Int32s 13440 13497 +0.42% BenchmarkPutUvarint32 28.5 26.3 -7.72% BenchmarkPutUvarint64 81.3 76.7 -5.66% benchmark old MB/s new MB/s speedup BenchmarkReadSlice1000Int32s 285.58 283.24 0.99x BenchmarkReadStruct 27.90 28.60 1.03x BenchmarkReadInts 32.57 32.31 0.99x BenchmarkWriteInts 14.38 14.41 1.00x BenchmarkWriteSlice1000Int32s 297.60 296.36 1.00x BenchmarkPutUvarint32 140.55 151.92 1.08x BenchmarkPutUvarint64 98.36 104.33 1.06x Fixes #6818. LGTM=r R=r CC=golang-codereviews https://golang.org/cl/149290045
* encoding/json: don't panic on incorrect map argumentRobert Griesemer2014-10-012-3/+15
| | | | | | | | | Fixes #8305. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/145680044
* encoding/binary: slightly better documentationRobert Griesemer2014-10-011-3/+4
| | | | | | | | | Fixes #7306. LGTM=r R=r CC=golang-codereviews https://golang.org/cl/153820044
* encoding/asn1: fix unmarshaling of implicitly tagged UTF-8 strings.Adam Langley2014-09-302-4/+13
| | | | | | | | | Fixes #8541. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/153770043
* encoding/gob: fix 386 buildRob Pike2014-09-251-9/+6
| | | | | | | LGTM=ruiu R=golang-codereviews, ruiu CC=golang-codereviews https://golang.org/cl/146320043
* encoding/gob: error rather than panic when decoding enormous slicesRob Pike2014-09-253-4/+39
| | | | | | | | | Fixes #8084. LGTM=ruiu R=golang-codereviews, ruiu CC=golang-codereviews https://golang.org/cl/142710043
* encoding/gob: speedup encodingDmitriy Vyukov2014-09-183-66/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace typeLock with copy-on-write map using atomic.Value. benchmark old ns/op new ns/op delta BenchmarkEndToEndPipe 7722 7709 -0.17% BenchmarkEndToEndPipe-2 5114 4344 -15.06% BenchmarkEndToEndPipe-4 3192 2429 -23.90% BenchmarkEndToEndPipe-8 1833 1438 -21.55% BenchmarkEndToEndPipe-16 1332 983 -26.20% BenchmarkEndToEndPipe-32 1444 675 -53.25% BenchmarkEndToEndByteBuffer 6474 6019 -7.03% BenchmarkEndToEndByteBuffer-2 4280 2810 -34.35% BenchmarkEndToEndByteBuffer-4 2264 1774 -21.64% BenchmarkEndToEndByteBuffer-8 1275 979 -23.22% BenchmarkEndToEndByteBuffer-16 1257 753 -40.10% BenchmarkEndToEndByteBuffer-32 1342 644 -52.01% BenchmarkEndToEndArrayByteBuffer 727725 671349 -7.75% BenchmarkEndToEndArrayByteBuffer-2 394079 320473 -18.68% BenchmarkEndToEndArrayByteBuffer-4 211785 178175 -15.87% BenchmarkEndToEndArrayByteBuffer-8 141003 118857 -15.71% BenchmarkEndToEndArrayByteBuffer-16 139249 86367 -37.98% BenchmarkEndToEndArrayByteBuffer-32 144128 73454 -49.04% LGTM=r R=golang-codereviews, r CC=golang-codereviews https://golang.org/cl/147720043
* build: move package sources from src/pkg to srcRuss Cox2014-09-0870-0/+29427
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.