Code Monkey home page Code Monkey logo

Comments (1)

wenovus avatar wenovus commented on June 24, 2024

Hi, the fields are ordered here:

for _, fName := range targetStruct.OrderedFieldNames() {
, and appended to an ordered slice here:
structDef.Fields = append(structDef.Fields, fieldDef)

and the writing to the template is done here by looping through the slice:

if err := generateGetOrCreateStruct(&methodBuf, structDef); err != nil {

If you trace back the dataflow from ParsedDirectory.Fields, then you'll eventually reach goyang's Entry type with its Dir map[string]*Entry field, whereupon you'll end up at https://github.com/openconfig/goyang/blob/5ad0d2feb9ce655fb39e414bd4e3696356780cdb/pkg/yang/entry.go#L410-L418, which is invoked in ToEntry: https://github.com/openconfig/goyang/blob/5ad0d2feb9ce655fb39e414bd4e3696356780cdb/pkg/yang/entry.go#L712-L720, and here you'll finally find some of the original ordering, but even then they're grouped by node type (e.g. leaf vs. leaf-list): https://github.com/openconfig/goyang/blob/5ad0d2feb9ce655fb39e414bd4e3696356780cdb/pkg/yang/ast.go#L454

So fundamentally the issue is that the order of fields are not respected when the Entry representation is converted from the original parsed AST (i.e. []*Statement).


TLDR: The easiest way I can see is to loop through the set of Entry.Node.Statement().SubStatements() to find the ordering, and use that order at

for _, fName := range targetStruct.OrderedFieldNames() {
, unfortunately Entry is not available in ParsedDirectory, so you would need to populate this information into ParsedDirectory from
pd.Fields[fn] = nd
, by accessing Entry from https://github.com/openconfig/ygot/blob/8efc81471e0fe679c453aa0e8c03d752721733bc/ygen/directory.go#L223C4-L223C9

Any other solution would involve adding a new field to either the Entry AST or other Node types, and that would involve some more effort.

from ygot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.