Re: [go-nuts] Re: encoding/json treats []byte as b64 encoded. Could it not?

2024-11-07 Thread Nikolay Dubina
I also stumbled upon this bug. I have base64 of some data in []bytes field in my struct. I do json.Marshal, then json.Unmarshal to the same struct type. And now, surprise! data automatically base64 decoded. what... any encoder in any system should have following guarantee (enforced with fuzz te

Re: [go-nuts] Re: encoding/json treats []byte as b64 encoded. Could it not?

2024-06-25 Thread 'Mauro Lacy' via golang-nuts
Related: https://stackoverflow.com/a/78662958/3768429 On Monday 16 December 2013 at 19:37:30 UTC+1 Kyle Lemons wrote: > On Sun, Dec 15, 2013 at 2:05 PM, Brian Picciano > wrote: > >> I'm going to compress my three responses to one. >> >> > What I'm less clear on is exactly what your use case is

[go-nuts] Re: encoding/xml: Marshal struct field depending on value of another struct field

2022-02-26 Thread Steffen Wentzel
I'm just using pointers now, this approach seems to work fine for my purpose: https://go.dev/play/p/lMwZisTayt3 Steffen Wentzel schrieb am Samstag, 26. Februar 2022 um 11:00:49 UTC+1: > Dear community, > > how can we XML marshal a struct field depending on the value of another > struct field in

[go-nuts] Re: encoding/json: add FlexObject for encoding/decoding between JSON and flex Go types.

2021-05-10 Thread Brian Candler
That is true, you need a separate wrapper object for decoding (the one with json.RawMessage). But the wrapped objects are the same. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it

[go-nuts] Re: encoding/json: add FlexObject for encoding/decoding between JSON and flex Go types.

2021-05-09 Thread Ally Dale
see the reffer issue both json.RawMessage and interface{} cannot solve this problem. ```Go // AnimalRaw can only used to delay decoding JSON type AnimalRaw struct { Kind string `json:"kind"` Attr json.RawMessage `json:"attr"` }

[go-nuts] Re: encoding/json: add FlexObject for encoding/decoding between JSON and flex Go types.

2021-05-09 Thread Brian Candler
On Sunday, 9 May 2021 at 13:30:59 UTC+1 Ally Dale wrote: > But the way of [generate a sample JSON]( > https://github.com/vipally/glab/blob/master/lab27/json_raw_test.go#L38) > in this case looks ugly: > > It doesn't have to be as ugly as that: https://play.golang.org/p/BUjUNtJP_rG -- You receiv

[go-nuts] Re: encoding/xml expose line

2021-04-19 Thread Patrick
Thank you Peter, I have opened an issue (https://github.com/golang/go/issues/45628). Patrick -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsub

[go-nuts] Re: encoding/xml expose line

2021-04-17 Thread peterGo
Patrick, A similar proposal has just been accepted for encoding/csv: encoding/csv: add the ability to get the line number of a record #44221 https://github.com/golang/go/issues/44221 Peter On Saturday, April 17, 2021 at 12:45:11 PM UTC-4 Patrick wrote: > I have my own programming language (a

[go-nuts] Re: encoding/xml expose line

2021-04-17 Thread Patrick
I have my own programming language (a bit similar to XSLT) and the XML can be valid but there still might be an error such as an uninitialised variable. I'd like to present feedback to the user on which line the error occurred. I am thinking about opening an issue on GitHub and providing a (sim

[go-nuts] Re: encoding/xml expose line

2021-04-17 Thread clba...@gmail.com
Don't know what you're trying to do, but the only time I've wanted the line number during decoding is when an error occurs. Then I retrieve it using xml.SyntaxError, assuming that 'error' is of type *xml.SyntaxError. On Friday, April 16, 2021 at 8:44:19 AM UTC-6 Patrick wrote: > Hello all, > >

[go-nuts] Re: encoding/csv: getting a line number of current record when using csv.Reader

2021-04-09 Thread Tamás Gulácsi
And if your CSV is not so simple, then extract the number of "\n"-s found in the fields from the line count gathered by counting "\n"-s. Or re-encode the csv into a "\n" counting io.Writer. nikolay nikolay a következőt írta (2021. április 9., péntek, 7:03:49 UTC+2): > If you CSV is simple, as i

[go-nuts] Re: encoding/csv: getting a line number of current record when using csv.Reader

2021-04-08 Thread nikolay nikolay
If you CSV is simple, as in does not have multi-line values in columns, \n in line ending — then you can create your own wrapper around io.Reader that counts number of \n before returning to caller []bytes. -- Nikolay On Friday, April 9, 2021 at 1:50:10 AM UTC+8 peterGo wrote: > Dan, > > For G

[go-nuts] Re: encoding/csv: getting a line number of current record when using csv.Reader

2021-04-08 Thread peterGo
Dan, For Go 1.17: encoding/csv: add the ability to get the line number of a record #44221 https://github.com/golang/go/issues/44221 Peter On Thursday, April 8, 2021 at 12:36:27 PM UTC-4 yodanj...@gmail.com wrote: > My need is similar to issue #26679 but not the same. > > I am using 1.15.8 > >

[go-nuts] Re: encoding/html package to generate html markup programmatically

2021-03-15 Thread atd...@gmail.com
Oh, you might be my savior ! :) I starred it and am going to look into it. Looks quite promising! On Monday, March 15, 2021 at 6:52:58 PM UTC+1 michael...@gmail.com wrote: > goht might be what you're > looking for. > > On Sunday, March 14, 2021 at 7:36:5

[go-nuts] Re: encoding/html package to generate html markup programmatically

2021-03-15 Thread Michael Ellis
goht might be what you're looking for. On Sunday, March 14, 2021 at 7:36:52 PM UTC-4 atd...@gmail.com wrote: > Hi, > > I am currently thinking about implementing SSR for a Go client-side > framework. > Not only that but I would like to be able to create

[go-nuts] Re: Encoding

2018-05-17 Thread Manlio Perillo
Il giorno giovedì 17 maggio 2018 04:57:48 UTC+2, Raulino Neto ha scritto: > > Hello Guys, I have to convert a Json to a UTF_16LE and byte array for sign > a rsa key, someone have idea that how I can do it? Thanks regards. > For encoding UTF-8 to UTF-16LE see: https://godoc.org/golang.org/x/text/e

[go-nuts] Re: encoding/json: unexpected behaviour when unmarshalling into struct with interface{} field

2017-05-02 Thread Frits van Bommel
On Tuesday, May 2, 2017 at 10:53:36 PM UTC+2, Brian Stengaard wrote: > > > On Tuesday, 2 May 2017 16:02:47 UTC-4, Pierre Curto wrote: >> >> Hello, >> >> My guess: >> If you dont pass in a pointer, then you pass a value. >> What would be the point of updating the value that you will never see and >

[go-nuts] Re: encoding/json: unexpected behaviour when unmarshalling into struct with interface{} field

2017-05-02 Thread Brian Stengaard
On Tuesday, 2 May 2017 16:02:47 UTC-4, Pierre Curto wrote: > > Hello, > > My guess: > If you dont pass in a pointer, then you pass a value. > What would be the point of updating the value that you will never see and > that will get discarded? > Hence it returns a map that provides the unmarshaled

[go-nuts] Re: encoding/json: unexpected behaviour when unmarshalling into struct with interface{} field

2017-05-02 Thread pierre . curto
Hello, My guess: If you dont pass in a pointer, then you pass a value. What would be the point of updating the value that you will never see and that will get discarded? Hence it returns a map that provides the unmarshaled values so at least you have something to work with. Le mardi 2 mai 2017

[go-nuts] Re: encoding an integral float like 1.0 as "1.0" in JSON (not "1"), and other JSON questions

2017-03-02 Thread Basile Starynkevitch
Thanks for all for the help. I managed to commit 4da8b9c7a7d7822ca1e45ce660 -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group a

[go-nuts] Re: encoding/gob decode []byte to multi struct types

2017-01-18 Thread caspian46
Thanks for you reply, I got it done: https://play.golang.org/p/oOEELLyaVv This is how I did it, pass *interface{} to gob.Encode, not interface{} the same with gob.Decode, then get the type info from the decoded value interface{} 在 2017年1月18日星期三 UTC+8下午10:51:51,Jordan Krage写道: > > Actually, it

[go-nuts] Re: encoding/gob decode []byte to multi struct types

2017-01-18 Thread Jordan Krage
Actually, it looks like the int/int8 distinction doesn't matter for gob. > There is no int8, int16 etc. discrimination in the gob format; there are > only signed and unsigned integers. > https://golang.org/pkg/encoding/gob/ On Wednesday, January 18, 2017 at 8:43:27 AM UTC-6, Jordan Krage wrote:

[go-nuts] Re: encoding/gob decode []byte to multi struct types

2017-01-18 Thread Jordan Krage
How about a compromise with denser type info? (could consider an int8 as well) type infoType int const ( firstType infoType = iota secondType ... ) type Info struct{ infoType IData interface{} } On Wednesday, January 18, 2017 at 12:07:49 AM UTC-6, casp...@gmail.com wrot

[go-nuts] Re: encoding/gob decode []byte to multi struct types

2017-01-17 Thread caspian46
First thanks for you reply. Because in fact, I have about more than 10 different struct types (maybe more and more), your suggest is good, this is better type Info struct{ typeStr string // store the type info to decode IData IData interface{} } But I don't like to send the typeInfo thro

[go-nuts] Re: encoding/gob decode []byte to multi struct types

2017-01-17 Thread Felipe Spinolo
Why not just create a wrapper struct? Something like: type Mixed struct{ A *A B *B } And then just encode/decode that? On Tuesday, January 17, 2017 at 1:16:37 PM UTC-8, casp...@gmail.com wrote: > > I got two struct types encoded into bytes by gob, I want to decode the > bytes into a spe

Re: [go-nuts] Re: encoding/json: any way to receive number literal "10.0" into integer field?

2016-06-18 Thread C Banning
Or: https://play.golang.org/p/VjFJGUI27W On Friday, June 17, 2016 at 4:33:20 PM UTC-6, Matt Harden wrote: > > https://play.golang.org/p/8R6QmYw_28 > > On Fri, Jun 17, 2016 at 3:08 PM Evan Digby > wrote: > >> To further this, if you do need your internal model to be a concrete >> struct rather th

Re: [go-nuts] Re: encoding/json: any way to receive number literal "10.0" into integer field?

2016-06-17 Thread Matt Harden
https://play.golang.org/p/8R6QmYw_28 On Fri, Jun 17, 2016 at 3:08 PM Evan Digby wrote: > To further this, if you do need your internal model to be a concrete > struct rather than interface this approach still fits: > > https://play.golang.org/p/_wrgN1FltA > > > On Friday, 17 June 2016 15:02:43 U

[go-nuts] Re: encoding/json: any way to receive number literal "10.0" into integer field?

2016-06-17 Thread Evan Digby
To further this, if you do need your internal model to be a concrete struct rather than interface this approach still fits: https://play.golang.org/p/_wrgN1FltA On Friday, 17 June 2016 15:02:43 UTC-7, Evan Digby wrote: > > One approach to deal with this would be to abstract your internal model a

[go-nuts] Re: encoding/json: any way to receive number literal "10.0" into integer field?

2016-06-17 Thread Evan Digby
One approach to deal with this would be to abstract your internal model as an interface from the model you receive and mutate them to match. This also gives you the power to truncate/round/mutate a float however best suites your needs rather than hoping the library truncates/rounds/mutates in a