Re: [go-nuts] encoding/asn1 I can't Marshal a struct with pointer members

2024-04-29 Thread Jason Phillips
Then that type probably won't work with encoding/asn1. If you have control over the call to asn1.Marshal, you could always create a "data transfer object " to translate between this third-party type and a type that you control that has a struc

Re: [go-nuts] encoding/asn1 I can't Marshal a struct with pointer members

2024-04-29 Thread J Liu
Thank you very much for your answer, but I cannot modify the definition of the field because this is the structure of the third-party library. On Monday, April 29, 2024 at 1:01:18 AM UTC+8 Def Ceb wrote: > Most marshal/unmarshal functions are unwilling to marshal/unmarshal > structs with pointer

Re: [go-nuts] encoding/asn1 I can't Marshal a struct with pointer members

2024-04-28 Thread Def Ceb
Most marshal/unmarshal functions are unwilling to marshal/unmarshal structs with pointer fields. Changing them to direct values fixes this. Example: https://go.dev/play/p/ykmpBm0bXqn I do not think there is any other simple alternative. J Liu: I understand this problem. My real program uses expo

Re: [go-nuts] encoding/asn1 I can't Marshal a struct with pointer members

2024-04-28 Thread J Liu
I understand this problem. My real program uses export correctly, but the problem I have is not export, asn1: structure error: unknown Go type: *pkg.Girl On Sunday, April 28, 2024 at 9:27:42 AM UTC+8 Jan Mercl wrote: > > > On Sun, Apr 28, 2024, 03:03 J Liu <88592...@gmail.com> wrote: > >> My pr

Re: [go-nuts] encoding/asn1 I can't Marshal a struct with pointer members

2024-04-27 Thread Jan Mercl
On Sun, Apr 28, 2024, 03:03 J Liu <8859210...@gmail.com> wrote: > My program is like this: > > type Girl struct { > Name string > Age int > } > > type Person struct { > girl *Girl > job string > } > > > What should I do to Marshal 'Person'? > I think you need to export th

[go-nuts] encoding/asn1 I can't Marshal a struct with pointer members

2024-04-27 Thread J Liu
My program is like this: type Girl struct { Name string Age int } type Person struct { girl *Girl job string } What should I do to Marshal 'Person'? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from t

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-10 Thread Brian Candler
On Friday, 10 June 2022 at 14:31:10 UTC+1 Andreas Götz wrote: > On Thursday, June 9, 2022 at 6:44:58 PM UTC+2 Brian Candler wrote: > >> I forgot to add one thing, and you didn't paste the whole certificate PEM >> so I can't check this. >> >> Recent versions of Go won't verify the certificate unle

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-10 Thread Andreas Götz
On Thursday, June 9, 2022 at 6:44:58 PM UTC+2 Brian Candler wrote: > I forgot to add one thing, and you didn't paste the whole certificate PEM > so I can't check this. > > Recent versions of Go won't verify the certificate unless it contains a > subjectAltName; matching against only the CN is no

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-09 Thread Brian Candler
I forgot to add one thing, and you didn't paste the whole certificate PEM so I can't check this. Recent versions of Go won't verify the certificate unless it contains a subjectAltName; matching against only the CN is no longer supported. So if you do get your vendor to re-issue the cert, make

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-09 Thread Brian Candler
On Thursday, 9 June 2022 at 14:27:04 UTC+1 cpu...@gmail.com wrote: > We receive an alert 40 (Handshake failure ) when using openssl. So the > cert is definitively faulty in some way. > > :~/wallbox/hack$ openssl s_client -connect 192.168.1.180:4712 > Certainly it will report a failed verifica

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-09 Thread cpu...@gmail.com
On Wednesday, June 8, 2022 at 5:53:50 PM UTC+2 Brian Candler wrote: > On Wednesday, 8 June 2022 at 10:09:26 UTC+1 andig wrote: > >> We've not found an approach for communicating with the device sofar >> unless using patched Go stdlib. >> > > Connect via a proxy like stunnel? > > Out of interest,

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-08 Thread Brian Candler
On Wednesday, 8 June 2022 at 10:09:26 UTC+1 cpu...@gmail.com wrote: > We've not found an approach for communicating with the device sofar unless > using patched Go stdlib. > Connect via a proxy like stunnel? Out of interest, does raw "openssl s_client" allow communication with the device? It

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-08 Thread Andreas Götz
To be more specific: in order to connect to the IOT server presenting the rogue BER certificate, we have InsecureSkipVerify: true. The description of InsecureSkipVerify reads: // InsecureSkipVerify controls whether a client verifies the server's // certificate chain and host name. If InsecureSki

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-08 Thread cpu...@gmail.com
Sorry to revive this ancient discussion. We've come across https://forum.golangbridge.org/t/x509-certificate-parse-error-with-iot-device/27622/2 where an IOT device from a large vendor uses BER for it's TLS certificate. It's unlikely, that the vendor will fix the certificate any time soon.

Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread Marcin Romaszewicz
Aha! That is what I was missing. Thank you. On Fri, May 20, 2022 at 7:37 AM 'Sean Liao' via golang-nuts < golang-nuts@googlegroups.com> wrote: > As explained above, `type AliasedDate Date` clears any methods you have > defined on `Date`. > But `Date` embeds `time.Time` which has its own `Unmrshal

Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread 'Sean Liao' via golang-nuts
As explained above, `type AliasedDate Date` clears any methods you have defined on `Date`. But `Date` embeds `time.Time` which has its own `UnmrshalJSON`, which now gets promoted. So `Date.UnmsrshalJSON` calls your `UnmsrshalJSON` `AliastedDate.UnmsrshalJSON` calls `AliastedDate.Time.UnmsrshalJSON

Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread Marcin Romaszewicz
Sorry about mixing up terms, however, my question still stands. encoding/json looks for the Marshaler/Unmarshaler interface convertibility, and in this case, the compiler thinks that the redeclared type does implement json.Unmarshaler. I extended my example to also do this test via reflection. ht

Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread 'Axel Wagner' via golang-nuts
It's not an "aliased type". Type aliases take the form type A = B and they make the name A be interchangeable with the name B. What you have is a type declaration type A B which creates a fully new type, with a new method set, but the same underlying type as B. On Fri, May 20, 2022 at 9:28 AM Marc

[go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread Marcin Romaszewicz
Hi All, I've created a simple struct that wraps time.Time because I'd like to unmarshal it differently from JSON than the default. It works great. However, when I pass a type alias of that struct to json.Marshal or json.Unmarshal, the MarshalJSON and UnmarshalJSON functions aren't invoked, despit

Re: [go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-14 Thread Brian Candler
"txtar " is the magic. In the playground, there's a dropdown on the right - it says "Hello, World!" by default. From here, you can select the example called "Multiple Files". On Thursday, 14 April 2022 at 17:50:14 UTC+1 michael...@gmail.com wrote:

Re: [go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-14 Thread Michael Ellis
@Brian That example is a superbly concise explanation go mod. Thanks! And I had no idea you could specify filenames and modules in the Playground. That's really useful! On Wednesday, April 13, 2022 at 3:11:54 AM UTC-4 Brian Candler wrote: > > I am a little bewildered by the new mod configurat

Re: [go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-13 Thread Brian Candler
> I am a little bewildered by the new mod configuration. It's as simple as this: go mod init blah go mod tidy You can put anything(*) for "blah". Literally "blah" will work. It's just whatever name you want to give your module. However if you plan to publish your module on github then using "

Re: [go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-12 Thread Zhaoxun Yan
Thank you Steven. I am a little bewildered by the new mod configuration. Will it compile If I download the source file from the new github source to src directory without further setting up a mod in the old fashioned way? I am using go1.15. And today I ran a test logging all the sendings to Redis

Re: [go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-12 Thread Steven Hartland
First off, the package you're using for redis isn't maintained; you should switch to github.com/gomodule/redigo/redis instead, which will allow you to remove the c == nil check as that doesn't happen. In your example you're ignoring error from json.Marshal which could be hiding a problem, so I wou

[go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-11 Thread Zhaoxun Yan
The scenario is upon receiving an incoming financial quotation, save it as a string of json into a Redis service. Sorry but I cannot provide the whole code of quotation receiving here, which is very complex with cgo. But the code below will help you get a glimpse on what should be going on: imp

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

2022-02-26 Thread Steffen Wentzel
Dear community, how can we XML marshal a struct field depending on the value of another struct field in the same struct? Playground Example: https://go.dev/play/p/vfRB-GfzZ54 My approaches so far: - Use a custom type for the Feature field and implement xml.Marshaler. However MarshalXML

[go-nuts] encoding/gob: doc of encoding of single values is inconsistent

2021-12-08 Thread Jared Zhou
The doc says. https://github.com/golang/go/blob/d6c4583ad4923533ddc9f5792ed3b66f3b9f9feb/src/encoding/gob/doc.go#L178 If a value is passed to Encode and the type is not a struct (or pointer to struct, etc.), for simplicity of processing it is represented as a struct of one field. The only visibl

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

2021-05-09 Thread Ally Dale
reffer issue ## Sometimes we have to deal with JSON that with unknown data types. Such as [sample JSON](https://github.com/vipally/glab/blob/master/lab27/json_test.go#L9) below: ``` [ { "kind":"dog", "attr":{ "type":"Col

[go-nuts] encoding/xml expose line

2021-04-16 Thread Patrick
Hello all, I use the XML package from the standard library (encoding/xml) and I wonder why the line attribute of the decoder is not exposed such as func (d *Decoder) InputLine() int { return d.line } The offset for example is exposed: func (d *Decoder) InputOffset() int64 { return d.of

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

2021-04-08 Thread Dan Jackson
My need is similar to issue #26679 but not the same. I am using 1.15.8 I have a need for the "current line number" when reading a csv file (with Reader.Read() ) so that I can report errors in the data (not a csv parsing error but errors in the data in the csv file). In my case, a comment char

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

2021-03-14 Thread atd...@gmail.com
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 static html from the same code I use to create dynamic wasm-based webapps. I was trying to find a package that would enable me to generate an html document bu

[go-nuts] encoding/json character escaping question

2019-10-05 Thread nanmu42
You can disable this behavior, this link may help: https://go-review.googlesource.com/c/go/+/21796/ -- 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+u

Re: [go-nuts] encoding/json character escaping question

2019-10-05 Thread Poussier William
Thank you David for the detailled answer. Le samedi 5 octobre 2019 20:48:11 UTC+2, David Finkel a écrit : > > > > On Thu, Oct 3, 2019 at 11:11 AM Poussier William > wrote: > >> Hello >> >> The encoding/json package escapes 0xA (line feed), 0xD (carriage return) >> and 0x9 (horizontal tab) using

Re: [go-nuts] encoding/json character escaping question

2019-10-05 Thread David Finkel
On Thu, Oct 3, 2019 at 11:11 AM Poussier William wrote: > Hello > > The encoding/json package escapes 0xA (line feed), 0xD (carriage return) > and 0x9 (horizontal tab) using the escape character '\'. However, when it > comes to 0x8 (backspace) and 0xc (form feed), it uses the Unicode escape > seq

[go-nuts] encoding/json character escaping question

2019-10-03 Thread Poussier William
Hello The encoding/json package escapes 0xA (line feed), 0xD (carriage return) and 0x9 (horizontal tab) using the escape character '\'. However, when it comes to 0x8 (backspace) and 0xc (form feed), it uses the Unicode escape sequence staring with '\u'. Reproducer: https://play.golang.org/

[go-nuts] Encoding

2018-05-16 Thread Raulino Neto
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. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving email

Re: [go-nuts] encoding/csv: Is this a bug?

2017-07-24 Thread howardcshaw
encoding/csv uses the io.Reader interface, so wouldn't you just need a CR->CR/LF filter that fulfills that interface? Something like https://github.com/andybalholm/crlf should do the trick. Though it would be annoying to deal with when writing a generic program for handling arbitrary input, if

Re: [go-nuts] encoding/csv: Is this a bug?

2017-07-18 Thread ajstarks
See: https://github.com/golang/go/issues/7897 See also: https://gist.github.com/ajstarks/04a61ace4fc8e18f51fda8da6adac017 for a program I use to read CSVs on a Mac. I typically use "Windows Comma Separated" when saving from Excel. On Monday, July 17, 2017 at 11:07:43 PM UTC-4, Matt Harden wrot

Re: [go-nuts] encoding/csv: Is this a bug?

2017-07-17 Thread Matt Harden
I suspect that this has to do with the line-ending characters on a Mac. I think Excel is writing the file with each line ending with a CR character. The encoding/csv package expects RFC 4180 format (each line terminated with CRLF), which is what Excel writes when you select "Windows Comma Separated

[go-nuts] encoding/csv: Is this a bug?

2017-07-17 Thread Dat Huynh
Hi all, I have a problem with parsing a .csv file using the library "encoding/csv". I wonder if that is the problem of Microsoft Excel or the Go library. I am using Microsoft Excel version 14.2.2 on MacOS and go1.8.3 darwin/amd64 What did I do? Firstly I input the below values into an Excel sh

[go-nuts] encoding/asn1: Accept the non-PrintableString character underscore

2017-05-09 Thread Ivan Borshukov
Hi Gohpers, I need to deal with certificates which contain '_'. Unfortunately, the '_' is not treated like a printable string character from Go. I read through the discussions in [1], [2], but unfortunately none of them proposes a work around. Can you suggest a solution other than forking the x

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

2017-05-02 Thread Brian Stengaard
Hey Gophers, When unmarshalling JSON into a struct with a blank interface (interface{}) I get a surprising result: If I set the field to a pointer to a T value before unmarshalling, the data is filled out on the T value as expected. (See I2 in the playground example.) If I set the field to a

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

2017-03-02 Thread 'Thomas Bushnell, BSG' via golang-nuts
There is no such distinction in json as a float vs. an int; they are just numbers. This is essentially a consequence of the javascript underpinnings of json. Thomas On Thu, Mar 2, 2017 at 2:29 AM Basile Starynkevitch < bas...@starynkevitch.net> wrote: > Hello All, > > This could be related to is

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

2017-03-02 Thread Konstantin Khomoutov
On Thu, 2 Mar 2017 03:35:39 -0800 (PST) Basile Starynkevitch wrote: [...] > > JSON itself doesn't distinguish between integers and floats so it > > could be a bad fit for your use case. [...] > In theory you are right, json.org don't make the difference. In > practice, a lot of JSON libraries (e

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

2017-03-02 Thread Basile Starynkevitch
On Thursday, March 2, 2017 at 12:01:49 PM UTC+1, Jakob Borg wrote: > > > On 2 Mar 2017, at 18:29, Basile Starynkevitch > wrote: > > I would like that second line to be at least json_emit buf: -1.0 because > I need to separate objvalmo.FloatV from objvalmo.IntV types > > > JSON itself doesn't di

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

2017-03-02 Thread Konstantin Khomoutov
On Thu, 2 Mar 2017 02:29:22 -0800 (PST) Basile Starynkevitch wrote: > I want to JSON encode a float64 point number always as a JSON float, > so 1.0 should be encoded as 1.0 not as 1 because at decoding time I > want to distinguish them. [...] Use custom type with a custom marshaler [1]: ---

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

2017-03-02 Thread Jakob Borg
> On 2 Mar 2017, at 18:29, Basile Starynkevitch > wrote: > > I would like that second line to be at least json_emit buf: -1.0 because I > need to separate objvalmo.FloatV from objvalmo.IntV types JSON itself doesn't distinguish between integers and floats so it could be a bad fit for your us

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

2017-03-02 Thread Basile Starynkevitch
Hello All, This could be related to issue #6384 I want to JSON encode a float64 point number always as a JSON float, so 1.0 should be encoded as 1.0 not as 1 because at decoding time I want to distinguish them. Conceptually, I am persisting in JSON fo

[go-nuts] encoding/binary partial read errors

2017-02-15 Thread Eric Buth
The ReadUvarint implementation (and ReadVarint which depends on it) reads from a io.ByteReader until it encounters a leading 0 bit indicating the end of the last byte of a varint. If it encounters an io.EOF error at any point, that error is passed back to the caller. The issue is that the

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

2017-01-17 Thread caspian46
I got two struct types encoded into bytes by gob, I want to decode the bytes into a specific struct, is it possible without try all struct types(maybe 3 or more struct types)? I want to decode bytes without specify which elem in mixedBytes is struct A, and which is struct B. This is the playgr

Re: [go-nuts] encoding/xml Unmarshal problem

2016-07-05 Thread Hoping White
Thanks for the reply. After a careful compare, I found what I did wrong. Value string `xml:,chardata” `=> Value string `xml:”,chardata”`, missing a “ token. > 在 2016年7月6日,上午11:12,Matt Harden 写道: > > It works for me: https://play.golang.org/p/yCI68Zsg1E >

Re: [go-nuts] encoding/xml Unmarshal problem

2016-07-05 Thread Matt Harden
It works for me: https://play.golang.org/p/yCI68Zsg1E On Tue, Jul 5, 2016 at 8:04 PM Hoping White wrote: > > Hi, gophers > > > How do I unmarshal an xml as following: > > > data > > > I have tried with > > *type* Resources *struct* { > XMLName xml.Name `xml:"resources"` > Strings []String

[go-nuts] encoding/xml Unmarshal problem

2016-07-05 Thread Hoping White
Hi, gophers How do I unmarshal an xml as following: data I have tried with type Resources struct { XMLName xml.Name `xml:"resources"` Strings []String `xml:"string"` } type String struct { Name string `xml:"name,attr"` Value string `xml:,chardata"` }

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

2016-06-17 Thread jonathan
Thanks -- I should have clarified that we've ruled that option out (it was our first approach), since we want to stick to the built in types that won't require explicit exchange with the primitive types. jonathan On Fri, Jun 17, 2016 at 02:56:49PM -0700, Edward Muller wrote: > AFAIK (and someone

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

2016-06-17 Thread Edward Muller
AFAIK (and someone will probably provide something better) you need to do something like this: https://play.golang.org/p/riq-m6cgZu > On Jun 17, 2016, at 2:37 PM, jg...@bitgirder.com wrote: > > We have an upstream provider of JSON data which sends integer data > types as floating point literal

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

2016-06-17 Thread jgold
We have an upstream provider of JSON data which sends integer data types as floating point literals with a "0" decimal part. By default json.Decoder doesn't allow this and fails: https://play.golang.org/p/MEJlg1n3vs Unfortunately this provider is almost certain not to change this, and so we j